@theia/notebook 1.41.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +30 -0
- package/lib/browser/contributions/notebook-actions-contribution.d.ts +27 -0
- package/lib/browser/contributions/notebook-actions-contribution.d.ts.map +1 -0
- package/lib/browser/contributions/notebook-actions-contribution.js +172 -0
- package/lib/browser/contributions/notebook-actions-contribution.js.map +1 -0
- package/lib/browser/contributions/notebook-cell-actions-contribution.d.ts +30 -0
- package/lib/browser/contributions/notebook-cell-actions-contribution.d.ts.map +1 -0
- package/lib/browser/contributions/notebook-cell-actions-contribution.js +200 -0
- package/lib/browser/contributions/notebook-cell-actions-contribution.js.map +1 -0
- package/lib/browser/contributions/notebook-color-contribution.d.ts +6 -0
- package/lib/browser/contributions/notebook-color-contribution.d.ts.map +1 -0
- package/lib/browser/contributions/notebook-color-contribution.js +252 -0
- package/lib/browser/contributions/notebook-color-contribution.js.map +1 -0
- package/lib/browser/contributions/notebook-context-keys.d.ts +38 -0
- package/lib/browser/contributions/notebook-context-keys.d.ts.map +1 -0
- package/lib/browser/contributions/notebook-context-keys.js +95 -0
- package/lib/browser/contributions/notebook-context-keys.js.map +1 -0
- package/lib/browser/index.d.ts +11 -0
- package/lib/browser/index.d.ts.map +1 -0
- package/lib/browser/index.js +38 -0
- package/lib/browser/index.js.map +1 -0
- package/lib/browser/notebook-cell-resource-resolver.d.ts +20 -0
- package/lib/browser/notebook-cell-resource-resolver.d.ts.map +1 -0
- package/lib/browser/notebook-cell-resource-resolver.js +75 -0
- package/lib/browser/notebook-cell-resource-resolver.js.map +1 -0
- package/lib/browser/notebook-editor-widget-factory.d.ts +17 -0
- package/lib/browser/notebook-editor-widget-factory.d.ts.map +1 -0
- package/lib/browser/notebook-editor-widget-factory.js +78 -0
- package/lib/browser/notebook-editor-widget-factory.js.map +1 -0
- package/lib/browser/notebook-editor-widget.d.ts +49 -0
- package/lib/browser/notebook-editor-widget.d.ts.map +1 -0
- package/lib/browser/notebook-editor-widget.js +150 -0
- package/lib/browser/notebook-editor-widget.js.map +1 -0
- package/lib/browser/notebook-frontend-module.d.ts +5 -0
- package/lib/browser/notebook-frontend-module.d.ts.map +1 -0
- package/lib/browser/notebook-frontend-module.js +81 -0
- package/lib/browser/notebook-frontend-module.js.map +1 -0
- package/lib/browser/notebook-open-handler.d.ts +18 -0
- package/lib/browser/notebook-open-handler.d.ts.map +1 -0
- package/lib/browser/notebook-open-handler.js +94 -0
- package/lib/browser/notebook-open-handler.js.map +1 -0
- package/lib/browser/notebook-renderer-registry.d.ts +17 -0
- package/lib/browser/notebook-renderer-registry.d.ts.map +1 -0
- package/lib/browser/notebook-renderer-registry.js +63 -0
- package/lib/browser/notebook-renderer-registry.js.map +1 -0
- package/lib/browser/notebook-type-registry.d.ts +7 -0
- package/lib/browser/notebook-type-registry.d.ts.map +1 -0
- package/lib/browser/notebook-type-registry.js +42 -0
- package/lib/browser/notebook-type-registry.js.map +1 -0
- package/lib/browser/renderers/cell-output-webview.d.ts +12 -0
- package/lib/browser/renderers/cell-output-webview.d.ts.map +1 -0
- package/lib/browser/renderers/cell-output-webview.js +20 -0
- package/lib/browser/renderers/cell-output-webview.js.map +1 -0
- package/lib/browser/service/notebook-cell-context-manager.d.ts +16 -0
- package/lib/browser/service/notebook-cell-context-manager.d.ts.map +1 -0
- package/lib/browser/service/notebook-cell-context-manager.js +83 -0
- package/lib/browser/service/notebook-cell-context-manager.js.map +1 -0
- package/lib/browser/service/notebook-editor-service.d.ts +22 -0
- package/lib/browser/service/notebook-editor-service.d.ts.map +1 -0
- package/lib/browser/service/notebook-editor-service.js +95 -0
- package/lib/browser/service/notebook-editor-service.js.map +1 -0
- package/lib/browser/service/notebook-execution-service.d.ts +25 -0
- package/lib/browser/service/notebook-execution-service.d.ts.map +1 -0
- package/lib/browser/service/notebook-execution-service.js +140 -0
- package/lib/browser/service/notebook-execution-service.js.map +1 -0
- package/lib/browser/service/notebook-execution-state-service.d.ts +94 -0
- package/lib/browser/service/notebook-execution-state-service.d.ts.map +1 -0
- package/lib/browser/service/notebook-execution-state-service.js +250 -0
- package/lib/browser/service/notebook-execution-state-service.js.map +1 -0
- package/lib/browser/service/notebook-kernel-history-service.d.ts +23 -0
- package/lib/browser/service/notebook-kernel-history-service.d.ts.map +1 -0
- package/lib/browser/service/notebook-kernel-history-service.js +109 -0
- package/lib/browser/service/notebook-kernel-history-service.js.map +1 -0
- package/lib/browser/service/notebook-kernel-quick-pick-service.d.ts +65 -0
- package/lib/browser/service/notebook-kernel-quick-pick-service.d.ts.map +1 -0
- package/lib/browser/service/notebook-kernel-quick-pick-service.js +430 -0
- package/lib/browser/service/notebook-kernel-quick-pick-service.js.map +1 -0
- package/lib/browser/service/notebook-kernel-service.d.ts +112 -0
- package/lib/browser/service/notebook-kernel-service.d.ts.map +1 -0
- package/lib/browser/service/notebook-kernel-service.js +274 -0
- package/lib/browser/service/notebook-kernel-service.js.map +1 -0
- package/lib/browser/service/notebook-model-resolver-service.d.ts +26 -0
- package/lib/browser/service/notebook-model-resolver-service.d.ts.map +1 -0
- package/lib/browser/service/notebook-model-resolver-service.js +139 -0
- package/lib/browser/service/notebook-model-resolver-service.js.map +1 -0
- package/lib/browser/service/notebook-renderer-messaging-service.d.ts +30 -0
- package/lib/browser/service/notebook-renderer-messaging-service.d.ts.map +1 -0
- package/lib/browser/service/notebook-renderer-messaging-service.js +94 -0
- package/lib/browser/service/notebook-renderer-messaging-service.js.map +1 -0
- package/lib/browser/service/notebook-service.d.ts +64 -0
- package/lib/browser/service/notebook-service.d.ts.map +1 -0
- package/lib/browser/service/notebook-service.js +162 -0
- package/lib/browser/service/notebook-service.js.map +1 -0
- package/lib/browser/view/notebook-cell-editor.d.ts +26 -0
- package/lib/browser/view/notebook-cell-editor.d.ts.map +1 -0
- package/lib/browser/view/notebook-cell-editor.js +79 -0
- package/lib/browser/view/notebook-cell-editor.js.map +1 -0
- package/lib/browser/view/notebook-cell-list-view.d.ts +43 -0
- package/lib/browser/view/notebook-cell-list-view.d.ts.map +1 -0
- package/lib/browser/view/notebook-cell-list-view.js +111 -0
- package/lib/browser/view/notebook-cell-list-view.js.map +1 -0
- package/lib/browser/view/notebook-cell-toolbar-factory.d.ts +25 -0
- package/lib/browser/view/notebook-cell-toolbar-factory.d.ts.map +1 -0
- package/lib/browser/view/notebook-cell-toolbar-factory.js +93 -0
- package/lib/browser/view/notebook-cell-toolbar-factory.js.map +1 -0
- package/lib/browser/view/notebook-cell-toolbar.d.ts +25 -0
- package/lib/browser/view/notebook-cell-toolbar.d.ts.map +1 -0
- package/lib/browser/view/notebook-cell-toolbar.js +50 -0
- package/lib/browser/view/notebook-cell-toolbar.js.map +1 -0
- package/lib/browser/view/notebook-code-cell-view.d.ts +47 -0
- package/lib/browser/view/notebook-code-cell-view.d.ts.map +1 -0
- package/lib/browser/view/notebook-code-cell-view.js +166 -0
- package/lib/browser/view/notebook-code-cell-view.js.map +1 -0
- package/lib/browser/view/notebook-main-toolbar.d.ts +31 -0
- package/lib/browser/view/notebook-main-toolbar.d.ts.map +1 -0
- package/lib/browser/view/notebook-main-toolbar.js +118 -0
- package/lib/browser/view/notebook-main-toolbar.js.map +1 -0
- package/lib/browser/view/notebook-markdown-cell-view.d.ts +12 -0
- package/lib/browser/view/notebook-markdown-cell-view.d.ts.map +1 -0
- package/lib/browser/view/notebook-markdown-cell-view.js +70 -0
- package/lib/browser/view/notebook-markdown-cell-view.js.map +1 -0
- package/lib/browser/view-model/notebook-cell-model.d.ts +74 -0
- package/lib/browser/view-model/notebook-cell-model.d.ts.map +1 -0
- package/lib/browser/view-model/notebook-cell-model.js +226 -0
- package/lib/browser/view-model/notebook-cell-model.js.map +1 -0
- package/lib/browser/view-model/notebook-cell-output-model.d.ts +19 -0
- package/lib/browser/view-model/notebook-cell-output-model.d.ts.map +1 -0
- package/lib/browser/view-model/notebook-cell-output-model.js +61 -0
- package/lib/browser/view-model/notebook-cell-output-model.js.map +1 -0
- package/lib/browser/view-model/notebook-model.d.ts +59 -0
- package/lib/browser/view-model/notebook-model.d.ts.map +1 -0
- package/lib/browser/view-model/notebook-model.js +315 -0
- package/lib/browser/view-model/notebook-model.js.map +1 -0
- package/lib/common/index.d.ts +3 -0
- package/lib/common/index.d.ts.map +1 -0
- package/lib/common/index.js +30 -0
- package/lib/common/index.js.map +1 -0
- package/lib/common/notebook-common.d.ts +344 -0
- package/lib/common/notebook-common.d.ts.map +1 -0
- package/lib/common/notebook-common.js +112 -0
- package/lib/common/notebook-common.js.map +1 -0
- package/lib/common/notebook-protocol.d.ts +21 -0
- package/lib/common/notebook-protocol.d.ts.map +1 -0
- package/lib/common/notebook-protocol.js +18 -0
- package/lib/common/notebook-protocol.js.map +1 -0
- package/lib/common/notebook-range.d.ts +14 -0
- package/lib/common/notebook-range.d.ts.map +1 -0
- package/lib/common/notebook-range.js +18 -0
- package/lib/common/notebook-range.js.map +1 -0
- package/package.json +52 -0
- package/src/browser/contributions/notebook-actions-contribution.ts +171 -0
- package/src/browser/contributions/notebook-cell-actions-contribution.ts +204 -0
- package/src/browser/contributions/notebook-color-contribution.ts +268 -0
- package/src/browser/contributions/notebook-context-keys.ts +99 -0
- package/src/browser/index.ts +26 -0
- package/src/browser/notebook-cell-resource-resolver.ts +79 -0
- package/src/browser/notebook-editor-widget-factory.ts +70 -0
- package/src/browser/notebook-editor-widget.tsx +157 -0
- package/src/browser/notebook-frontend-module.ts +95 -0
- package/src/browser/notebook-open-handler.ts +87 -0
- package/src/browser/notebook-renderer-registry.ts +62 -0
- package/src/browser/notebook-type-registry.ts +30 -0
- package/src/browser/renderers/cell-output-webview.ts +32 -0
- package/src/browser/service/notebook-cell-context-manager.ts +70 -0
- package/src/browser/service/notebook-editor-service.ts +86 -0
- package/src/browser/service/notebook-execution-service.ts +139 -0
- package/src/browser/service/notebook-execution-state-service.ts +322 -0
- package/src/browser/service/notebook-kernel-history-service.ts +109 -0
- package/src/browser/service/notebook-kernel-quick-pick-service.ts +494 -0
- package/src/browser/service/notebook-kernel-service.ts +357 -0
- package/src/browser/service/notebook-model-resolver-service.ts +141 -0
- package/src/browser/service/notebook-renderer-messaging-service.ts +111 -0
- package/src/browser/service/notebook-service.ts +178 -0
- package/src/browser/style/index.css +236 -0
- package/src/browser/view/notebook-cell-editor.tsx +97 -0
- package/src/browser/view/notebook-cell-list-view.tsx +171 -0
- package/src/browser/view/notebook-cell-toolbar-factory.tsx +91 -0
- package/src/browser/view/notebook-cell-toolbar.tsx +70 -0
- package/src/browser/view/notebook-code-cell-view.tsx +190 -0
- package/src/browser/view/notebook-main-toolbar.tsx +115 -0
- package/src/browser/view/notebook-markdown-cell-view.tsx +73 -0
- package/src/browser/view-model/notebook-cell-model.ts +271 -0
- package/src/browser/view-model/notebook-cell-output-model.ts +69 -0
- package/src/browser/view-model/notebook-model.ts +372 -0
- package/src/common/index.ts +18 -0
- package/src/common/notebook-common.ts +462 -0
- package/src/common/notebook-protocol.ts +35 -0
- package/src/common/notebook-range.ts +30 -0
|
@@ -0,0 +1,99 @@
|
|
|
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 { ContextKeyService } from '@theia/core/lib/browser/context-key-service';
|
|
18
|
+
|
|
19
|
+
export type NotebookCellExecutionStateContext = 'idle' | 'pending' | 'executing' | 'succeeded' | 'failed';
|
|
20
|
+
|
|
21
|
+
export const HAS_OPENED_NOTEBOOK = 'userHasOpenedNotebook';
|
|
22
|
+
export const KEYBINDING_CONTEXT_NOTEBOOK_FIND_WIDGET_FOCUSED = 'notebookFindWidgetFocused';
|
|
23
|
+
export const NOTEBOOK_EDITOR_FOCUSED = 'notebookEditorFocused';
|
|
24
|
+
export const NOTEBOOK_CELL_LIST_FOCUSED = 'notebookCellListFocused';
|
|
25
|
+
export const NOTEBOOK_OUTPUT_FOCUSED = 'notebookOutputFocused';
|
|
26
|
+
export const NOTEBOOK_EDITOR_EDITABLE = 'notebookEditable';
|
|
27
|
+
export const NOTEBOOK_HAS_RUNNING_CELL = 'notebookHasRunningCell';
|
|
28
|
+
export const NOTEBOOK_USE_CONSOLIDATED_OUTPUT_BUTTON = 'notebookUseConsolidatedOutputButton';
|
|
29
|
+
export const NOTEBOOK_BREAKPOINT_MARGIN_ACTIVE = 'notebookBreakpointMargin';
|
|
30
|
+
export const NOTEBOOK_CELL_TOOLBAR_LOCATION = 'notebookCellToolbarLocation';
|
|
31
|
+
export const NOTEBOOK_CURSOR_NAVIGATION_MODE = 'notebookCursorNavigationMode';
|
|
32
|
+
export const NOTEBOOK_LAST_CELL_FAILED = 'notebookLastCellFailed';
|
|
33
|
+
export const NOTEBOOK_VIEW_TYPE = 'notebookType';
|
|
34
|
+
export const NOTEBOOK_CELL_TYPE = 'notebookCellType';
|
|
35
|
+
export const NOTEBOOK_CELL_EDITABLE = 'notebookCellEditable';
|
|
36
|
+
export const NOTEBOOK_CELL_FOCUSED = 'notebookCellFocused';
|
|
37
|
+
export const NOTEBOOK_CELL_EDITOR_FOCUSED = 'notebookCellEditorFocused';
|
|
38
|
+
export const NOTEBOOK_CELL_MARKDOWN_EDIT_MODE = 'notebookCellMarkdownEditMode';
|
|
39
|
+
export const NOTEBOOK_CELL_LINE_NUMBERS = 'notebookCellLineNumbers';
|
|
40
|
+
export const NOTEBOOK_CELL_EXECUTION_STATE = 'notebookCellExecutionState';
|
|
41
|
+
export const NOTEBOOK_CELL_EXECUTING = 'notebookCellExecuting';
|
|
42
|
+
export const NOTEBOOK_CELL_HAS_OUTPUTS = 'notebookCellHasOutputs';
|
|
43
|
+
export const NOTEBOOK_CELL_INPUT_COLLAPSED = 'notebookCellInputIsCollapsed';
|
|
44
|
+
export const NOTEBOOK_CELL_OUTPUT_COLLAPSED = 'notebookCellOutputIsCollapsed';
|
|
45
|
+
export const NOTEBOOK_CELL_RESOURCE = 'notebookCellResource';
|
|
46
|
+
export const NOTEBOOK_KERNEL = 'notebookKernel';
|
|
47
|
+
export const NOTEBOOK_KERNEL_COUNT = 'notebookKernelCount';
|
|
48
|
+
export const NOTEBOOK_KERNEL_SOURCE_COUNT = 'notebookKernelSourceCount';
|
|
49
|
+
export const NOTEBOOK_KERNEL_SELECTED = 'notebookKernelSelected';
|
|
50
|
+
export const NOTEBOOK_INTERRUPTIBLE_KERNEL = 'notebookInterruptibleKernel';
|
|
51
|
+
export const NOTEBOOK_MISSING_KERNEL_EXTENSION = 'notebookMissingKernelExtension';
|
|
52
|
+
export const NOTEBOOK_HAS_OUTPUTS = 'notebookHasOutputs';
|
|
53
|
+
|
|
54
|
+
export namespace NotebookContextKeys {
|
|
55
|
+
export function initNotebookContextKeys(service: ContextKeyService): void {
|
|
56
|
+
service.createKey(HAS_OPENED_NOTEBOOK, false);
|
|
57
|
+
service.createKey(KEYBINDING_CONTEXT_NOTEBOOK_FIND_WIDGET_FOCUSED, false);
|
|
58
|
+
|
|
59
|
+
// // Is Notebook
|
|
60
|
+
// export const NOTEBOOK_IS_ACTIVE_EDITOR = ContextKeyExpr.equals('activeEditor', NOTEBOOK_EDITOR_ID);
|
|
61
|
+
// export const INTERACTIVE_WINDOW_IS_ACTIVE_EDITOR = ContextKeyExpr.equals('activeEditor', INTERACTIVE_WINDOW_EDITOR_ID);
|
|
62
|
+
|
|
63
|
+
// Editor keys
|
|
64
|
+
service.createKey(NOTEBOOK_EDITOR_FOCUSED, false);
|
|
65
|
+
service.createKey(NOTEBOOK_CELL_LIST_FOCUSED, false);
|
|
66
|
+
service.createKey(NOTEBOOK_OUTPUT_FOCUSED, false);
|
|
67
|
+
service.createKey(NOTEBOOK_EDITOR_EDITABLE, true);
|
|
68
|
+
service.createKey(NOTEBOOK_HAS_RUNNING_CELL, false);
|
|
69
|
+
service.createKey(NOTEBOOK_USE_CONSOLIDATED_OUTPUT_BUTTON, false);
|
|
70
|
+
service.createKey(NOTEBOOK_BREAKPOINT_MARGIN_ACTIVE, false);
|
|
71
|
+
service.createKey(NOTEBOOK_CELL_TOOLBAR_LOCATION, 'left');
|
|
72
|
+
service.createKey(NOTEBOOK_CURSOR_NAVIGATION_MODE, false);
|
|
73
|
+
service.createKey(NOTEBOOK_LAST_CELL_FAILED, false);
|
|
74
|
+
|
|
75
|
+
// Cell keys
|
|
76
|
+
service.createKey(NOTEBOOK_VIEW_TYPE, undefined);
|
|
77
|
+
service.createKey(NOTEBOOK_CELL_TYPE, undefined);
|
|
78
|
+
service.createKey(NOTEBOOK_CELL_EDITABLE, false);
|
|
79
|
+
service.createKey(NOTEBOOK_CELL_FOCUSED, false);
|
|
80
|
+
service.createKey(NOTEBOOK_CELL_EDITOR_FOCUSED, false);
|
|
81
|
+
service.createKey(NOTEBOOK_CELL_MARKDOWN_EDIT_MODE, false);
|
|
82
|
+
service.createKey(NOTEBOOK_CELL_LINE_NUMBERS, 'inherit');
|
|
83
|
+
service.createKey(NOTEBOOK_CELL_EXECUTION_STATE, undefined);
|
|
84
|
+
service.createKey(NOTEBOOK_CELL_EXECUTING, false);
|
|
85
|
+
service.createKey(NOTEBOOK_CELL_HAS_OUTPUTS, false);
|
|
86
|
+
service.createKey(NOTEBOOK_CELL_INPUT_COLLAPSED, false);
|
|
87
|
+
service.createKey(NOTEBOOK_CELL_OUTPUT_COLLAPSED, false);
|
|
88
|
+
service.createKey(NOTEBOOK_CELL_RESOURCE, '');
|
|
89
|
+
|
|
90
|
+
// Kernels
|
|
91
|
+
service.createKey(NOTEBOOK_KERNEL, undefined);
|
|
92
|
+
service.createKey(NOTEBOOK_KERNEL_COUNT, 0);
|
|
93
|
+
service.createKey(NOTEBOOK_KERNEL_SOURCE_COUNT, 0);
|
|
94
|
+
service.createKey(NOTEBOOK_KERNEL_SELECTED, false);
|
|
95
|
+
service.createKey(NOTEBOOK_INTERRUPTIBLE_KERNEL, false);
|
|
96
|
+
service.createKey(NOTEBOOK_MISSING_KERNEL_EXTENSION, false);
|
|
97
|
+
service.createKey(NOTEBOOK_HAS_OUTPUTS, false);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
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
|
+
export * from './notebook-type-registry';
|
|
18
|
+
export * from './notebook-renderer-registry';
|
|
19
|
+
export * from './notebook-editor-widget';
|
|
20
|
+
export * from './service/notebook-service';
|
|
21
|
+
export * from './service/notebook-editor-service';
|
|
22
|
+
export * from './service/notebook-kernel-service';
|
|
23
|
+
export * from './service/notebook-execution-state-service';
|
|
24
|
+
export * from './service/notebook-model-resolver-service';
|
|
25
|
+
export * from './service/notebook-renderer-messaging-service';
|
|
26
|
+
export * from './renderers/cell-output-webview';
|
|
@@ -0,0 +1,79 @@
|
|
|
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 { Emitter, Resource, ResourceReadOptions, ResourceResolver, ResourceVersion, URI } from '@theia/core';
|
|
18
|
+
import { inject, injectable } from '@theia/core/shared/inversify';
|
|
19
|
+
import { CellUri } from '../common';
|
|
20
|
+
import { NotebookService } from './service/notebook-service';
|
|
21
|
+
import { NotebookCellModel } from './view-model/notebook-cell-model';
|
|
22
|
+
|
|
23
|
+
export class NotebookCellResource implements Resource {
|
|
24
|
+
|
|
25
|
+
protected readonly didChangeContentsEmitter = new Emitter<void>();
|
|
26
|
+
readonly onDidChangeContents = this.didChangeContentsEmitter.event;
|
|
27
|
+
|
|
28
|
+
version?: ResourceVersion | undefined;
|
|
29
|
+
encoding?: string | undefined;
|
|
30
|
+
isReadonly?: boolean | undefined;
|
|
31
|
+
|
|
32
|
+
private cell: NotebookCellModel;
|
|
33
|
+
|
|
34
|
+
constructor(public uri: URI, cell: NotebookCellModel) {
|
|
35
|
+
this.cell = cell;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
readContents(options?: ResourceReadOptions | undefined): Promise<string> {
|
|
39
|
+
return Promise.resolve(this.cell.source);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
dispose(): void {
|
|
43
|
+
this.didChangeContentsEmitter.dispose();
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
@injectable()
|
|
49
|
+
export class NotebookCellResourceResolver implements ResourceResolver {
|
|
50
|
+
|
|
51
|
+
@inject(NotebookService)
|
|
52
|
+
protected readonly notebookService: NotebookService;
|
|
53
|
+
|
|
54
|
+
async resolve(uri: URI): Promise<Resource> {
|
|
55
|
+
if (uri.scheme !== CellUri.scheme) {
|
|
56
|
+
throw new Error(`Cannot resolve cell uri with scheme '${uri.scheme}'`);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const parsedUri = CellUri.parse(uri);
|
|
60
|
+
if (!parsedUri) {
|
|
61
|
+
throw new Error(`Cannot parse uri '${uri.toString()}'`);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const notebookModel = this.notebookService.getNotebookEditorModel(parsedUri.notebook);
|
|
65
|
+
|
|
66
|
+
if (!notebookModel) {
|
|
67
|
+
throw new Error(`No notebook found for uri '${parsedUri.notebook}'`);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const notebookCellModel = notebookModel.cells.find(cell => cell.handle === parsedUri.handle);
|
|
71
|
+
|
|
72
|
+
if (!notebookCellModel) {
|
|
73
|
+
throw new Error(`No cell found with handle '${parsedUri.handle}' in '${parsedUri.notebook}'`);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return new NotebookCellResource(uri, notebookCellModel);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
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 } from '@theia/core';
|
|
18
|
+
import { WidgetFactory, NavigatableWidgetOptions, LabelProvider } from '@theia/core/lib/browser';
|
|
19
|
+
import { inject, injectable } from '@theia/core/shared/inversify';
|
|
20
|
+
import { NotebookEditorWidget, NotebookEditorContainerFactory, NotebookEditorProps } from './notebook-editor-widget';
|
|
21
|
+
import { NotebookService } from './service/notebook-service';
|
|
22
|
+
import { NotebookModelResolverService } from './service/notebook-model-resolver-service';
|
|
23
|
+
|
|
24
|
+
export interface NotebookEditorWidgetOptions extends NavigatableWidgetOptions {
|
|
25
|
+
notebookType: string;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
@injectable()
|
|
29
|
+
export class NotebookEditorWidgetFactory implements WidgetFactory {
|
|
30
|
+
readonly id: string = NotebookEditorWidget.ID;
|
|
31
|
+
|
|
32
|
+
@inject(NotebookService)
|
|
33
|
+
protected readonly notebookService: NotebookService;
|
|
34
|
+
|
|
35
|
+
@inject(NotebookModelResolverService)
|
|
36
|
+
protected readonly notebookModelResolver: NotebookModelResolverService;
|
|
37
|
+
|
|
38
|
+
@inject(LabelProvider)
|
|
39
|
+
protected readonly labelProvider: LabelProvider;
|
|
40
|
+
|
|
41
|
+
@inject(NotebookEditorContainerFactory)
|
|
42
|
+
protected readonly createNotebookEditorWidget: (props: NotebookEditorProps) => NotebookEditorWidget;
|
|
43
|
+
|
|
44
|
+
async createWidget(options?: NotebookEditorWidgetOptions): Promise<NotebookEditorWidget> {
|
|
45
|
+
if (!options) {
|
|
46
|
+
throw new Error('no options found for widget. Need at least uri and notebookType');
|
|
47
|
+
}
|
|
48
|
+
const uri = new URI(options.uri);
|
|
49
|
+
|
|
50
|
+
await this.notebookService.willOpenNotebook(options.notebookType);
|
|
51
|
+
|
|
52
|
+
const editor = await this.createEditor(uri, options.notebookType);
|
|
53
|
+
|
|
54
|
+
const icon = this.labelProvider.getIcon(uri);
|
|
55
|
+
editor.title.label = this.labelProvider.getName(uri);
|
|
56
|
+
editor.title.iconClass = icon + ' file-icon';
|
|
57
|
+
|
|
58
|
+
return editor;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
private async createEditor(uri: URI, notebookType: string): Promise<NotebookEditorWidget> {
|
|
62
|
+
|
|
63
|
+
return this.createNotebookEditorWidget({
|
|
64
|
+
uri,
|
|
65
|
+
notebookType,
|
|
66
|
+
notebookData: this.notebookModelResolver.resolve(uri, notebookType),
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
}
|
|
@@ -0,0 +1,157 @@
|
|
|
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 * as React from '@theia/core/shared/react';
|
|
18
|
+
import { CommandRegistry, MenuModelRegistry, URI } from '@theia/core';
|
|
19
|
+
import { ReactWidget, Navigatable, SaveableSource, Message, SaveableDelegate } from '@theia/core/lib/browser';
|
|
20
|
+
import { ReactNode } from '@theia/core/shared/react';
|
|
21
|
+
import { CellKind } from '../common';
|
|
22
|
+
import { CellRenderer as CellRenderer, NotebookCellListView } from './view/notebook-cell-list-view';
|
|
23
|
+
import { NotebookCodeCellRenderer } from './view/notebook-code-cell-view';
|
|
24
|
+
import { NotebookMarkdownCellRenderer } from './view/notebook-markdown-cell-view';
|
|
25
|
+
import { NotebookModel } from './view-model/notebook-model';
|
|
26
|
+
import { NotebookCellToolbarFactory } from './view/notebook-cell-toolbar-factory';
|
|
27
|
+
import { inject, injectable, interfaces } from '@theia/core/shared/inversify';
|
|
28
|
+
import { Emitter } from '@theia/core/shared/vscode-languageserver-protocol';
|
|
29
|
+
import { NotebookEditorWidgetService } from './service/notebook-editor-service';
|
|
30
|
+
import { NotebookMainToolbarRenderer } from './view/notebook-main-toolbar';
|
|
31
|
+
|
|
32
|
+
export const NotebookEditorContainerFactory = Symbol('NotebookModelFactory');
|
|
33
|
+
|
|
34
|
+
export function createNotebookEditorWidgetContainer(parent: interfaces.Container, props: NotebookEditorProps): interfaces.Container {
|
|
35
|
+
const child = parent.createChild();
|
|
36
|
+
|
|
37
|
+
child.bind(NotebookEditorProps).toConstantValue(props);
|
|
38
|
+
child.bind(NotebookEditorWidget).toSelf();
|
|
39
|
+
|
|
40
|
+
return child;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const NotebookEditorProps = Symbol('NotebookEditorProps');
|
|
44
|
+
|
|
45
|
+
export interface NotebookEditorProps {
|
|
46
|
+
uri: URI,
|
|
47
|
+
readonly notebookType: string,
|
|
48
|
+
notebookData: Promise<NotebookModel>
|
|
49
|
+
}
|
|
50
|
+
export const NOTEBOOK_EDITOR_ID_PREFIX = 'notebook:';
|
|
51
|
+
|
|
52
|
+
@injectable()
|
|
53
|
+
export class NotebookEditorWidget extends ReactWidget implements Navigatable, SaveableSource {
|
|
54
|
+
static readonly ID = 'notebook';
|
|
55
|
+
|
|
56
|
+
readonly saveable = new SaveableDelegate();
|
|
57
|
+
|
|
58
|
+
@inject(NotebookCellToolbarFactory)
|
|
59
|
+
protected readonly cellToolbarFactory: NotebookCellToolbarFactory;
|
|
60
|
+
|
|
61
|
+
@inject(CommandRegistry)
|
|
62
|
+
protected commandRegistry: CommandRegistry;
|
|
63
|
+
|
|
64
|
+
@inject(MenuModelRegistry)
|
|
65
|
+
protected menuRegistry: MenuModelRegistry;
|
|
66
|
+
|
|
67
|
+
@inject(NotebookEditorWidgetService)
|
|
68
|
+
protected notebookEditorService: NotebookEditorWidgetService;
|
|
69
|
+
|
|
70
|
+
@inject(NotebookMainToolbarRenderer)
|
|
71
|
+
protected notebookMainToolbarRenderer: NotebookMainToolbarRenderer;
|
|
72
|
+
|
|
73
|
+
protected readonly onDidChangeModelEmitter = new Emitter<void>();
|
|
74
|
+
readonly onDidChangeModel = this.onDidChangeModelEmitter.event;
|
|
75
|
+
|
|
76
|
+
protected readonly renderers = new Map<CellKind, CellRenderer>();
|
|
77
|
+
protected _model?: NotebookModel;
|
|
78
|
+
|
|
79
|
+
get notebookType(): string {
|
|
80
|
+
return this.props.notebookType;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
get model(): NotebookModel | undefined {
|
|
84
|
+
return this._model;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
constructor(
|
|
88
|
+
@inject(NotebookCodeCellRenderer) codeCellRenderer: NotebookCodeCellRenderer,
|
|
89
|
+
@inject(NotebookMarkdownCellRenderer) markdownCellRenderer: NotebookMarkdownCellRenderer,
|
|
90
|
+
@inject(NotebookEditorProps) private readonly props: NotebookEditorProps) {
|
|
91
|
+
super();
|
|
92
|
+
this.id = NOTEBOOK_EDITOR_ID_PREFIX + this.props.uri.toString();
|
|
93
|
+
this.node.tabIndex = -1;
|
|
94
|
+
|
|
95
|
+
this.title.closable = true;
|
|
96
|
+
this.update();
|
|
97
|
+
|
|
98
|
+
this.toDispose.push(this.onDidChangeModelEmitter);
|
|
99
|
+
|
|
100
|
+
this.renderers.set(CellKind.Markup, markdownCellRenderer);
|
|
101
|
+
this.renderers.set(CellKind.Code, codeCellRenderer);
|
|
102
|
+
this.waitForData();
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
protected async waitForData(): Promise<void> {
|
|
106
|
+
this._model = await this.props.notebookData;
|
|
107
|
+
this.saveable.set(this._model);
|
|
108
|
+
this.toDispose.push(this._model);
|
|
109
|
+
// Ensure that the model is loaded before adding the editor
|
|
110
|
+
this.notebookEditorService.addNotebookEditor(this);
|
|
111
|
+
this.update();
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
protected override onActivateRequest(msg: Message): void {
|
|
115
|
+
super.onActivateRequest(msg);
|
|
116
|
+
this.node.focus();
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
getResourceUri(): URI | undefined {
|
|
120
|
+
return this.props.uri;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
createMoveToUri(resourceUri: URI): URI | undefined {
|
|
124
|
+
return this.props.uri;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
undo(): void {
|
|
128
|
+
this.model?.undo();
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
redo(): void {
|
|
132
|
+
this.model?.redo();
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
protected render(): ReactNode {
|
|
136
|
+
if (this._model) {
|
|
137
|
+
return <div>
|
|
138
|
+
{this.notebookMainToolbarRenderer.render(this._model)}
|
|
139
|
+
<NotebookCellListView renderers={this.renderers}
|
|
140
|
+
notebookModel={this._model}
|
|
141
|
+
toolbarRenderer={this.cellToolbarFactory}
|
|
142
|
+
commandRegistry={this.commandRegistry} />
|
|
143
|
+
</div>;
|
|
144
|
+
} else {
|
|
145
|
+
return <div></div>;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
protected override onAfterAttach(msg: Message): void {
|
|
150
|
+
super.onAfterAttach(msg);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
protected override onAfterDetach(msg: Message): void {
|
|
154
|
+
super.onAfterDetach(msg);
|
|
155
|
+
this.notebookEditorService.removeNotebookEditor(this);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
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 { OpenHandler, 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 } 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 { NotebookCellToolbarFactory } from './view/notebook-cell-toolbar-factory';
|
|
31
|
+
import { createNotebookModelContainer, NotebookModel, NotebookModelFactory, NotebookModelProps } from './view-model/notebook-model';
|
|
32
|
+
import { createNotebookCellModelContainer, NotebookCellModel, NotebookCellModelFactory, NotebookCellModelProps } from './view-model/notebook-cell-model';
|
|
33
|
+
import { createNotebookEditorWidgetContainer, NotebookEditorContainerFactory, NotebookEditorProps, NotebookEditorWidget } from './notebook-editor-widget';
|
|
34
|
+
import { NotebookCodeCellRenderer } from './view/notebook-code-cell-view';
|
|
35
|
+
import { NotebookMarkdownCellRenderer } from './view/notebook-markdown-cell-view';
|
|
36
|
+
import { NotebookActionsContribution } from './contributions/notebook-actions-contribution';
|
|
37
|
+
import { NotebookExecutionService } from './service/notebook-execution-service';
|
|
38
|
+
import { NotebookExecutionStateService } from './service/notebook-execution-state-service';
|
|
39
|
+
import { NotebookKernelService } from './service/notebook-kernel-service';
|
|
40
|
+
import { KernelPickerMRUStrategy, NotebookKernelQuickPickService } from './service/notebook-kernel-quick-pick-service';
|
|
41
|
+
import { NotebookKernelHistoryService } from './service/notebook-kernel-history-service';
|
|
42
|
+
import { NotebookEditorWidgetService } from './service/notebook-editor-service';
|
|
43
|
+
import { NotebookRendererMessagingService } from './service/notebook-renderer-messaging-service';
|
|
44
|
+
import { NotebookColorContribution } from './contributions/notebook-color-contribution';
|
|
45
|
+
import { NotebookCellContextManager } from './service/notebook-cell-context-manager';
|
|
46
|
+
import { NotebookMainToolbarRenderer } from './view/notebook-main-toolbar';
|
|
47
|
+
|
|
48
|
+
export default new ContainerModule(bind => {
|
|
49
|
+
bind(NotebookColorContribution).toSelf().inSingletonScope();
|
|
50
|
+
bind(ColorContribution).toService(NotebookColorContribution);
|
|
51
|
+
|
|
52
|
+
bind(NotebookOpenHandler).toSelf().inSingletonScope();
|
|
53
|
+
bind(OpenHandler).toService(NotebookOpenHandler);
|
|
54
|
+
|
|
55
|
+
bind(NotebookTypeRegistry).toSelf().inSingletonScope();
|
|
56
|
+
bind(NotebookRendererRegistry).toSelf().inSingletonScope();
|
|
57
|
+
|
|
58
|
+
bind(WidgetFactory).to(NotebookEditorWidgetFactory).inSingletonScope();
|
|
59
|
+
bind(NotebookCellToolbarFactory).toSelf().inSingletonScope();
|
|
60
|
+
|
|
61
|
+
bind(NotebookService).toSelf().inSingletonScope();
|
|
62
|
+
bind(NotebookEditorWidgetService).toSelf().inSingletonScope();
|
|
63
|
+
bind(NotebookExecutionService).toSelf().inSingletonScope();
|
|
64
|
+
bind(NotebookExecutionStateService).toSelf().inSingletonScope();
|
|
65
|
+
bind(NotebookKernelService).toSelf().inSingletonScope();
|
|
66
|
+
bind(NotebookRendererMessagingService).toSelf().inSingletonScope();
|
|
67
|
+
bind(NotebookKernelHistoryService).toSelf().inSingletonScope();
|
|
68
|
+
bind(NotebookKernelQuickPickService).to(KernelPickerMRUStrategy).inSingletonScope();
|
|
69
|
+
|
|
70
|
+
bind(NotebookCellResourceResolver).toSelf().inSingletonScope();
|
|
71
|
+
bind(ResourceResolver).toService(NotebookCellResourceResolver);
|
|
72
|
+
bind(NotebookModelResolverService).toSelf().inSingletonScope();
|
|
73
|
+
|
|
74
|
+
bind(NotebookCellActionContribution).toSelf().inSingletonScope();
|
|
75
|
+
bind(MenuContribution).toService(NotebookCellActionContribution);
|
|
76
|
+
bind(CommandContribution).toService(NotebookCellActionContribution);
|
|
77
|
+
|
|
78
|
+
bind(NotebookActionsContribution).toSelf().inSingletonScope();
|
|
79
|
+
bind(CommandContribution).toService(NotebookActionsContribution);
|
|
80
|
+
bind(MenuContribution).toService(NotebookActionsContribution);
|
|
81
|
+
|
|
82
|
+
bind(NotebookCodeCellRenderer).toSelf().inSingletonScope();
|
|
83
|
+
bind(NotebookMarkdownCellRenderer).toSelf().inSingletonScope();
|
|
84
|
+
bind(NotebookMainToolbarRenderer).toSelf().inSingletonScope();
|
|
85
|
+
|
|
86
|
+
bind(NotebookEditorContainerFactory).toFactory(ctx => (props: NotebookEditorProps) =>
|
|
87
|
+
createNotebookEditorWidgetContainer(ctx.container, props).get(NotebookEditorWidget)
|
|
88
|
+
);
|
|
89
|
+
bind(NotebookModelFactory).toFactory(ctx => (props: NotebookModelProps) =>
|
|
90
|
+
createNotebookModelContainer(ctx.container, props).get(NotebookModel)
|
|
91
|
+
);
|
|
92
|
+
bind(NotebookCellModelFactory).toFactory(ctx => (props: NotebookCellModelProps) =>
|
|
93
|
+
createNotebookCellModelContainer(ctx.container, props, NotebookCellContextManager).get(NotebookCellModel)
|
|
94
|
+
);
|
|
95
|
+
});
|
|
@@ -0,0 +1,87 @@
|
|
|
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 } from '@theia/core';
|
|
18
|
+
import { NavigatableWidgetOpenHandler, WidgetOpenerOptions } from '@theia/core/lib/browser';
|
|
19
|
+
import { inject, injectable } from '@theia/core/shared/inversify';
|
|
20
|
+
import { NotebookFileSelector, NotebookTypeDescriptor } from '../common/notebook-protocol';
|
|
21
|
+
import { NotebookTypeRegistry } from './notebook-type-registry';
|
|
22
|
+
import { NotebookEditorWidget } from './notebook-editor-widget';
|
|
23
|
+
import { match } from '@theia/core/lib/common/glob';
|
|
24
|
+
import { NotebookEditorWidgetOptions } from './notebook-editor-widget-factory';
|
|
25
|
+
|
|
26
|
+
@injectable()
|
|
27
|
+
export class NotebookOpenHandler extends NavigatableWidgetOpenHandler<NotebookEditorWidget> {
|
|
28
|
+
|
|
29
|
+
id: string = 'notebook';
|
|
30
|
+
|
|
31
|
+
constructor(@inject(NotebookTypeRegistry) private notebookTypeRegistry: NotebookTypeRegistry) {
|
|
32
|
+
super();
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
canHandle(uri: URI, options?: WidgetOpenerOptions | undefined): MaybePromise<number> {
|
|
36
|
+
const priorities = this.notebookTypeRegistry.notebookTypes
|
|
37
|
+
.filter(notebook => notebook.selector && this.matches(notebook.selector, uri))
|
|
38
|
+
.map(notebook => this.calculatePriority(notebook));
|
|
39
|
+
return Math.max(...priorities);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
protected findHighestPriorityType(uri: URI): NotebookTypeDescriptor | undefined {
|
|
43
|
+
const matchingTypes = this.notebookTypeRegistry.notebookTypes
|
|
44
|
+
.filter(notebookType => notebookType.selector && this.matches(notebookType.selector, uri))
|
|
45
|
+
.map(notebookType => ({ descriptor: notebookType, priority: this.calculatePriority(notebookType) }));
|
|
46
|
+
|
|
47
|
+
if (matchingTypes.length === 0) {
|
|
48
|
+
return undefined;
|
|
49
|
+
}
|
|
50
|
+
let type = matchingTypes[0];
|
|
51
|
+
for (let i = 1; i < matchingTypes.length; i++) {
|
|
52
|
+
const notebookType = matchingTypes[i];
|
|
53
|
+
if (notebookType.priority > type.priority) {
|
|
54
|
+
type = notebookType;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return type.descriptor;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
protected calculatePriority(notebookType: NotebookTypeDescriptor | undefined): number {
|
|
61
|
+
if (!notebookType) {
|
|
62
|
+
return -1;
|
|
63
|
+
}
|
|
64
|
+
return notebookType.priority === 'option' ? 100 : 200;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
protected override createWidgetOptions(uri: URI, options?: WidgetOpenerOptions | undefined): NotebookEditorWidgetOptions {
|
|
68
|
+
const widgetOptions = super.createWidgetOptions(uri, options);
|
|
69
|
+
const notebookType = this.findHighestPriorityType(uri);
|
|
70
|
+
if (!notebookType) {
|
|
71
|
+
throw new Error('No notebook types registered for uri: ' + uri.toString());
|
|
72
|
+
}
|
|
73
|
+
return {
|
|
74
|
+
notebookType: notebookType.type,
|
|
75
|
+
...widgetOptions
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
matches(selectors: readonly NotebookFileSelector[], resource: URI): boolean {
|
|
80
|
+
return selectors.some(selector => this.selectorMatches(selector, resource));
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
selectorMatches(selector: NotebookFileSelector, resource: URI): boolean {
|
|
84
|
+
return !!selector.filenamePattern
|
|
85
|
+
&& match(selector.filenamePattern, resource.path.name + resource.path.ext);
|
|
86
|
+
}
|
|
87
|
+
}
|