@opensumi/ide-notebook 3.4.5-next-1730119322.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 (197) hide show
  1. package/README.md +33 -0
  2. package/lib/browser/index.d.ts +12 -0
  3. package/lib/browser/index.d.ts.map +1 -0
  4. package/lib/browser/index.js +49 -0
  5. package/lib/browser/index.js.map +1 -0
  6. package/lib/browser/kernel-panel/collapse/collapse-content.d.ts +10 -0
  7. package/lib/browser/kernel-panel/collapse/collapse-content.d.ts.map +1 -0
  8. package/lib/browser/kernel-panel/collapse/collapse-content.js +27 -0
  9. package/lib/browser/kernel-panel/collapse/collapse-content.js.map +1 -0
  10. package/lib/browser/kernel-panel/collapse/icon.d.ts +7 -0
  11. package/lib/browser/kernel-panel/collapse/icon.d.ts.map +1 -0
  12. package/lib/browser/kernel-panel/collapse/icon.js +64 -0
  13. package/lib/browser/kernel-panel/collapse/icon.js.map +1 -0
  14. package/lib/browser/kernel-panel/collapse/index.d.ts +5 -0
  15. package/lib/browser/kernel-panel/collapse/index.d.ts.map +1 -0
  16. package/lib/browser/kernel-panel/collapse/index.js +66 -0
  17. package/lib/browser/kernel-panel/collapse/index.js.map +1 -0
  18. package/lib/browser/kernel-panel/collapse/index.less +95 -0
  19. package/lib/browser/kernel-panel/collapse/kernel-collapse-content-item.d.ts +9 -0
  20. package/lib/browser/kernel-panel/collapse/kernel-collapse-content-item.d.ts.map +1 -0
  21. package/lib/browser/kernel-panel/collapse/kernel-collapse-content-item.js +41 -0
  22. package/lib/browser/kernel-panel/collapse/kernel-collapse-content-item.js.map +1 -0
  23. package/lib/browser/kernel-panel/collapse/kernel-collapse-content.d.ts +10 -0
  24. package/lib/browser/kernel-panel/collapse/kernel-collapse-content.d.ts.map +1 -0
  25. package/lib/browser/kernel-panel/collapse/kernel-collapse-content.js +4 -0
  26. package/lib/browser/kernel-panel/collapse/kernel-collapse-content.js.map +1 -0
  27. package/lib/browser/kernel-panel/collapse/page-collapse-content.d.ts +10 -0
  28. package/lib/browser/kernel-panel/collapse/page-collapse-content.d.ts.map +1 -0
  29. package/lib/browser/kernel-panel/collapse/page-collapse-content.js +32 -0
  30. package/lib/browser/kernel-panel/collapse/page-collapse-content.js.map +1 -0
  31. package/lib/browser/kernel-panel/index.d.ts +5 -0
  32. package/lib/browser/kernel-panel/index.d.ts.map +1 -0
  33. package/lib/browser/kernel-panel/index.js +5 -0
  34. package/lib/browser/kernel-panel/index.js.map +1 -0
  35. package/lib/browser/kernel-panel/index.less +20 -0
  36. package/lib/browser/kernel-panel/kernel-panel-view.d.ts +4 -0
  37. package/lib/browser/kernel-panel/kernel-panel-view.d.ts.map +1 -0
  38. package/lib/browser/kernel-panel/kernel-panel-view.js +72 -0
  39. package/lib/browser/kernel-panel/kernel-panel-view.js.map +1 -0
  40. package/lib/browser/kernel-panel/kernel.panel.color.tokens.d.ts +2 -0
  41. package/lib/browser/kernel-panel/kernel.panel.color.tokens.d.ts.map +1 -0
  42. package/lib/browser/kernel-panel/kernel.panel.color.tokens.js +10 -0
  43. package/lib/browser/kernel-panel/kernel.panel.color.tokens.js.map +1 -0
  44. package/lib/browser/kernel-panel/kernel.panel.contribution.d.ts +7 -0
  45. package/lib/browser/kernel-panel/kernel.panel.contribution.d.ts.map +1 -0
  46. package/lib/browser/kernel-panel/kernel.panel.contribution.js +32 -0
  47. package/lib/browser/kernel-panel/kernel.panel.contribution.js.map +1 -0
  48. package/lib/browser/kernel-panel/kernel.panel.protocol.d.ts +25 -0
  49. package/lib/browser/kernel-panel/kernel.panel.protocol.d.ts.map +1 -0
  50. package/lib/browser/kernel-panel/kernel.panel.protocol.js +7 -0
  51. package/lib/browser/kernel-panel/kernel.panel.protocol.js.map +1 -0
  52. package/lib/browser/libro/editor/editor-contribution.d.ts +13 -0
  53. package/lib/browser/libro/editor/editor-contribution.d.ts.map +1 -0
  54. package/lib/browser/libro/editor/editor-contribution.js +30 -0
  55. package/lib/browser/libro/editor/editor-contribution.js.map +1 -0
  56. package/lib/browser/libro/editor/index.less +48 -0
  57. package/lib/browser/libro/editor/keybind-handler.d.ts +14 -0
  58. package/lib/browser/libro/editor/keybind-handler.d.ts.map +1 -0
  59. package/lib/browser/libro/editor/keybind-handler.js +132 -0
  60. package/lib/browser/libro/editor/keybind-handler.js.map +1 -0
  61. package/lib/browser/libro/editor/module.d.ts +3 -0
  62. package/lib/browser/libro/editor/module.d.ts.map +1 -0
  63. package/lib/browser/libro/editor/module.js +22 -0
  64. package/lib/browser/libro/editor/module.js.map +1 -0
  65. package/lib/browser/libro/editor/opensumi-editor.d.ts +251 -0
  66. package/lib/browser/libro/editor/opensumi-editor.d.ts.map +1 -0
  67. package/lib/browser/libro/editor/opensumi-editor.js +567 -0
  68. package/lib/browser/libro/editor/opensumi-editor.js.map +1 -0
  69. package/lib/browser/libro/index.d.ts +4 -0
  70. package/lib/browser/libro/index.d.ts.map +1 -0
  71. package/lib/browser/libro/index.js +4 -0
  72. package/lib/browser/libro/index.js.map +1 -0
  73. package/lib/browser/libro/libro-opensumi-content-contribution.d.ts +9 -0
  74. package/lib/browser/libro/libro-opensumi-content-contribution.d.ts.map +1 -0
  75. package/lib/browser/libro/libro-opensumi-content-contribution.js +71 -0
  76. package/lib/browser/libro/libro-opensumi-content-contribution.js.map +1 -0
  77. package/lib/browser/libro/libro-opensumi-save-content-contribution.d.ts +10 -0
  78. package/lib/browser/libro/libro-opensumi-save-content-contribution.d.ts.map +1 -0
  79. package/lib/browser/libro/libro-opensumi-save-content-contribution.js +51 -0
  80. package/lib/browser/libro/libro-opensumi-save-content-contribution.js.map +1 -0
  81. package/lib/browser/libro/mana-module.d.ts +3 -0
  82. package/lib/browser/libro/mana-module.d.ts.map +1 -0
  83. package/lib/browser/libro/mana-module.js +8 -0
  84. package/lib/browser/libro/mana-module.js.map +1 -0
  85. package/lib/browser/libro-keybind-contribution.d.ts +19 -0
  86. package/lib/browser/libro-keybind-contribution.d.ts.map +1 -0
  87. package/lib/browser/libro-keybind-contribution.js +142 -0
  88. package/lib/browser/libro-keybind-contribution.js.map +1 -0
  89. package/lib/browser/libro-opener.d.ts +12 -0
  90. package/lib/browser/libro-opener.d.ts.map +1 -0
  91. package/lib/browser/libro-opener.js +83 -0
  92. package/lib/browser/libro-opener.js.map +1 -0
  93. package/lib/browser/libro.color.tokens.d.ts +2 -0
  94. package/lib/browser/libro.color.tokens.d.ts.map +1 -0
  95. package/lib/browser/libro.color.tokens.js +9 -0
  96. package/lib/browser/libro.color.tokens.js.map +1 -0
  97. package/lib/browser/libro.command.d.ts +6 -0
  98. package/lib/browser/libro.command.d.ts.map +1 -0
  99. package/lib/browser/libro.command.js +66 -0
  100. package/lib/browser/libro.command.js.map +1 -0
  101. package/lib/browser/libro.contribution.d.ts +29 -0
  102. package/lib/browser/libro.contribution.d.ts.map +1 -0
  103. package/lib/browser/libro.contribution.js +140 -0
  104. package/lib/browser/libro.contribution.js.map +1 -0
  105. package/lib/browser/libro.module.less +40 -0
  106. package/lib/browser/libro.protocol.d.ts +3 -0
  107. package/lib/browser/libro.protocol.d.ts.map +1 -0
  108. package/lib/browser/libro.protocol.js +3 -0
  109. package/lib/browser/libro.protocol.js.map +1 -0
  110. package/lib/browser/libro.service.d.ts +24 -0
  111. package/lib/browser/libro.service.d.ts.map +1 -0
  112. package/lib/browser/libro.service.js +68 -0
  113. package/lib/browser/libro.service.js.map +1 -0
  114. package/lib/browser/libro.view.d.ts +3 -0
  115. package/lib/browser/libro.view.d.ts.map +1 -0
  116. package/lib/browser/libro.view.js +54 -0
  117. package/lib/browser/libro.view.js.map +1 -0
  118. package/lib/browser/libro.view.tracker.d.ts +6 -0
  119. package/lib/browser/libro.view.tracker.d.ts.map +1 -0
  120. package/lib/browser/libro.view.tracker.js +28 -0
  121. package/lib/browser/libro.view.tracker.js.map +1 -0
  122. package/lib/browser/mana/index.d.ts +8 -0
  123. package/lib/browser/mana/index.d.ts.map +1 -0
  124. package/lib/browser/mana/index.js +15 -0
  125. package/lib/browser/mana/index.js.map +1 -0
  126. package/lib/browser/notebook-document-content-provider.d.ts +22 -0
  127. package/lib/browser/notebook-document-content-provider.d.ts.map +1 -0
  128. package/lib/browser/notebook-document-content-provider.js +80 -0
  129. package/lib/browser/notebook-document-content-provider.js.map +1 -0
  130. package/lib/browser/notebook.service.d.ts +27 -0
  131. package/lib/browser/notebook.service.d.ts.map +1 -0
  132. package/lib/browser/notebook.service.js +186 -0
  133. package/lib/browser/notebook.service.js.map +1 -0
  134. package/lib/browser/toc/index.d.ts +4 -0
  135. package/lib/browser/toc/index.d.ts.map +1 -0
  136. package/lib/browser/toc/index.js +4 -0
  137. package/lib/browser/toc/index.js.map +1 -0
  138. package/lib/browser/toc/toc.contribution.d.ts +6 -0
  139. package/lib/browser/toc/toc.contribution.d.ts.map +1 -0
  140. package/lib/browser/toc/toc.contribution.js +25 -0
  141. package/lib/browser/toc/toc.contribution.js.map +1 -0
  142. package/lib/browser/toc/toc.module.less +23 -0
  143. package/lib/browser/toc/toc.panel.color.tokens.d.ts +2 -0
  144. package/lib/browser/toc/toc.panel.color.tokens.d.ts.map +1 -0
  145. package/lib/browser/toc/toc.panel.color.tokens.js +6 -0
  146. package/lib/browser/toc/toc.panel.color.tokens.js.map +1 -0
  147. package/lib/browser/toc/toc.panel.d.ts +6 -0
  148. package/lib/browser/toc/toc.panel.d.ts.map +1 -0
  149. package/lib/browser/toc/toc.panel.js +61 -0
  150. package/lib/browser/toc/toc.panel.js.map +1 -0
  151. package/lib/index.d.ts +2 -0
  152. package/lib/index.d.ts.map +1 -0
  153. package/lib/index.js +2 -0
  154. package/lib/index.js.map +1 -0
  155. package/package.json +42 -0
  156. package/src/browser/index.ts +44 -0
  157. package/src/browser/kernel-panel/collapse/collapse-content.tsx +46 -0
  158. package/src/browser/kernel-panel/collapse/icon.tsx +171 -0
  159. package/src/browser/kernel-panel/collapse/index.less +95 -0
  160. package/src/browser/kernel-panel/collapse/index.tsx +111 -0
  161. package/src/browser/kernel-panel/collapse/kernel-collapse-content-item.tsx +77 -0
  162. package/src/browser/kernel-panel/collapse/kernel-collapse-content.tsx +17 -0
  163. package/src/browser/kernel-panel/collapse/page-collapse-content.tsx +53 -0
  164. package/src/browser/kernel-panel/index.less +20 -0
  165. package/src/browser/kernel-panel/index.ts +4 -0
  166. package/src/browser/kernel-panel/kernel-panel-view.tsx +104 -0
  167. package/src/browser/kernel-panel/kernel.panel.color.tokens.ts +39 -0
  168. package/src/browser/kernel-panel/kernel.panel.contribution.ts +32 -0
  169. package/src/browser/kernel-panel/kernel.panel.protocol.ts +24 -0
  170. package/src/browser/libro/editor/editor-contribution.ts +41 -0
  171. package/src/browser/libro/editor/index.less +48 -0
  172. package/src/browser/libro/editor/keybind-handler.ts +133 -0
  173. package/src/browser/libro/editor/module.ts +30 -0
  174. package/src/browser/libro/editor/opensumi-editor.ts +826 -0
  175. package/src/browser/libro/index.ts +3 -0
  176. package/src/browser/libro/libro-opensumi-content-contribution.ts +63 -0
  177. package/src/browser/libro/libro-opensumi-save-content-contribution.ts +43 -0
  178. package/src/browser/libro/mana-module.ts +9 -0
  179. package/src/browser/libro-keybind-contribution.ts +147 -0
  180. package/src/browser/libro-opener.ts +96 -0
  181. package/src/browser/libro.color.tokens.ts +32 -0
  182. package/src/browser/libro.command.ts +63 -0
  183. package/src/browser/libro.contribution.tsx +189 -0
  184. package/src/browser/libro.module.less +40 -0
  185. package/src/browser/libro.protocol.ts +2 -0
  186. package/src/browser/libro.service.ts +85 -0
  187. package/src/browser/libro.view.tracker.ts +18 -0
  188. package/src/browser/libro.view.tsx +62 -0
  189. package/src/browser/mana/index.ts +20 -0
  190. package/src/browser/notebook-document-content-provider.ts +100 -0
  191. package/src/browser/notebook.service.ts +195 -0
  192. package/src/browser/toc/index.ts +3 -0
  193. package/src/browser/toc/toc.contribution.ts +24 -0
  194. package/src/browser/toc/toc.module.less +23 -0
  195. package/src/browser/toc/toc.panel.color.tokens.ts +11 -0
  196. package/src/browser/toc/toc.panel.tsx +66 -0
  197. package/src/index.ts +1 -0
@@ -0,0 +1,3 @@
1
+ export * from './libro-opensumi-content-contribution';
2
+ export * from './libro-opensumi-save-content-contribution';
3
+ export * from './mana-module';
@@ -0,0 +1,63 @@
1
+ import { ContentContribution } from '@difizen/libro-core';
2
+ import { IContentsModel, INotebookContent, LibroJupyterModel, NotebookOption } from '@difizen/libro-jupyter/noeditor';
3
+ import { getOrigin, inject, singleton } from '@difizen/mana-app';
4
+
5
+ import { Injector } from '@opensumi/di';
6
+ import { URI } from '@opensumi/ide-core-browser';
7
+ import { IFileServiceClient } from '@opensumi/ide-file-service';
8
+ import { IMessageService } from '@opensumi/ide-overlay';
9
+
10
+ import { ContentLoaderType, OpensumiInjector } from '../mana';
11
+
12
+ @singleton({ contrib: ContentContribution })
13
+ export class LibroOpensumiContentContribution implements ContentContribution {
14
+ @inject(OpensumiInjector) injector: Injector;
15
+
16
+ canHandle = (options) => options.loadType === ContentLoaderType ? 100 : 1;
17
+ async loadContent(options: NotebookOption, model: LibroJupyterModel) {
18
+ const fileServiceClient: IFileServiceClient = this.injector.get(IFileServiceClient);
19
+ const messageService = this.injector.get(IMessageService);
20
+ let notebookContent: INotebookContent;
21
+ try {
22
+ const { content } = await getOrigin(fileServiceClient).readFile(options.resource.toString());
23
+ const stat = await getOrigin(fileServiceClient).getFileStat(options.resource.toString());
24
+ if (content.byteLength === 0) {
25
+ notebookContent = {
26
+ cells: [],
27
+ metadata: {},
28
+ nbformat: 4,
29
+ nbformat_minor: 5,
30
+ };
31
+ } else {
32
+ notebookContent = JSON.parse(content.toString());
33
+ }
34
+ const uri = new URI(options.resource.toString());
35
+ const currentFileContents: IContentsModel = {
36
+ name: uri.path.name,
37
+ path: uri.path.toString(),
38
+ last_modified: stat?.lastModification.toString() || new Date().toJSON(),
39
+ created: stat?.createTime?.toString() || new Date().toJSON(),
40
+ content: notebookContent,
41
+ size: stat?.size,
42
+ writable: true,
43
+ type: 'notebook',
44
+ };
45
+ model.currentFileContents = currentFileContents;
46
+ model.filePath = currentFileContents.path;
47
+ model.id = currentFileContents.path; //
48
+ model.lastModified = model.currentFileContents.last_modified;
49
+ if (model.executable) {
50
+ model.startKernelConnection();
51
+ }
52
+ } catch (e) {
53
+ messageService.error(`Notebook file ${options.resource.toString()} read error: ${e}`);
54
+ notebookContent = {
55
+ cells: [],
56
+ metadata: {},
57
+ nbformat: 4,
58
+ nbformat_minor: 5,
59
+ };
60
+ }
61
+ return notebookContent;
62
+ }
63
+ }
@@ -0,0 +1,43 @@
1
+ import {
2
+ ContentSaveContribution,
3
+ LibroJupyterModel,
4
+ NotebookOption,
5
+ SaveFileErrorModal,
6
+ } from '@difizen/libro-jupyter/noeditor';
7
+ import { ModalService, URI, getOrigin, inject, singleton } from '@difizen/mana-app';
8
+
9
+ import { Injector } from '@opensumi/di';
10
+ import { IFileServiceClient } from '@opensumi/ide-file-service';
11
+
12
+ import { ContentLoaderType, OpensumiInjector } from '../mana';
13
+
14
+ @singleton({ contrib: ContentSaveContribution })
15
+ export class LibroOpensumiContentSaveContribution implements ContentSaveContribution {
16
+ @inject(ModalService) protected readonly modalService: ModalService;
17
+ @inject(OpensumiInjector) injector: Injector;
18
+
19
+ canHandle = (options: NotebookOption) => options.loadType === ContentLoaderType ? 100 : 1;
20
+ saveContent = async (options: NotebookOption, model: LibroJupyterModel) => {
21
+ const uri = new URI(options.resource.toString());
22
+ const fileServiceClient: IFileServiceClient = getOrigin(this.injector.get(IFileServiceClient));
23
+ const stat = await getOrigin(fileServiceClient).getFileStat(options.resource.toString());
24
+ try {
25
+ const notebookContent = model.toJSON();
26
+ if (!stat) {throw new Error('Get file stat error!');}
27
+ getOrigin(fileServiceClient).setContent(stat, JSON.stringify(notebookContent));
28
+ } catch (e: any) {
29
+ model.fileService.fileSaveErrorEmitter.fire({
30
+ cause: e.errorCause,
31
+ msg: e.message,
32
+ name: uri.path?.name || model.currentFileContents.name,
33
+ path: uri?.path.toString() || model.currentFileContents.path,
34
+ created: stat?.createTime?.toString() || model.currentFileContents.created,
35
+ last_modified: stat?.lastModification.toString() || model.currentFileContents.last_modified,
36
+ size: stat?.size || model.currentFileContents.size,
37
+ type: 'notebook',
38
+ });
39
+ this.modalService.openModal(SaveFileErrorModal);
40
+ throw new Error('File Save Error', e);
41
+ }
42
+ };
43
+ }
@@ -0,0 +1,9 @@
1
+ import { ManaModule } from '@difizen/mana-app';
2
+
3
+ import { LibroOpensumiEditorModule } from './editor/module';
4
+ import { LibroOpensumiContentContribution } from './libro-opensumi-content-contribution';
5
+ import { LibroOpensumiContentSaveContribution } from './libro-opensumi-save-content-contribution';
6
+
7
+ export const LibroOpensumiModule = ManaModule.create()
8
+ .register(LibroOpensumiContentContribution, LibroOpensumiContentSaveContribution)
9
+ .dependOn(LibroOpensumiEditorModule);
@@ -0,0 +1,147 @@
1
+ import { LibroSearchToggleCommand, LibroService, LibroView, NotebookCommands } from '@difizen/libro-jupyter/noeditor';
2
+ import { Container, CommandRegistry as LibroCommandRegistry } from '@difizen/mana-app';
3
+
4
+ import { Autowired } from '@opensumi/di';
5
+ import {
6
+ ClientAppContribution,
7
+ CommandRegistry,
8
+ Domain,
9
+ IContextKeyService,
10
+ KeybindingRegistry,
11
+ KeybindingScope,
12
+ } from '@opensumi/ide-core-browser';
13
+ import { WorkbenchEditorService } from '@opensumi/ide-editor';
14
+
15
+ import { LIBRO_COMPONENTS_SCHEME_ID } from './libro.protocol';
16
+ import { ManaContainer } from './mana';
17
+
18
+ @Domain(ClientAppContribution)
19
+ export class LibroKeybindContribition implements ClientAppContribution {
20
+ @Autowired(IContextKeyService) contextKeyService: IContextKeyService;
21
+ @Autowired(KeybindingRegistry) keybindingRegistry: KeybindingRegistry;
22
+ @Autowired(WorkbenchEditorService)
23
+ workbenchEditorService: WorkbenchEditorService;
24
+ @Autowired(CommandRegistry)
25
+ protected readonly commandRegistry: CommandRegistry;
26
+ @Autowired(ManaContainer)
27
+ private readonly manaContainer: Container;
28
+
29
+ onStart() {
30
+ this.registerContextKey();
31
+ this.registerCommand();
32
+ this.registerKeybind();
33
+ }
34
+
35
+ registerContextKey() {
36
+ const notebookFocusContext = this.contextKeyService.createKey<boolean>(
37
+ 'libroNotebookFocused',
38
+ this.hasActiveNotebook(),
39
+ );
40
+
41
+ this.workbenchEditorService.onActiveResourceChange((e) => {
42
+ if (e?.uri?.path.ext === `.${LIBRO_COMPONENTS_SCHEME_ID}`) {
43
+ notebookFocusContext.set(true);
44
+ } else {
45
+ notebookFocusContext.set(false);
46
+ }
47
+ });
48
+ }
49
+
50
+ get libroService() {
51
+ return this.manaContainer.get(LibroService);
52
+ }
53
+
54
+ get libroCommandRegistry() {
55
+ return this.manaContainer.get(LibroCommandRegistry);
56
+ }
57
+
58
+ hasActiveNotebook() {
59
+ return this.libroService.active instanceof LibroView;
60
+ }
61
+
62
+ registerCommand() {
63
+ this.commandRegistry.registerCommand(NotebookCommands['EnterCommandMode'], {
64
+ execute: () => {
65
+ this.libroCommandRegistry.executeCommand(NotebookCommands['EnterCommandMode'].id);
66
+ },
67
+ });
68
+ this.commandRegistry.registerCommand(NotebookCommands['RunCell'], {
69
+ execute: () => {
70
+ this.libroCommandRegistry.executeCommand(NotebookCommands['RunCell'].id);
71
+ },
72
+ });
73
+ this.commandRegistry.registerCommand(NotebookCommands['RunCellAndSelectNext'], {
74
+ execute: () => {
75
+ this.libroCommandRegistry.executeCommand(NotebookCommands['RunCellAndSelectNext'].id);
76
+ },
77
+ });
78
+ this.commandRegistry.registerCommand(NotebookCommands['RunCellAndInsertBelow'], {
79
+ execute: () => {
80
+ this.libroCommandRegistry.executeCommand(NotebookCommands['RunCellAndInsertBelow'].id);
81
+ },
82
+ });
83
+ this.commandRegistry.registerCommand(NotebookCommands['SplitCellAntCursor'], {
84
+ execute: () => {
85
+ this.libroCommandRegistry.executeCommand(NotebookCommands['SplitCellAntCursor'].id);
86
+ },
87
+ });
88
+ this.commandRegistry.registerCommand(LibroSearchToggleCommand.ShowLibroSearch, {
89
+ execute: () => {
90
+ this.libroCommandRegistry.executeCommand(LibroSearchToggleCommand.ShowLibroSearch.id);
91
+ },
92
+ });
93
+ }
94
+
95
+ registerKeybind() {
96
+ this.keybindingRegistry.registerKeybindings(
97
+ [
98
+ {
99
+ keybinding: 'f1',
100
+ command: '',
101
+ when: 'libroNotebookFocused',
102
+ },
103
+ {
104
+ keybinding: 'f8',
105
+ command: '',
106
+ when: 'libroNotebookFocused',
107
+ },
108
+ {
109
+ keybinding: 'f9',
110
+ command: '',
111
+ when: 'libroNotebookFocused',
112
+ },
113
+ {
114
+ keybinding: 'esc',
115
+ command: NotebookCommands['EnterCommandMode'].id,
116
+ when: 'libroNotebookFocused && !editorHasSelection && !editorHasSelection && !editorHasMultipleSelections',
117
+ },
118
+ {
119
+ keybinding: 'ctrlcmd+enter',
120
+ command: NotebookCommands['RunCell'].id,
121
+ when: 'libroNotebookFocused && !findWidgetVisible && !referenceSearchVisible',
122
+ },
123
+ {
124
+ keybinding: 'shift+enter',
125
+ command: NotebookCommands['RunCellAndSelectNext'].id,
126
+ when: 'libroNotebookFocused && !findInputFocussed',
127
+ },
128
+ {
129
+ keybinding: 'alt+enter',
130
+ command: NotebookCommands['RunCellAndInsertBelow'].id,
131
+ when: 'libroNotebookFocused && !findWidgetVisible',
132
+ },
133
+ {
134
+ keybinding: 'ctrlcmd+shift+-',
135
+ command: NotebookCommands['SplitCellAntCursor'].id,
136
+ when: 'libroNotebookFocused && !findWidgetVisible',
137
+ },
138
+ {
139
+ keybinding: 'ctrlcmd+f',
140
+ command: LibroSearchToggleCommand.ShowLibroSearch.id,
141
+ when: 'libroNotebookFocused',
142
+ },
143
+ ],
144
+ KeybindingScope.USER,
145
+ );
146
+ }
147
+ }
@@ -0,0 +1,96 @@
1
+ import { IPosition as LibroPosition, IRange as LibroRange } from '@difizen/libro-code-editor';
2
+ import { CellUri, EditorCellView, ExecutableNotebookModel } from '@difizen/libro-jupyter/noeditor';
3
+
4
+ import { Autowired, Injectable } from '@opensumi/di';
5
+ import { IOpener, IPosition, IRange, URI } from '@opensumi/ide-core-browser';
6
+ import { Schemes } from '@opensumi/ide-core-common';
7
+
8
+ import { LibroOpensumiService } from './libro.service';
9
+
10
+ export const toEditorRange = (range: IRange): LibroRange => ({
11
+ start: {
12
+ line: range.startLineNumber - 1,
13
+ column: range.startColumn - 1,
14
+ },
15
+ end: {
16
+ line: range.endLineNumber - 1,
17
+ column: range.endColumn - 1,
18
+ },
19
+ });
20
+
21
+ export const toMonacoPosition = (position: IPosition | undefined): LibroPosition => {
22
+ if (!position) {
23
+ return {
24
+ column: 0,
25
+ line: 0,
26
+ };
27
+ }
28
+ return {
29
+ column: position?.column - 1,
30
+ line: position?.lineNumber - 1,
31
+ };
32
+ };
33
+
34
+ @Injectable()
35
+ export class LibroOpener implements IOpener {
36
+ // @Autowired(ResourceService)
37
+ // resourceService: ResourceService;
38
+
39
+ // @Autowired(WorkbenchEditorService)
40
+ // workbenchEditorService: WorkbenchEditorService;
41
+ @Autowired(LibroOpensumiService)
42
+ libroOpensumiService: LibroOpensumiService;
43
+
44
+ async open(uri: URI) {
45
+ let range: IRange | undefined;
46
+ const match = /^L?(\d+)(?:,(\d+))?/.exec(uri.fragment);
47
+ if (match) {
48
+ // support file:///some/file.js#73,84
49
+ // support file:///some/file.js#L73
50
+ const startLineNumber = parseInt(match[1], 10);
51
+ const startColumn = match[2] ? parseInt(match[2], 10) : 1;
52
+ range = {
53
+ startLineNumber,
54
+ startColumn,
55
+ endLineNumber: startLineNumber,
56
+ endColumn: startColumn,
57
+ };
58
+ }
59
+ await this.openCell(uri, range);
60
+ return true;
61
+ }
62
+
63
+ protected async openCell(uri: URI, range?: IRange) {
64
+ const notebookUri = URI.file(uri.path.toString());
65
+ const libroView = await this.libroOpensumiService.getOrCreatLibroView(notebookUri);
66
+
67
+ if (!libroView) {
68
+ return false;
69
+ }
70
+
71
+ const cell = libroView.model.cells.find(
72
+ (item) =>
73
+ ExecutableNotebookModel.is(libroView.model) &&
74
+ CellUri.from(libroView.model.filePath, item.model.id).toString() === decodeURIComponent(uri.toString()),
75
+ );
76
+
77
+ if (!EditorCellView.is(cell)) {
78
+ return;
79
+ }
80
+
81
+ libroView.selectCell(cell);
82
+ let line = 0;
83
+ if (range) {
84
+ cell.editor?.focus();
85
+ cell.editor?.revealSelection(toEditorRange(range));
86
+ cell.editor?.setCursorPosition(toEditorRange(range).start);
87
+ line = toEditorRange(range).start.line;
88
+ }
89
+ libroView.model.scrollToView(cell, (line ?? 0) * 20);
90
+ }
91
+
92
+ handleScheme(scheme: string) {
93
+ // 使用 handleURI 后会忽略 handleScheme
94
+ return scheme === Schemes.notebookCell;
95
+ }
96
+ }
@@ -0,0 +1,32 @@
1
+ import { localize } from '@opensumi/ide-core-browser';
2
+ import { registerColor } from '@opensumi/ide-theme/lib/common';
3
+
4
+ export const initLibroColorToken = () => {
5
+ registerColor(
6
+ 'libro.background',
7
+ { dark: '#151b21', light: '#ffffff', hcDark: null, hcLight: null },
8
+ localize('libro.background', 'Background color of libroView'),
9
+ true,
10
+ );
11
+
12
+ registerColor(
13
+ 'libro.side.toolbar.background',
14
+ { dark: '#20262E', light: '#ffffff', hcDark: null, hcLight: null },
15
+ localize('libro.side.toolbar.background', 'the side toolbar color of libro'),
16
+ true,
17
+ );
18
+
19
+ registerColor(
20
+ 'libro.output.background',
21
+ { dark: '#222830', light: '#ffffff', hcDark: null, hcLight: null },
22
+ localize('libro.output.background', 'the output color of libro'),
23
+ true,
24
+ );
25
+
26
+ registerColor(
27
+ 'libro.input.background',
28
+ { dark: '#151b21', light: '#f4f6fb', hcDark: null, hcLight: null },
29
+ localize('libro.input.background', 'the input color of libro'),
30
+ true,
31
+ );
32
+ };
@@ -0,0 +1,63 @@
1
+ import { LibroSearchManager, LibroService } from '@difizen/libro-jupyter/noeditor';
2
+ import { Container } from '@difizen/mana-app';
3
+
4
+ import { Autowired } from '@opensumi/di';
5
+ import { CommandContribution, CommandRegistry, Domain, EDITOR_COMMANDS } from '@opensumi/ide-core-browser';
6
+
7
+ import { ManaContainer } from './mana';
8
+
9
+ @Domain(CommandContribution)
10
+ export class LibroCommandContribution implements CommandContribution {
11
+ @Autowired(ManaContainer)
12
+ private readonly manaContainer: Container;
13
+
14
+ registerCommands(commands: CommandRegistry): void {
15
+ commands.registerHandler(EDITOR_COMMANDS.SAVE_CURRENT.id, {
16
+ execute: () => {
17
+ const libroService = this.manaContainer.get(LibroService);
18
+ const libro = libroService.active;
19
+ libro?.save();
20
+ },
21
+ isEnabled: () => {
22
+ const libroService = this.manaContainer.get(LibroService);
23
+ if (libroService.focus) {
24
+ return true;
25
+ }
26
+ return false;
27
+ },
28
+ });
29
+ commands.registerHandler(EDITOR_COMMANDS.FOCUS_IF_NOT_ACTIVATE_ELEMENT.id, {
30
+ execute: () => {
31
+ const libroService = this.manaContainer.get(LibroService);
32
+ const libro = libroService.active;
33
+ const libroSearchManager = this.manaContainer.get(LibroSearchManager);
34
+ if (libro) {
35
+ libroSearchManager.showSearchView(libro);
36
+ }
37
+ },
38
+ isEnabled: () => {
39
+ const libroService = this.manaContainer.get(LibroService);
40
+ if (libroService.focus) {
41
+ return true;
42
+ }
43
+ return false;
44
+ },
45
+ });
46
+ commands.registerHandler('markers', {
47
+ execute: () => {
48
+ const libroService = this.manaContainer.get(LibroService);
49
+ const libro = libroService.active;
50
+ if (libro && libro.activeCell) {
51
+ libro.mergeCellBelow(libro.activeCell);
52
+ }
53
+ },
54
+ isEnabled: () => {
55
+ const libroService = this.manaContainer.get(LibroService);
56
+ if (libroService.focus) {
57
+ return true;
58
+ }
59
+ return false;
60
+ },
61
+ });
62
+ }
63
+ }
@@ -0,0 +1,189 @@
1
+ import { LibroJupyterNoEditorModule, ServerConnection, ServerManager } from '@difizen/libro-jupyter/noeditor';
2
+ import { LibroTOCModule } from '@difizen/libro-toc';
3
+ import { Container, ManaAppPreset, ManaComponents, ThemeService } from '@difizen/mana-app';
4
+ import React, { useState } from 'react';
5
+
6
+ import { Autowired, Injector } from '@opensumi/di';
7
+ import {
8
+ AppConfig,
9
+ ClientAppContextContribution,
10
+ ClientAppContribution,
11
+ CommandContribution,
12
+ type CommandRegistry,
13
+ Domain,
14
+ IClientApp,
15
+ IOpenerService,
16
+ OpenerContribution,
17
+ Schemes,
18
+ URI,
19
+ } from '@opensumi/ide-core-browser';
20
+ import {
21
+ BrowserEditorContribution,
22
+ EditorComponentRegistry,
23
+ IResource,
24
+ ResourceService,
25
+ WorkbenchEditorService,
26
+ } from '@opensumi/ide-editor/lib/browser';
27
+ import { IEditorDocumentModelContentRegistry } from '@opensumi/ide-editor/lib/browser/doc-model/types';
28
+ import { IconService } from '@opensumi/ide-theme/lib/browser';
29
+ import { IThemeService, IconType } from '@opensumi/ide-theme/lib/common';
30
+
31
+ import { initKernelPanelColorToken } from './kernel-panel';
32
+ import { LibroOpensumiModule } from './libro';
33
+ import { LibroOpener } from './libro-opener';
34
+ import { initLibroColorToken } from './libro.color.tokens';
35
+ import { LIBRO_COMPONENTS_ID, LIBRO_COMPONENTS_SCHEME_ID } from './libro.protocol';
36
+ import { OpensumiLibroView } from './libro.view';
37
+ import { ManaContainer, initLibroOpensumi, manaContainer } from './mana/index';
38
+ import { NotebookDocumentContentProvider } from './notebook-document-content-provider';
39
+ import { initTocPanelColorToken } from './toc';
40
+
41
+ const LIBRO_COMPONENTS_VIEW_COMMAND = {
42
+ id: 'opensumi-libro',
43
+ };
44
+
45
+ const LayoutWrapper: React.FC<React.PropsWithChildren> = ({ children }) => {
46
+ const [isReady, setIsReady] = useState(false);
47
+ return (
48
+ <ManaComponents.Application
49
+ context={{ container: manaContainer }}
50
+ modules={[ManaAppPreset, LibroJupyterNoEditorModule, LibroTOCModule, LibroOpensumiModule]}
51
+ renderChildren
52
+ onReady={() => setIsReady(true)}
53
+ >
54
+ {isReady ? children : 'loading'}
55
+ </ManaComponents.Application>
56
+ );
57
+ };
58
+
59
+ @Domain(
60
+ ClientAppContribution,
61
+ BrowserEditorContribution,
62
+ ClientAppContextContribution,
63
+ CommandContribution,
64
+ OpenerContribution,
65
+ )
66
+ export class LibroContribution
67
+ implements
68
+ ClientAppContribution,
69
+ BrowserEditorContribution,
70
+ ClientAppContextContribution,
71
+ CommandContribution,
72
+ OpenerContribution
73
+ {
74
+ @Autowired(ManaContainer)
75
+ private readonly manaContainer: Container;
76
+
77
+ @Autowired(IconService)
78
+ protected readonly iconService: IconService;
79
+
80
+ @Autowired(WorkbenchEditorService)
81
+ protected readonly editorService: WorkbenchEditorService;
82
+
83
+ @Autowired(IThemeService)
84
+ protected readonly themeService: IThemeService;
85
+
86
+ @Autowired(NotebookDocumentContentProvider)
87
+ protected readonly notebookDocumentContentProvider: NotebookDocumentContentProvider;
88
+
89
+ @Autowired(LibroOpener)
90
+ protected readonly libroOpener: LibroOpener;
91
+
92
+ @Autowired(AppConfig)
93
+ config: AppConfig;
94
+
95
+ private serverManagerInited = false;
96
+
97
+ registerOpener(registry: IOpenerService): void {
98
+ registry.registerOpener(this.libroOpener);
99
+ }
100
+
101
+ initialize(app: IClientApp) {
102
+ initLibroOpensumi(app.injector, manaContainer);
103
+ }
104
+
105
+ registerClientAppContext(Layout: React.FC, injector: Injector): React.FC {
106
+ initLibroColorToken();
107
+ initKernelPanelColorToken();
108
+ initTocPanelColorToken();
109
+ return () => (
110
+ <LayoutWrapper>
111
+ <Layout />
112
+ </LayoutWrapper>
113
+ );
114
+ }
115
+
116
+ registerCommands(registry: CommandRegistry) {
117
+ registry.registerCommand(LIBRO_COMPONENTS_VIEW_COMMAND, {
118
+ execute: () => {
119
+ this.editorService.open(new URI(`${LIBRO_COMPONENTS_SCHEME_ID}://`), {
120
+ preview: false,
121
+ });
122
+ },
123
+ });
124
+ }
125
+
126
+ registerEditorComponent(registry: EditorComponentRegistry) {
127
+ registry.registerEditorComponent({
128
+ uid: LIBRO_COMPONENTS_ID,
129
+ scheme: LIBRO_COMPONENTS_SCHEME_ID,
130
+ component: OpensumiLibroView,
131
+ });
132
+
133
+ registry.registerEditorComponentResolver(Schemes.file, (resource, results) => {
134
+ if (resource.uri.path.ext === `.${LIBRO_COMPONENTS_SCHEME_ID}`) {
135
+ // 首次打开 notebook 文件时初始化 jupyter 服务连接
136
+ if (!this.serverManagerInited && this.config.notebookServerHost) {
137
+ this.serverManagerInited = true;
138
+ // 目前直接从浏览器连接 jupyter 服务,对服务的cors等配置会有要求
139
+ this.connectJupyterServer(this.config.notebookServerHost);
140
+ }
141
+ results.push({
142
+ type: 'component',
143
+ componentId: LIBRO_COMPONENTS_ID,
144
+ });
145
+ }
146
+ });
147
+ }
148
+
149
+ registerEditorDocumentModelContentProvider(registry: IEditorDocumentModelContentRegistry) {
150
+ registry.registerEditorDocumentModelContentProvider(this.notebookDocumentContentProvider);
151
+ }
152
+
153
+ registerResource(service: ResourceService) {
154
+ service.registerResourceProvider({
155
+ scheme: LIBRO_COMPONENTS_SCHEME_ID,
156
+ provideResource: async (uri: URI): Promise<IResource<any>> => {
157
+ const iconClass = this.iconService.fromIcon(
158
+ '',
159
+ 'https://mdn.alipayobjects.com/huamei_xt20ge/afts/img/A*LDFvSptm_zgAAAAAAAAAAAAADiuUAQ/original',
160
+ IconType.Background,
161
+ );
162
+ return {
163
+ uri,
164
+ name: 'notebook',
165
+ icon: iconClass!,
166
+ };
167
+ },
168
+ });
169
+ }
170
+
171
+ async onDidStart() {
172
+ const manaThemeService = this.manaContainer.get(ThemeService);
173
+ const curTheme = await this.themeService.getCurrentTheme();
174
+ manaThemeService.setCurrentTheme(curTheme.type);
175
+ this.themeService.onThemeChange((theme) => {
176
+ manaThemeService.setCurrentTheme(theme.type);
177
+ });
178
+ }
179
+
180
+ protected connectJupyterServer(serverHost: string) {
181
+ const libroServerConnection = this.manaContainer.get(ServerConnection);
182
+ libroServerConnection.updateSettings({
183
+ baseUrl: `http://${serverHost}/`,
184
+ wsUrl: `ws://${serverHost}/`,
185
+ });
186
+ const serverManager = this.manaContainer.get(ServerManager);
187
+ serverManager.launch();
188
+ }
189
+ }
@@ -0,0 +1,40 @@
1
+ .libroView {
2
+ height: 100%;
3
+
4
+ :global {
5
+ .libro-view {
6
+ background-color: var(--libro-background);
7
+
8
+ .cm-editor,
9
+ .cm-gutters {
10
+ background-color: var(--libro-input-background);
11
+ }
12
+ }
13
+
14
+ .libro-cell-right-toolbar {
15
+ background-color: var(--libro-side-toolbar-background);
16
+ }
17
+
18
+ .libro-cell-output-container {
19
+ background-color: var(--libro-output-background);
20
+ }
21
+
22
+ .libro-cell-container,
23
+ .libro-input-hidden {
24
+ background-color: var(--libro-input-background);
25
+ }
26
+
27
+ .libro-e2-editor-container {
28
+ background-color: var(--libro-input-background) !important;
29
+ }
30
+
31
+ .libro-e2-editor {
32
+ background: var(--mana-libro-input-background) !important;
33
+
34
+ .monaco-editor-background,
35
+ .margin {
36
+ background: var(--libro-input-background) !important;
37
+ }
38
+ }
39
+ }
40
+ }
@@ -0,0 +1,2 @@
1
+ export const LIBRO_COMPONENTS_ID = 'opensumi:libro';
2
+ export const LIBRO_COMPONENTS_SCHEME_ID = 'ipynb';