@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.
Files changed (188) hide show
  1. package/README.md +30 -0
  2. package/lib/browser/contributions/notebook-actions-contribution.d.ts +27 -0
  3. package/lib/browser/contributions/notebook-actions-contribution.d.ts.map +1 -0
  4. package/lib/browser/contributions/notebook-actions-contribution.js +172 -0
  5. package/lib/browser/contributions/notebook-actions-contribution.js.map +1 -0
  6. package/lib/browser/contributions/notebook-cell-actions-contribution.d.ts +30 -0
  7. package/lib/browser/contributions/notebook-cell-actions-contribution.d.ts.map +1 -0
  8. package/lib/browser/contributions/notebook-cell-actions-contribution.js +200 -0
  9. package/lib/browser/contributions/notebook-cell-actions-contribution.js.map +1 -0
  10. package/lib/browser/contributions/notebook-color-contribution.d.ts +6 -0
  11. package/lib/browser/contributions/notebook-color-contribution.d.ts.map +1 -0
  12. package/lib/browser/contributions/notebook-color-contribution.js +252 -0
  13. package/lib/browser/contributions/notebook-color-contribution.js.map +1 -0
  14. package/lib/browser/contributions/notebook-context-keys.d.ts +38 -0
  15. package/lib/browser/contributions/notebook-context-keys.d.ts.map +1 -0
  16. package/lib/browser/contributions/notebook-context-keys.js +95 -0
  17. package/lib/browser/contributions/notebook-context-keys.js.map +1 -0
  18. package/lib/browser/index.d.ts +11 -0
  19. package/lib/browser/index.d.ts.map +1 -0
  20. package/lib/browser/index.js +38 -0
  21. package/lib/browser/index.js.map +1 -0
  22. package/lib/browser/notebook-cell-resource-resolver.d.ts +20 -0
  23. package/lib/browser/notebook-cell-resource-resolver.d.ts.map +1 -0
  24. package/lib/browser/notebook-cell-resource-resolver.js +75 -0
  25. package/lib/browser/notebook-cell-resource-resolver.js.map +1 -0
  26. package/lib/browser/notebook-editor-widget-factory.d.ts +17 -0
  27. package/lib/browser/notebook-editor-widget-factory.d.ts.map +1 -0
  28. package/lib/browser/notebook-editor-widget-factory.js +78 -0
  29. package/lib/browser/notebook-editor-widget-factory.js.map +1 -0
  30. package/lib/browser/notebook-editor-widget.d.ts +49 -0
  31. package/lib/browser/notebook-editor-widget.d.ts.map +1 -0
  32. package/lib/browser/notebook-editor-widget.js +150 -0
  33. package/lib/browser/notebook-editor-widget.js.map +1 -0
  34. package/lib/browser/notebook-frontend-module.d.ts +5 -0
  35. package/lib/browser/notebook-frontend-module.d.ts.map +1 -0
  36. package/lib/browser/notebook-frontend-module.js +81 -0
  37. package/lib/browser/notebook-frontend-module.js.map +1 -0
  38. package/lib/browser/notebook-open-handler.d.ts +18 -0
  39. package/lib/browser/notebook-open-handler.d.ts.map +1 -0
  40. package/lib/browser/notebook-open-handler.js +94 -0
  41. package/lib/browser/notebook-open-handler.js.map +1 -0
  42. package/lib/browser/notebook-renderer-registry.d.ts +17 -0
  43. package/lib/browser/notebook-renderer-registry.d.ts.map +1 -0
  44. package/lib/browser/notebook-renderer-registry.js +63 -0
  45. package/lib/browser/notebook-renderer-registry.js.map +1 -0
  46. package/lib/browser/notebook-type-registry.d.ts +7 -0
  47. package/lib/browser/notebook-type-registry.d.ts.map +1 -0
  48. package/lib/browser/notebook-type-registry.js +42 -0
  49. package/lib/browser/notebook-type-registry.js.map +1 -0
  50. package/lib/browser/renderers/cell-output-webview.d.ts +12 -0
  51. package/lib/browser/renderers/cell-output-webview.d.ts.map +1 -0
  52. package/lib/browser/renderers/cell-output-webview.js +20 -0
  53. package/lib/browser/renderers/cell-output-webview.js.map +1 -0
  54. package/lib/browser/service/notebook-cell-context-manager.d.ts +16 -0
  55. package/lib/browser/service/notebook-cell-context-manager.d.ts.map +1 -0
  56. package/lib/browser/service/notebook-cell-context-manager.js +83 -0
  57. package/lib/browser/service/notebook-cell-context-manager.js.map +1 -0
  58. package/lib/browser/service/notebook-editor-service.d.ts +22 -0
  59. package/lib/browser/service/notebook-editor-service.d.ts.map +1 -0
  60. package/lib/browser/service/notebook-editor-service.js +95 -0
  61. package/lib/browser/service/notebook-editor-service.js.map +1 -0
  62. package/lib/browser/service/notebook-execution-service.d.ts +25 -0
  63. package/lib/browser/service/notebook-execution-service.d.ts.map +1 -0
  64. package/lib/browser/service/notebook-execution-service.js +140 -0
  65. package/lib/browser/service/notebook-execution-service.js.map +1 -0
  66. package/lib/browser/service/notebook-execution-state-service.d.ts +94 -0
  67. package/lib/browser/service/notebook-execution-state-service.d.ts.map +1 -0
  68. package/lib/browser/service/notebook-execution-state-service.js +250 -0
  69. package/lib/browser/service/notebook-execution-state-service.js.map +1 -0
  70. package/lib/browser/service/notebook-kernel-history-service.d.ts +23 -0
  71. package/lib/browser/service/notebook-kernel-history-service.d.ts.map +1 -0
  72. package/lib/browser/service/notebook-kernel-history-service.js +109 -0
  73. package/lib/browser/service/notebook-kernel-history-service.js.map +1 -0
  74. package/lib/browser/service/notebook-kernel-quick-pick-service.d.ts +65 -0
  75. package/lib/browser/service/notebook-kernel-quick-pick-service.d.ts.map +1 -0
  76. package/lib/browser/service/notebook-kernel-quick-pick-service.js +430 -0
  77. package/lib/browser/service/notebook-kernel-quick-pick-service.js.map +1 -0
  78. package/lib/browser/service/notebook-kernel-service.d.ts +112 -0
  79. package/lib/browser/service/notebook-kernel-service.d.ts.map +1 -0
  80. package/lib/browser/service/notebook-kernel-service.js +274 -0
  81. package/lib/browser/service/notebook-kernel-service.js.map +1 -0
  82. package/lib/browser/service/notebook-model-resolver-service.d.ts +26 -0
  83. package/lib/browser/service/notebook-model-resolver-service.d.ts.map +1 -0
  84. package/lib/browser/service/notebook-model-resolver-service.js +139 -0
  85. package/lib/browser/service/notebook-model-resolver-service.js.map +1 -0
  86. package/lib/browser/service/notebook-renderer-messaging-service.d.ts +30 -0
  87. package/lib/browser/service/notebook-renderer-messaging-service.d.ts.map +1 -0
  88. package/lib/browser/service/notebook-renderer-messaging-service.js +94 -0
  89. package/lib/browser/service/notebook-renderer-messaging-service.js.map +1 -0
  90. package/lib/browser/service/notebook-service.d.ts +64 -0
  91. package/lib/browser/service/notebook-service.d.ts.map +1 -0
  92. package/lib/browser/service/notebook-service.js +162 -0
  93. package/lib/browser/service/notebook-service.js.map +1 -0
  94. package/lib/browser/view/notebook-cell-editor.d.ts +26 -0
  95. package/lib/browser/view/notebook-cell-editor.d.ts.map +1 -0
  96. package/lib/browser/view/notebook-cell-editor.js +79 -0
  97. package/lib/browser/view/notebook-cell-editor.js.map +1 -0
  98. package/lib/browser/view/notebook-cell-list-view.d.ts +43 -0
  99. package/lib/browser/view/notebook-cell-list-view.d.ts.map +1 -0
  100. package/lib/browser/view/notebook-cell-list-view.js +111 -0
  101. package/lib/browser/view/notebook-cell-list-view.js.map +1 -0
  102. package/lib/browser/view/notebook-cell-toolbar-factory.d.ts +25 -0
  103. package/lib/browser/view/notebook-cell-toolbar-factory.d.ts.map +1 -0
  104. package/lib/browser/view/notebook-cell-toolbar-factory.js +93 -0
  105. package/lib/browser/view/notebook-cell-toolbar-factory.js.map +1 -0
  106. package/lib/browser/view/notebook-cell-toolbar.d.ts +25 -0
  107. package/lib/browser/view/notebook-cell-toolbar.d.ts.map +1 -0
  108. package/lib/browser/view/notebook-cell-toolbar.js +50 -0
  109. package/lib/browser/view/notebook-cell-toolbar.js.map +1 -0
  110. package/lib/browser/view/notebook-code-cell-view.d.ts +47 -0
  111. package/lib/browser/view/notebook-code-cell-view.d.ts.map +1 -0
  112. package/lib/browser/view/notebook-code-cell-view.js +166 -0
  113. package/lib/browser/view/notebook-code-cell-view.js.map +1 -0
  114. package/lib/browser/view/notebook-main-toolbar.d.ts +31 -0
  115. package/lib/browser/view/notebook-main-toolbar.d.ts.map +1 -0
  116. package/lib/browser/view/notebook-main-toolbar.js +118 -0
  117. package/lib/browser/view/notebook-main-toolbar.js.map +1 -0
  118. package/lib/browser/view/notebook-markdown-cell-view.d.ts +12 -0
  119. package/lib/browser/view/notebook-markdown-cell-view.d.ts.map +1 -0
  120. package/lib/browser/view/notebook-markdown-cell-view.js +70 -0
  121. package/lib/browser/view/notebook-markdown-cell-view.js.map +1 -0
  122. package/lib/browser/view-model/notebook-cell-model.d.ts +74 -0
  123. package/lib/browser/view-model/notebook-cell-model.d.ts.map +1 -0
  124. package/lib/browser/view-model/notebook-cell-model.js +226 -0
  125. package/lib/browser/view-model/notebook-cell-model.js.map +1 -0
  126. package/lib/browser/view-model/notebook-cell-output-model.d.ts +19 -0
  127. package/lib/browser/view-model/notebook-cell-output-model.d.ts.map +1 -0
  128. package/lib/browser/view-model/notebook-cell-output-model.js +61 -0
  129. package/lib/browser/view-model/notebook-cell-output-model.js.map +1 -0
  130. package/lib/browser/view-model/notebook-model.d.ts +59 -0
  131. package/lib/browser/view-model/notebook-model.d.ts.map +1 -0
  132. package/lib/browser/view-model/notebook-model.js +315 -0
  133. package/lib/browser/view-model/notebook-model.js.map +1 -0
  134. package/lib/common/index.d.ts +3 -0
  135. package/lib/common/index.d.ts.map +1 -0
  136. package/lib/common/index.js +30 -0
  137. package/lib/common/index.js.map +1 -0
  138. package/lib/common/notebook-common.d.ts +344 -0
  139. package/lib/common/notebook-common.d.ts.map +1 -0
  140. package/lib/common/notebook-common.js +112 -0
  141. package/lib/common/notebook-common.js.map +1 -0
  142. package/lib/common/notebook-protocol.d.ts +21 -0
  143. package/lib/common/notebook-protocol.d.ts.map +1 -0
  144. package/lib/common/notebook-protocol.js +18 -0
  145. package/lib/common/notebook-protocol.js.map +1 -0
  146. package/lib/common/notebook-range.d.ts +14 -0
  147. package/lib/common/notebook-range.d.ts.map +1 -0
  148. package/lib/common/notebook-range.js +18 -0
  149. package/lib/common/notebook-range.js.map +1 -0
  150. package/package.json +52 -0
  151. package/src/browser/contributions/notebook-actions-contribution.ts +171 -0
  152. package/src/browser/contributions/notebook-cell-actions-contribution.ts +204 -0
  153. package/src/browser/contributions/notebook-color-contribution.ts +268 -0
  154. package/src/browser/contributions/notebook-context-keys.ts +99 -0
  155. package/src/browser/index.ts +26 -0
  156. package/src/browser/notebook-cell-resource-resolver.ts +79 -0
  157. package/src/browser/notebook-editor-widget-factory.ts +70 -0
  158. package/src/browser/notebook-editor-widget.tsx +157 -0
  159. package/src/browser/notebook-frontend-module.ts +95 -0
  160. package/src/browser/notebook-open-handler.ts +87 -0
  161. package/src/browser/notebook-renderer-registry.ts +62 -0
  162. package/src/browser/notebook-type-registry.ts +30 -0
  163. package/src/browser/renderers/cell-output-webview.ts +32 -0
  164. package/src/browser/service/notebook-cell-context-manager.ts +70 -0
  165. package/src/browser/service/notebook-editor-service.ts +86 -0
  166. package/src/browser/service/notebook-execution-service.ts +139 -0
  167. package/src/browser/service/notebook-execution-state-service.ts +322 -0
  168. package/src/browser/service/notebook-kernel-history-service.ts +109 -0
  169. package/src/browser/service/notebook-kernel-quick-pick-service.ts +494 -0
  170. package/src/browser/service/notebook-kernel-service.ts +357 -0
  171. package/src/browser/service/notebook-model-resolver-service.ts +141 -0
  172. package/src/browser/service/notebook-renderer-messaging-service.ts +111 -0
  173. package/src/browser/service/notebook-service.ts +178 -0
  174. package/src/browser/style/index.css +236 -0
  175. package/src/browser/view/notebook-cell-editor.tsx +97 -0
  176. package/src/browser/view/notebook-cell-list-view.tsx +171 -0
  177. package/src/browser/view/notebook-cell-toolbar-factory.tsx +91 -0
  178. package/src/browser/view/notebook-cell-toolbar.tsx +70 -0
  179. package/src/browser/view/notebook-code-cell-view.tsx +190 -0
  180. package/src/browser/view/notebook-main-toolbar.tsx +115 -0
  181. package/src/browser/view/notebook-markdown-cell-view.tsx +73 -0
  182. package/src/browser/view-model/notebook-cell-model.ts +271 -0
  183. package/src/browser/view-model/notebook-cell-output-model.ts +69 -0
  184. package/src/browser/view-model/notebook-model.ts +372 -0
  185. package/src/common/index.ts +18 -0
  186. package/src/common/notebook-common.ts +462 -0
  187. package/src/common/notebook-protocol.ts +35 -0
  188. package/src/common/notebook-range.ts +30 -0
@@ -0,0 +1,171 @@
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 { Command, CommandContribution, CommandRegistry, CompoundMenuNodeRole, MenuContribution, MenuModelRegistry, nls } from '@theia/core';
18
+ import { inject, injectable } from '@theia/core/shared/inversify';
19
+ import { ApplicationShell, codicon, CommonCommands } from '@theia/core/lib/browser';
20
+ import { NotebookModel } from '../view-model/notebook-model';
21
+ import { NotebookService } from '../service/notebook-service';
22
+ import { CellEditType, CellKind } from '../../common';
23
+ import { KernelPickerMRUStrategy, NotebookKernelQuickPickService } from '../service/notebook-kernel-quick-pick-service';
24
+ import { NotebookExecutionService } from '../service/notebook-execution-service';
25
+ import { NotebookEditorWidget } from '../notebook-editor-widget';
26
+
27
+ export namespace NotebookCommands {
28
+ export const ADD_NEW_CELL_COMMAND = Command.toDefaultLocalizedCommand({
29
+ id: 'notebook.add-new-cell',
30
+ iconClass: codicon('add')
31
+ });
32
+
33
+ export const ADD_NEW_MARKDOWN_CELL_COMMAND = Command.toDefaultLocalizedCommand({
34
+ id: 'notebook.add-new-markdown-cell',
35
+ iconClass: codicon('add')
36
+ });
37
+
38
+ export const ADD_NEW_CODE_CELL_COMMAND = Command.toDefaultLocalizedCommand({
39
+ id: 'notebook.add-new-code-cell',
40
+ iconClass: codicon('add')
41
+ });
42
+
43
+ export const SELECT_KERNEL_COMMAND = Command.toDefaultLocalizedCommand({
44
+ id: 'notebook.selectKernel',
45
+ category: 'Notebook',
46
+ iconClass: codicon('server-environment')
47
+ });
48
+
49
+ export const EXECUTE_NOTEBOOK_COMMAND = Command.toDefaultLocalizedCommand({
50
+ id: 'notebook.execute',
51
+ category: 'Notebook',
52
+ iconClass: codicon('run-all')
53
+ });
54
+
55
+ export const CLEAR_ALL_OUTPUTS_COMMAND = Command.toDefaultLocalizedCommand({
56
+ id: 'notebook.clear-all-outputs',
57
+ category: 'Notebook',
58
+ iconClass: codicon('clear-all')
59
+ });
60
+ }
61
+
62
+ @injectable()
63
+ export class NotebookActionsContribution implements CommandContribution, MenuContribution {
64
+
65
+ @inject(NotebookService)
66
+ protected notebookService: NotebookService;
67
+
68
+ @inject(NotebookKernelQuickPickService)
69
+ protected notebookKernelQuickPickService: KernelPickerMRUStrategy;
70
+
71
+ @inject(NotebookExecutionService)
72
+ protected notebookExecutionService: NotebookExecutionService;
73
+
74
+ @inject(ApplicationShell)
75
+ protected shell: ApplicationShell;
76
+
77
+ registerCommands(commands: CommandRegistry): void {
78
+ commands.registerCommand(NotebookCommands.ADD_NEW_CELL_COMMAND, {
79
+ execute: (notebookModel: NotebookModel, cellKind: CellKind, index?: number) => {
80
+ const insertIndex = index ?? (notebookModel.selectedCell ? notebookModel.cells.indexOf(notebookModel.selectedCell) : 0);
81
+ let firstCodeCell;
82
+ if (cellKind === CellKind.Code) {
83
+ firstCodeCell = notebookModel.cells.find(cell => cell.cellKind === CellKind.Code);
84
+ }
85
+
86
+ notebookModel.applyEdits([{
87
+ editType: CellEditType.Replace,
88
+ index: insertIndex,
89
+ count: 0,
90
+ cells: [{
91
+ cellKind,
92
+ language: firstCodeCell?.language ?? 'markdown',
93
+ source: '',
94
+ outputs: [],
95
+ metadata: {},
96
+ }]
97
+ }], true);
98
+ }
99
+ });
100
+
101
+ commands.registerCommand(NotebookCommands.ADD_NEW_MARKDOWN_CELL_COMMAND, {
102
+ execute: (notebookModel: NotebookModel) => commands.executeCommand(NotebookCommands.ADD_NEW_CELL_COMMAND.id, notebookModel, CellKind.Markup)
103
+ });
104
+
105
+ commands.registerCommand(NotebookCommands.ADD_NEW_CODE_CELL_COMMAND, {
106
+ execute: (notebookModel: NotebookModel) => commands.executeCommand(NotebookCommands.ADD_NEW_CELL_COMMAND.id, notebookModel, CellKind.Code)
107
+ });
108
+
109
+ commands.registerCommand(NotebookCommands.SELECT_KERNEL_COMMAND, {
110
+ execute: (notebookModel: NotebookModel) => this.notebookKernelQuickPickService.showQuickPick(notebookModel)
111
+ });
112
+
113
+ commands.registerCommand(NotebookCommands.EXECUTE_NOTEBOOK_COMMAND, {
114
+ execute: (notebookModel: NotebookModel) => this.notebookExecutionService.executeNotebookCells(notebookModel, notebookModel.cells)
115
+ });
116
+
117
+ commands.registerCommand(NotebookCommands.CLEAR_ALL_OUTPUTS_COMMAND, {
118
+ execute: (notebookModel: NotebookModel) =>
119
+ notebookModel.cells.forEach(cell => cell.spliceNotebookCellOutputs({ start: 0, deleteCount: cell.outputs.length, newOutputs: [] }))
120
+ });
121
+
122
+ commands.registerHandler(CommonCommands.UNDO.id, {
123
+ isEnabled: () => this.shell.activeWidget instanceof NotebookEditorWidget,
124
+ execute: () => (this.shell.activeWidget as NotebookEditorWidget).undo()
125
+ });
126
+ commands.registerHandler(CommonCommands.REDO.id, {
127
+ isEnabled: () => this.shell.activeWidget instanceof NotebookEditorWidget,
128
+ execute: () => (this.shell.activeWidget as NotebookEditorWidget).redo()
129
+ });
130
+ }
131
+
132
+ registerMenus(menus: MenuModelRegistry): void {
133
+ // independent submenu for plugins to add commands
134
+ menus.registerIndependentSubmenu(NotebookMenus.NOTEBOOK_MAIN_TOOLBAR, 'Notebook Main Toolbar');
135
+ // Add Notebook Cell items
136
+ menus.registerSubmenu(NotebookMenus.NOTEBOOK_MAIN_TOOLBAR_CELL_ADD_GROUP, 'Add Notebook Cell', { role: CompoundMenuNodeRole.Group });
137
+ menus.registerMenuAction(NotebookMenus.NOTEBOOK_MAIN_TOOLBAR_CELL_ADD_GROUP, {
138
+ commandId: NotebookCommands.ADD_NEW_CODE_CELL_COMMAND.id,
139
+ label: nls.localizeByDefault('Code'),
140
+ icon: codicon('add'),
141
+ });
142
+ menus.registerMenuAction(NotebookMenus.NOTEBOOK_MAIN_TOOLBAR_CELL_ADD_GROUP, {
143
+ commandId: NotebookCommands.ADD_NEW_MARKDOWN_CELL_COMMAND.id,
144
+ label: nls.localizeByDefault('Markdown'),
145
+ icon: codicon('add'),
146
+ });
147
+
148
+ // Execution related items
149
+ menus.registerSubmenu(NotebookMenus.NOTEBOOK_MAIN_TOOLBAR_EXECUTION_GROUP, 'Cell Execution', { role: CompoundMenuNodeRole.Group });
150
+ menus.registerMenuAction(NotebookMenus.NOTEBOOK_MAIN_TOOLBAR_EXECUTION_GROUP, {
151
+ commandId: NotebookCommands.EXECUTE_NOTEBOOK_COMMAND.id,
152
+ label: nls.localizeByDefault('Run All'),
153
+ icon: codicon('run-all'),
154
+ order: '10'
155
+ });
156
+ menus.registerMenuAction(NotebookMenus.NOTEBOOK_MAIN_TOOLBAR_EXECUTION_GROUP, {
157
+ commandId: NotebookCommands.CLEAR_ALL_OUTPUTS_COMMAND.id,
158
+ label: nls.localizeByDefault('Clear All Outputs'),
159
+ icon: codicon('clear-all'),
160
+ order: '30'
161
+ });
162
+ // other items
163
+ }
164
+
165
+ }
166
+
167
+ export namespace NotebookMenus {
168
+ export const NOTEBOOK_MAIN_TOOLBAR = 'notebook/toolbar';
169
+ export const NOTEBOOK_MAIN_TOOLBAR_CELL_ADD_GROUP = [NOTEBOOK_MAIN_TOOLBAR, 'cell-add-group'];
170
+ export const NOTEBOOK_MAIN_TOOLBAR_EXECUTION_GROUP = [NOTEBOOK_MAIN_TOOLBAR, 'cell-execution-group'];
171
+ }
@@ -0,0 +1,204 @@
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 { Command, CommandContribution, CommandRegistry, CompoundMenuNodeRole, MenuContribution, MenuModelRegistry, nls } from '@theia/core';
18
+ import { codicon } from '@theia/core/lib/browser';
19
+ import { inject, injectable, postConstruct } from '@theia/core/shared/inversify';
20
+ import { NotebookModel } from '../view-model/notebook-model';
21
+ import { NotebookCellModel } from '../view-model/notebook-cell-model';
22
+ import { NOTEBOOK_CELL_MARKDOWN_EDIT_MODE, NOTEBOOK_CELL_TYPE, NotebookContextKeys, NOTEBOOK_CELL_EXECUTING } from './notebook-context-keys';
23
+ import { ContextKeyService } from '@theia/core/lib/browser/context-key-service';
24
+ import { NotebookExecutionService } from '../service/notebook-execution-service';
25
+ import { NotebookCellOutputModel } from '../view-model/notebook-cell-output-model';
26
+ import { CellEditType } from '../../common';
27
+
28
+ export namespace NotebookCellCommands {
29
+ export const EDIT_COMMAND = Command.toDefaultLocalizedCommand({
30
+ id: 'notebook.cell.edit',
31
+ iconClass: codicon('edit')
32
+ });
33
+ export const STOP_EDIT_COMMAND = Command.toDefaultLocalizedCommand({
34
+ id: 'notebook.cell.stop-edit',
35
+ iconClass: codicon('check')
36
+ });
37
+ export const DELETE_COMMAND = Command.toDefaultLocalizedCommand({
38
+ id: 'notebook.cell.delete',
39
+ iconClass: codicon('trash')
40
+ });
41
+ export const SPLIT_CELL_COMMAND = Command.toDefaultLocalizedCommand({
42
+ id: 'notebook.cell.split-cell',
43
+ iconClass: codicon('split-vertical'),
44
+ });
45
+ export const EXECUTE_SINGLE_CELL_COMMAND = Command.toDefaultLocalizedCommand({
46
+ id: 'notebook.cell.execute-cell',
47
+ iconClass: codicon('play'),
48
+ });
49
+ export const STOP_CELL_EXECUTION_COMMAND = Command.toDefaultLocalizedCommand({
50
+ id: 'notebook.cell.stop-cell-execution',
51
+ iconClass: codicon('stop'),
52
+ });
53
+
54
+ export const CLEAR_OUTPUTS_COMMAND = Command.toDefaultLocalizedCommand({
55
+ id: 'notebook.cell.clear-outputs',
56
+ label: 'Clear Cell Outputs',
57
+ });
58
+ export const CHANGE_OUTPUT_PRESENTATION_COMMAND = Command.toDefaultLocalizedCommand({
59
+ id: 'notebook.cell.change-presentation',
60
+ label: 'Change Presentation',
61
+ });
62
+ }
63
+
64
+ @injectable()
65
+ export class NotebookCellActionContribution implements MenuContribution, CommandContribution {
66
+
67
+ @inject(ContextKeyService)
68
+ protected contextKeyService: ContextKeyService;
69
+
70
+ @inject(NotebookExecutionService)
71
+ protected notebookExecutionService: NotebookExecutionService;
72
+
73
+ @postConstruct()
74
+ protected init(): void {
75
+ NotebookContextKeys.initNotebookContextKeys(this.contextKeyService);
76
+ }
77
+
78
+ registerMenus(menus: MenuModelRegistry): void {
79
+ menus.registerMenuAction(NotebookCellActionContribution.ACTION_MENU, {
80
+ commandId: NotebookCellCommands.EDIT_COMMAND.id,
81
+ icon: NotebookCellCommands.EDIT_COMMAND.iconClass,
82
+ when: `${NOTEBOOK_CELL_TYPE} == 'markdown' && !${NOTEBOOK_CELL_MARKDOWN_EDIT_MODE}`,
83
+ label: nls.localizeByDefault('Edit Cell'),
84
+ order: '10'
85
+ });
86
+ menus.registerMenuAction(NotebookCellActionContribution.ACTION_MENU, {
87
+ commandId: NotebookCellCommands.STOP_EDIT_COMMAND.id,
88
+ icon: NotebookCellCommands.STOP_EDIT_COMMAND.iconClass,
89
+ when: `${NOTEBOOK_CELL_TYPE} == 'markdown' && ${NOTEBOOK_CELL_MARKDOWN_EDIT_MODE}`,
90
+ label: nls.localizeByDefault('Stop Editing Cell'),
91
+ order: '10'
92
+ });
93
+ menus.registerMenuAction(NotebookCellActionContribution.ACTION_MENU, {
94
+ commandId: NotebookCellCommands.EXECUTE_SINGLE_CELL_COMMAND.id,
95
+ icon: NotebookCellCommands.EXECUTE_SINGLE_CELL_COMMAND.iconClass,
96
+ when: `${NOTEBOOK_CELL_TYPE} == 'code'`,
97
+ label: nls.localizeByDefault('Execute Cell'),
98
+ order: '10'
99
+ });
100
+
101
+ menus.registerMenuAction(NotebookCellActionContribution.ACTION_MENU, {
102
+ commandId: NotebookCellCommands.SPLIT_CELL_COMMAND.id,
103
+ icon: NotebookCellCommands.SPLIT_CELL_COMMAND.iconClass,
104
+ label: nls.localizeByDefault('Split Cell'),
105
+ order: '20'
106
+ });
107
+ menus.registerMenuAction(NotebookCellActionContribution.ACTION_MENU, {
108
+ commandId: NotebookCellCommands.DELETE_COMMAND.id,
109
+ icon: NotebookCellCommands.DELETE_COMMAND.iconClass,
110
+ label: nls.localizeByDefault('Delete Cell'),
111
+ order: '999'
112
+ });
113
+
114
+ menus.registerSubmenu(
115
+ NotebookCellActionContribution.ADDITIONAL_ACTION_MENU,
116
+ nls.localizeByDefault('More'),
117
+ {
118
+ icon: codicon('ellipsis'),
119
+ role: CompoundMenuNodeRole.Submenu,
120
+ order: '30'
121
+ }
122
+ );
123
+
124
+ menus.registerIndependentSubmenu(NotebookCellActionContribution.CONTRIBUTED_CELL_ACTION_MENU, '', { role: CompoundMenuNodeRole.Flat });
125
+ // since contributions are adding to an independent submenu we have to manually add it to the more submenu
126
+ menus.getMenu(NotebookCellActionContribution.ADDITIONAL_ACTION_MENU).addNode(menus.getMenuNode(NotebookCellActionContribution.CONTRIBUTED_CELL_ACTION_MENU));
127
+
128
+ // code cell sidebar menu
129
+ menus.registerMenuAction(NotebookCellActionContribution.CODE_CELL_SIDEBAR_MENU, {
130
+ commandId: NotebookCellCommands.EXECUTE_SINGLE_CELL_COMMAND.id,
131
+ icon: NotebookCellCommands.EXECUTE_SINGLE_CELL_COMMAND.iconClass,
132
+ label: nls.localizeByDefault('Execute Cell'),
133
+ when: `!${NOTEBOOK_CELL_EXECUTING}`
134
+ });
135
+ menus.registerMenuAction(NotebookCellActionContribution.CODE_CELL_SIDEBAR_MENU, {
136
+ commandId: NotebookCellCommands.STOP_CELL_EXECUTION_COMMAND.id,
137
+ icon: NotebookCellCommands.STOP_CELL_EXECUTION_COMMAND.iconClass,
138
+ label: nls.localizeByDefault('Stop Cell Execution'),
139
+ when: NOTEBOOK_CELL_EXECUTING
140
+ });
141
+
142
+ // Notebook Cell extra execution options
143
+ menus.registerIndependentSubmenu(NotebookCellActionContribution.CONTRIBUTED_CELL_EXECUTION_MENU,
144
+ nls.localizeByDefault('More...'),
145
+ { role: CompoundMenuNodeRole.Flat, icon: codicon('chevron-down') });
146
+ menus.getMenu(NotebookCellActionContribution.CODE_CELL_SIDEBAR_MENU).addNode(menus.getMenuNode(NotebookCellActionContribution.CONTRIBUTED_CELL_EXECUTION_MENU));
147
+
148
+ // code cell output sidebar menu
149
+ menus.registerSubmenu(
150
+ NotebookCellActionContribution.ADDITIONAL_OUTPUT_SIDEBAR_MENU,
151
+ nls.localizeByDefault('More'),
152
+ {
153
+ icon: codicon('ellipsis'),
154
+ role: CompoundMenuNodeRole.Submenu
155
+ });
156
+ menus.registerMenuAction(NotebookCellActionContribution.ADDITIONAL_OUTPUT_SIDEBAR_MENU, {
157
+ commandId: NotebookCellCommands.CLEAR_OUTPUTS_COMMAND.id,
158
+ label: nls.localizeByDefault('Clear Cell Outputs'),
159
+ });
160
+ menus.registerMenuAction(NotebookCellActionContribution.ADDITIONAL_OUTPUT_SIDEBAR_MENU, {
161
+ commandId: NotebookCellCommands.CHANGE_OUTPUT_PRESENTATION_COMMAND.id,
162
+ label: nls.localizeByDefault('Change Presentation'),
163
+ });
164
+
165
+ }
166
+
167
+ registerCommands(commands: CommandRegistry): void {
168
+ commands.registerCommand(NotebookCellCommands.EDIT_COMMAND, { execute: (_, cell: NotebookCellModel) => cell.requestEdit() });
169
+ commands.registerCommand(NotebookCellCommands.STOP_EDIT_COMMAND, { execute: (_, cell: NotebookCellModel) => cell.requestStopEdit() });
170
+ commands.registerCommand(NotebookCellCommands.DELETE_COMMAND, {
171
+ execute: (notebookModel: NotebookModel, cell: NotebookCellModel) => notebookModel.applyEdits([{
172
+ editType: CellEditType.Replace,
173
+ index: notebookModel.cells.indexOf(cell),
174
+ count: 1,
175
+ cells: []
176
+ }], true)
177
+ });
178
+ commands.registerCommand(NotebookCellCommands.SPLIT_CELL_COMMAND);
179
+
180
+ commands.registerCommand(NotebookCellCommands.EXECUTE_SINGLE_CELL_COMMAND, {
181
+ execute: (notebookModel: NotebookModel, cell: NotebookCellModel) => this.notebookExecutionService.executeNotebookCells(notebookModel, [cell])
182
+ });
183
+ commands.registerCommand(NotebookCellCommands.STOP_CELL_EXECUTION_COMMAND, {
184
+ execute: (notebookModel: NotebookModel, cell: NotebookCellModel) => this.notebookExecutionService.cancelNotebookCells(notebookModel, [cell])
185
+ });
186
+ commands.registerCommand(NotebookCellCommands.CLEAR_OUTPUTS_COMMAND, {
187
+ execute: (notebookModel: NotebookModel, cell: NotebookCellModel) => cell.spliceNotebookCellOutputs({ start: 0, deleteCount: cell.outputs.length, newOutputs: [] })
188
+ });
189
+ commands.registerCommand(NotebookCellCommands.CHANGE_OUTPUT_PRESENTATION_COMMAND, {
190
+ execute: (_, __, output: NotebookCellOutputModel) => output.requestOutputPresentationUpdate()
191
+ });
192
+ }
193
+ }
194
+
195
+ export namespace NotebookCellActionContribution {
196
+ export const ACTION_MENU = ['notebook-cell-actions-menu'];
197
+ export const ADDITIONAL_ACTION_MENU = [...ACTION_MENU, 'more'];
198
+ export const CONTRIBUTED_CELL_ACTION_MENU = 'notebook/cell/title';
199
+ export const CONTRIBUTED_CELL_EXECUTION_MENU = 'notebook/cell/execute';
200
+ export const CODE_CELL_SIDEBAR_MENU = ['code-cell-sidebar-menu'];
201
+ export const OUTPUT_SIDEBAR_MENU = ['code-cell-output-sidebar-menu'];
202
+ export const ADDITIONAL_OUTPUT_SIDEBAR_MENU = [...OUTPUT_SIDEBAR_MENU, 'more'];
203
+
204
+ }
@@ -0,0 +1,268 @@
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 { ColorContribution } from '@theia/core/lib/browser/color-application-contribution';
18
+ import { ColorRegistry } from '@theia/core/lib/browser/color-registry';
19
+ import { Color } from '@theia/core/lib/common/color';
20
+ import { injectable } from '@theia/core/shared/inversify';
21
+
22
+ @injectable()
23
+ export class NotebookColorContribution implements ColorContribution {
24
+ registerColors(colors: ColorRegistry): void {
25
+ colors.register(
26
+ {
27
+ id: 'notebook.cellBorderColor',
28
+ defaults: {
29
+ dark: Color.transparent('list.inactiveSelectionBackground', 1),
30
+ light: Color.transparent('list.inactiveSelectionBackground', 1),
31
+ hcDark: 'panel.border',
32
+ hcLight: 'panel.border'
33
+ },
34
+ description: 'The border color for notebook cells.'
35
+ },
36
+ {
37
+ id: 'notebook.focusedEditorBorder',
38
+ defaults: {
39
+ dark: 'focusBorder',
40
+ light: 'focusBorder',
41
+ hcDark: 'focusBorder',
42
+ hcLight: 'focusBorder'
43
+ },
44
+ description: 'The color of the notebook cell editor border.'
45
+ },
46
+ {
47
+ id: 'notebookStatusSuccessIcon.foreground',
48
+ defaults: {
49
+ dark: 'debugIcon.startForeground',
50
+ light: 'debugIcon.startForeground',
51
+ hcDark: 'debugIcon.startForeground',
52
+ hcLight: 'debugIcon.startForeground'
53
+ },
54
+ description: 'The error icon color of notebook cells in the cell status bar.'
55
+ },
56
+ {
57
+ id: 'notebookEditorOverviewRuler.runningCellForeground',
58
+ defaults: {
59
+ dark: 'debugIcon.startForeground',
60
+ light: 'debugIcon.startForeground',
61
+ hcDark: 'debugIcon.startForeground',
62
+ hcLight: 'debugIcon.startForeground'
63
+ },
64
+ description: 'The color of the running cell decoration in the notebook editor overview ruler.'
65
+ },
66
+ {
67
+ id: 'notebookStatusErrorIcon.foreground',
68
+ defaults: {
69
+ dark: 'errorForeground',
70
+ light: 'errorForeground',
71
+ hcDark: 'errorForeground',
72
+ hcLight: 'errorForeground'
73
+ },
74
+ description: 'The error icon color of notebook cells in the cell status bar.'
75
+ },
76
+ {
77
+ id: 'notebookStatusRunningIcon.foreground',
78
+ defaults: {
79
+ dark: 'foreground',
80
+ light: 'foreground',
81
+ hcDark: 'foreground',
82
+ hcLight: 'foreground'
83
+ },
84
+ description: 'The running icon color of notebook cells in the cell status bar.'
85
+ },
86
+ {
87
+ id: 'notebook.outputContainerBorderColor',
88
+ defaults: {
89
+ dark: undefined,
90
+ light: undefined,
91
+ hcDark: undefined,
92
+ hcLight: undefined
93
+ },
94
+ description: 'The border color of the notebook output container.'
95
+ },
96
+ {
97
+ id: 'notebook.outputContainerBackgroundColor',
98
+ defaults: {
99
+ dark: undefined,
100
+ light: undefined,
101
+ hcDark: undefined,
102
+ hcLight: undefined
103
+ },
104
+ description: 'The color of the notebook output container background.'
105
+ },
106
+ {
107
+ id: 'notebook.cellToolbarSeparator',
108
+ defaults: {
109
+ dark: Color.rgba(128, 128, 128, 0.35),
110
+ light: Color.rgba(128, 128, 128, 0.35),
111
+ hcDark: 'contrastBorder',
112
+ hcLight: 'contrastBorder'
113
+ },
114
+ description: 'The color of the separator in the cell bottom toolbar'
115
+ },
116
+ {
117
+ id: 'notebook.focusedCellBackground',
118
+ defaults: {
119
+ dark: undefined,
120
+ light: undefined,
121
+ hcDark: undefined,
122
+ hcLight: undefined
123
+ },
124
+ description: 'The background color of a cell when the cell is focused.'
125
+ },
126
+ {
127
+ id: 'notebook.selectedCellBackground',
128
+ defaults: {
129
+ dark: 'list.inactiveSelectionBackground',
130
+ light: 'list.inactiveSelectionBackground',
131
+ hcDark: undefined,
132
+ hcLight: undefined
133
+ },
134
+ description: 'The background color of a cell when the cell is selected.'
135
+ },
136
+ {
137
+ id: 'notebook.cellHoverBackground',
138
+ defaults: {
139
+ dark: Color.transparent('notebook.focusedCellBackground', 0.5),
140
+ light: Color.transparent('notebook.focusedCellBackground', 0.7),
141
+ hcDark: undefined,
142
+ hcLight: undefined
143
+ },
144
+ description: 'The background color of a cell when the cell is hovered.'
145
+ },
146
+ {
147
+ id: 'notebook.selectedCellBorder',
148
+ defaults: {
149
+ dark: 'notebook.cellBorderColor',
150
+ light: 'notebook.cellBorderColor',
151
+ hcDark: 'contrastBorder',
152
+ hcLight: 'contrastBorder'
153
+ },
154
+ description: "The color of the cell's top and bottom border when the cell is selected but not focused."
155
+ },
156
+ {
157
+ id: 'notebook.inactiveSelectedCellBorder',
158
+ defaults: {
159
+ dark: undefined,
160
+ light: undefined,
161
+ hcDark: 'focusBorder',
162
+ hcLight: 'focusBorder'
163
+ },
164
+ description: "The color of the cell's borders when multiple cells are selected."
165
+ },
166
+ {
167
+ id: 'notebook.focusedCellBorder',
168
+ defaults: {
169
+ dark: 'focusBorder',
170
+ light: 'focusBorder',
171
+ hcDark: 'focusBorder',
172
+ hcLight: 'focusBorder'
173
+ },
174
+ description: "The color of the cell's focus indicator borders when the cell is focused."
175
+ },
176
+ {
177
+ id: 'notebook.inactiveFocusedCellBorder',
178
+ defaults: {
179
+ dark: 'notebook.cellBorderColor',
180
+ light: 'notebook.cellBorderColor',
181
+ hcDark: 'notebook.cellBorderColor',
182
+ hcLight: 'notebook.cellBorderColor'
183
+ },
184
+ description: "The color of the cell's top and bottom border when a cell is focused while the primary focus is outside of the editor."
185
+ },
186
+ {
187
+ id: 'notebook.cellStatusBarItemHoverBackground',
188
+ defaults: {
189
+ dark: Color.rgba(0, 0, 0, 0.08),
190
+ light: Color.rgba(255, 255, 255, 0.15),
191
+ hcDark: Color.rgba(0, 0, 0, 0.08),
192
+ hcLight: Color.rgba(255, 255, 255, 0.15)
193
+ },
194
+ description: 'The background color of notebook cell status bar items.'
195
+ },
196
+ {
197
+ id: 'notebook.cellInsertionIndicator',
198
+ defaults: {
199
+ dark: 'focusBorder',
200
+ light: 'focusBorder',
201
+ hcDark: 'focusBorder',
202
+ hcLight: undefined
203
+ },
204
+ description: 'Notebook background color.'
205
+ },
206
+ {
207
+ id: 'notebookScrollbarSlider.background',
208
+ defaults: {
209
+ dark: 'scrollbarSlider.background',
210
+ light: 'scrollbarSlider.background',
211
+ hcDark: 'scrollbarSlider.background',
212
+ hcLight: 'scrollbarSlider.background'
213
+ },
214
+ description: 'Notebook scrollbar slider background color.'
215
+ },
216
+ {
217
+ id: 'notebookScrollbarSlider.hoverBackground',
218
+ defaults: {
219
+ dark: 'scrollbarSlider.hoverBackground',
220
+ light: 'scrollbarSlider.hoverBackground',
221
+ hcDark: 'scrollbarSlider.hoverBackground',
222
+ hcLight: 'scrollbarSlider.hoverBackground'
223
+ },
224
+ description: 'Notebook scrollbar slider background color when hovering.'
225
+ },
226
+ {
227
+ id: 'notebookScrollbarSlider.activeBackground',
228
+ defaults: {
229
+ dark: 'scrollbarSlider.activeBackground',
230
+ light: 'scrollbarSlider.activeBackground',
231
+ hcDark: 'scrollbarSlider.activeBackground',
232
+ hcLight: 'scrollbarSlider.activeBackground'
233
+ },
234
+ description: 'Notebook scrollbar slider background color when clicked on.'
235
+ },
236
+ {
237
+ id: 'notebook.symbolHighlightBackground',
238
+ defaults: {
239
+ dark: Color.rgba(255, 255, 255, 0.04),
240
+ light: Color.rgba(253, 255, 0, 0.2),
241
+ hcDark: undefined,
242
+ hcLight: undefined
243
+ },
244
+ description: 'Background color of highlighted cell'
245
+ },
246
+ {
247
+ id: 'notebook.cellEditorBackground',
248
+ defaults: {
249
+ dark: 'sideBar.background',
250
+ light: 'sideBar.background',
251
+ hcDark: undefined,
252
+ hcLight: undefined
253
+ },
254
+ description: 'Cell editor background color.'
255
+ },
256
+ {
257
+ id: 'notebook.editorBackground',
258
+ defaults: {
259
+ dark: 'editorPane.background',
260
+ light: 'editorPane.background',
261
+ hcDark: undefined,
262
+ hcLight: undefined
263
+ },
264
+ description: 'Notebook background color.'
265
+ }
266
+ );
267
+ }
268
+ }