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

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 (78) hide show
  1. package/README.md +30 -30
  2. package/lib/browser/index.d.ts +1 -0
  3. package/lib/browser/index.d.ts.map +1 -1
  4. package/lib/browser/index.js +1 -0
  5. package/lib/browser/index.js.map +1 -1
  6. package/lib/browser/notebook-frontend-module.d.ts.map +1 -1
  7. package/lib/browser/notebook-frontend-module.js +2 -0
  8. package/lib/browser/notebook-frontend-module.js.map +1 -1
  9. package/lib/browser/service/notebook-cell-editor-service.d.ts +16 -0
  10. package/lib/browser/service/notebook-cell-editor-service.d.ts.map +1 -0
  11. package/lib/browser/service/notebook-cell-editor-service.js +53 -0
  12. package/lib/browser/service/notebook-cell-editor-service.js.map +1 -0
  13. package/lib/browser/view/notebook-cell-editor.d.ts +2 -0
  14. package/lib/browser/view/notebook-cell-editor.d.ts.map +1 -1
  15. package/lib/browser/view/notebook-cell-editor.js +12 -1
  16. package/lib/browser/view/notebook-cell-editor.js.map +1 -1
  17. package/lib/browser/view/notebook-code-cell-view.d.ts +2 -0
  18. package/lib/browser/view/notebook-code-cell-view.d.ts.map +1 -1
  19. package/lib/browser/view/notebook-code-cell-view.js +6 -1
  20. package/lib/browser/view/notebook-code-cell-view.js.map +1 -1
  21. package/lib/browser/view/notebook-markdown-cell-view.d.ts +2 -0
  22. package/lib/browser/view/notebook-markdown-cell-view.d.ts.map +1 -1
  23. package/lib/browser/view/notebook-markdown-cell-view.js +8 -3
  24. package/lib/browser/view/notebook-markdown-cell-view.js.map +1 -1
  25. package/package.json +7 -7
  26. package/src/browser/contributions/cell-operations.ts +44 -44
  27. package/src/browser/contributions/notebook-actions-contribution.ts +379 -379
  28. package/src/browser/contributions/notebook-cell-actions-contribution.ts +525 -525
  29. package/src/browser/contributions/notebook-color-contribution.ts +268 -268
  30. package/src/browser/contributions/notebook-context-keys.ts +113 -113
  31. package/src/browser/contributions/notebook-label-provider-contribution.ts +85 -85
  32. package/src/browser/contributions/notebook-outline-contribution.ts +114 -114
  33. package/src/browser/contributions/notebook-output-action-contribution.ts +82 -82
  34. package/src/browser/contributions/notebook-preferences.ts +92 -92
  35. package/src/browser/contributions/notebook-status-bar-contribution.ts +77 -77
  36. package/src/browser/contributions/notebook-undo-redo-handler.ts +41 -41
  37. package/src/browser/index.ts +28 -27
  38. package/src/browser/notebook-cell-resource-resolver.ts +130 -130
  39. package/src/browser/notebook-editor-widget-factory.ts +82 -82
  40. package/src/browser/notebook-editor-widget.tsx +330 -330
  41. package/src/browser/notebook-frontend-module.ts +121 -119
  42. package/src/browser/notebook-open-handler.ts +120 -120
  43. package/src/browser/notebook-output-utils.ts +119 -119
  44. package/src/browser/notebook-renderer-registry.ts +85 -85
  45. package/src/browser/notebook-type-registry.ts +54 -54
  46. package/src/browser/notebook-types.ts +186 -186
  47. package/src/browser/renderers/cell-output-webview.ts +33 -33
  48. package/src/browser/service/notebook-cell-editor-service.ts +56 -0
  49. package/src/browser/service/notebook-clipboard-service.ts +43 -43
  50. package/src/browser/service/notebook-context-manager.ts +162 -162
  51. package/src/browser/service/notebook-editor-widget-service.ts +101 -101
  52. package/src/browser/service/notebook-execution-service.ts +139 -139
  53. package/src/browser/service/notebook-execution-state-service.ts +311 -311
  54. package/src/browser/service/notebook-kernel-history-service.ts +124 -124
  55. package/src/browser/service/notebook-kernel-quick-pick-service.ts +479 -479
  56. package/src/browser/service/notebook-kernel-service.ts +357 -357
  57. package/src/browser/service/notebook-model-resolver-service.ts +160 -160
  58. package/src/browser/service/notebook-monaco-text-model-service.ts +48 -48
  59. package/src/browser/service/notebook-options.ts +155 -155
  60. package/src/browser/service/notebook-renderer-messaging-service.ts +121 -121
  61. package/src/browser/service/notebook-service.ts +215 -215
  62. package/src/browser/style/index.css +484 -483
  63. package/src/browser/view/notebook-cell-editor.tsx +276 -263
  64. package/src/browser/view/notebook-cell-list-view.tsx +279 -279
  65. package/src/browser/view/notebook-cell-toolbar-factory.tsx +102 -102
  66. package/src/browser/view/notebook-cell-toolbar.tsx +74 -74
  67. package/src/browser/view/notebook-code-cell-view.tsx +355 -350
  68. package/src/browser/view/notebook-find-widget.tsx +335 -335
  69. package/src/browser/view/notebook-main-toolbar.tsx +235 -235
  70. package/src/browser/view/notebook-markdown-cell-view.tsx +215 -208
  71. package/src/browser/view/notebook-viewport-service.ts +61 -61
  72. package/src/browser/view-model/notebook-cell-model.ts +473 -473
  73. package/src/browser/view-model/notebook-cell-output-model.ts +100 -100
  74. package/src/browser/view-model/notebook-model.ts +550 -550
  75. package/src/common/index.ts +18 -18
  76. package/src/common/notebook-common.ts +337 -337
  77. package/src/common/notebook-protocol.ts +35 -35
  78. package/src/common/notebook-range.ts +30 -30
@@ -1,330 +1,330 @@
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, DelegatingSaveable, lock, unlock, animationFrame } 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, postConstruct } from '@theia/core/shared/inversify';
28
- import { Emitter } from '@theia/core/shared/vscode-languageserver-protocol';
29
- import { NotebookEditorWidgetService } from './service/notebook-editor-widget-service';
30
- import { NotebookMainToolbarRenderer } from './view/notebook-main-toolbar';
31
- import { Deferred } from '@theia/core/lib/common/promise-util';
32
- import { MarkdownString } from '@theia/core/lib/common/markdown-rendering';
33
- import { NotebookContextManager } from './service/notebook-context-manager';
34
- import { NotebookViewportService } from './view/notebook-viewport-service';
35
- import { NotebookCellCommands } from './contributions/notebook-cell-actions-contribution';
36
- import { NotebookFindWidget } from './view/notebook-find-widget';
37
- import debounce = require('lodash/debounce');
38
- const PerfectScrollbar = require('react-perfect-scrollbar');
39
-
40
- export const NotebookEditorWidgetContainerFactory = Symbol('NotebookEditorWidgetContainerFactory');
41
-
42
- export function createNotebookEditorWidgetContainer(parent: interfaces.Container, props: NotebookEditorProps): interfaces.Container {
43
- const child = parent.createChild();
44
-
45
- child.bind(NotebookEditorProps).toConstantValue(props);
46
-
47
- child.bind(NotebookContextManager).toSelf().inSingletonScope();
48
- child.bind(NotebookMainToolbarRenderer).toSelf().inSingletonScope();
49
- child.bind(NotebookCellToolbarFactory).toSelf().inSingletonScope();
50
- child.bind(NotebookCodeCellRenderer).toSelf().inSingletonScope();
51
- child.bind(NotebookMarkdownCellRenderer).toSelf().inSingletonScope();
52
- child.bind(NotebookViewportService).toSelf().inSingletonScope();
53
-
54
- child.bind(NotebookEditorWidget).toSelf();
55
-
56
- return child;
57
- }
58
-
59
- export const NotebookEditorProps = Symbol('NotebookEditorProps');
60
-
61
- interface RenderMessage {
62
- rendererId: string;
63
- message: unknown;
64
- }
65
-
66
- export interface NotebookEditorProps {
67
- uri: URI,
68
- readonly notebookType: string,
69
- notebookData: Promise<NotebookModel>
70
- }
71
- export const NOTEBOOK_EDITOR_ID_PREFIX = 'notebook:';
72
-
73
- @injectable()
74
- export class NotebookEditorWidget extends ReactWidget implements Navigatable, SaveableSource {
75
- static readonly ID = 'notebook';
76
-
77
- readonly saveable = new DelegatingSaveable();
78
-
79
- @inject(NotebookCellToolbarFactory)
80
- protected readonly cellToolbarFactory: NotebookCellToolbarFactory;
81
-
82
- @inject(CommandRegistry)
83
- protected commandRegistry: CommandRegistry;
84
-
85
- @inject(MenuModelRegistry)
86
- protected menuRegistry: MenuModelRegistry;
87
-
88
- @inject(NotebookEditorWidgetService)
89
- protected notebookEditorService: NotebookEditorWidgetService;
90
-
91
- @inject(NotebookMainToolbarRenderer)
92
- protected notebookMainToolbarRenderer: NotebookMainToolbarRenderer;
93
-
94
- @inject(NotebookContextManager)
95
- protected notebookContextManager: NotebookContextManager;
96
-
97
- @inject(NotebookCodeCellRenderer)
98
- protected codeCellRenderer: NotebookCodeCellRenderer;
99
- @inject(NotebookMarkdownCellRenderer)
100
- protected markdownCellRenderer: NotebookMarkdownCellRenderer;
101
- @inject(NotebookEditorProps)
102
- protected readonly props: NotebookEditorProps;
103
-
104
- @inject(NotebookViewportService)
105
- protected readonly viewportService: NotebookViewportService;
106
-
107
- protected readonly onDidChangeModelEmitter = new Emitter<void>();
108
- readonly onDidChangeModel = this.onDidChangeModelEmitter.event;
109
-
110
- protected readonly onDidChangeReadOnlyEmitter = new Emitter<boolean | MarkdownString>();
111
- readonly onDidChangeReadOnly = this.onDidChangeReadOnlyEmitter.event;
112
-
113
- protected readonly onPostKernelMessageEmitter = new Emitter<unknown>();
114
- readonly onPostKernelMessage = this.onPostKernelMessageEmitter.event;
115
-
116
- protected readonly onDidPostKernelMessageEmitter = new Emitter<unknown>();
117
- readonly onDidPostKernelMessage = this.onDidPostKernelMessageEmitter.event;
118
-
119
- protected readonly onPostRendererMessageEmitter = new Emitter<RenderMessage>();
120
- readonly onPostRendererMessage = this.onPostRendererMessageEmitter.event;
121
-
122
- protected readonly onDidReceiveKernelMessageEmitter = new Emitter<unknown>();
123
- readonly onDidReceiveKernelMessage = this.onDidReceiveKernelMessageEmitter.event;
124
-
125
- protected readonly onDidChangeOutputInputFocusEmitter = new Emitter<boolean>();
126
- readonly onDidChangeOutputInputFocus = this.onDidChangeOutputInputFocusEmitter.event;
127
-
128
- protected readonly renderers = new Map<CellKind, CellRenderer>();
129
- protected _model?: NotebookModel;
130
- protected _ready: Deferred<NotebookModel> = new Deferred();
131
- protected _findWidgetVisible = false;
132
- protected _findWidgetRef = React.createRef<NotebookFindWidget>();
133
- protected scrollBarRef = React.createRef<{ updateScroll(): void }>();
134
- protected debounceFind = debounce(() => {
135
- this._findWidgetRef.current?.search({});
136
- }, 30, {
137
- trailing: true,
138
- maxWait: 100,
139
- leading: false
140
- });
141
-
142
- get notebookType(): string {
143
- return this.props.notebookType;
144
- }
145
-
146
- get ready(): Promise<NotebookModel> {
147
- return this._ready.promise;
148
- }
149
-
150
- get model(): NotebookModel | undefined {
151
- return this._model;
152
- }
153
-
154
- @postConstruct()
155
- protected init(): void {
156
- this.id = NOTEBOOK_EDITOR_ID_PREFIX + this.props.uri.toString();
157
-
158
- this.scrollOptions = {
159
- suppressScrollY: true
160
- };
161
-
162
- this.title.closable = true;
163
- this.update();
164
-
165
- this.toDispose.push(this.onDidChangeModelEmitter);
166
- this.toDispose.push(this.onDidChangeReadOnlyEmitter);
167
-
168
- this.renderers.set(CellKind.Markup, this.markdownCellRenderer);
169
- this.renderers.set(CellKind.Code, this.codeCellRenderer);
170
- this._ready.resolve(this.waitForData());
171
- this.ready.then(model => {
172
- if (model.cells.length === 1 && model.cells[0].source === '') {
173
- this.commandRegistry.executeCommand(NotebookCellCommands.EDIT_COMMAND.id, model, model.cells[0]);
174
- model.setSelectedCell(model.cells[0]);
175
- }
176
- });
177
- }
178
-
179
- protected async waitForData(): Promise<NotebookModel> {
180
- this._model = await this.props.notebookData;
181
- this.saveable.delegate = this._model;
182
- this.toDispose.push(this._model);
183
- this.toDispose.push(this._model.onDidChangeContent(() => {
184
- // Update the scroll bar content after the content has changed
185
- // Wait one frame to ensure that the content has been rendered
186
- animationFrame().then(() => this.scrollBarRef.current?.updateScroll());
187
- }));
188
- this.toDispose.push(this._model.onContentChanged(() => {
189
- if (this._findWidgetVisible) {
190
- this.debounceFind();
191
- }
192
- }));
193
- this.toDispose.push(this._model.onDidChangeReadOnly(readOnly => {
194
- if (readOnly) {
195
- lock(this.title);
196
- } else {
197
- unlock(this.title);
198
- }
199
- this.onDidChangeReadOnlyEmitter.fire(readOnly);
200
- this.update();
201
- }));
202
- if (this._model.readOnly) {
203
- lock(this.title);
204
- }
205
- // Ensure that the model is loaded before adding the editor
206
- this.notebookEditorService.addNotebookEditor(this);
207
- this._model.selectedCell = this._model.cells[0];
208
- this.update();
209
- this.notebookContextManager.init(this);
210
- return this._model;
211
- }
212
-
213
- protected override onActivateRequest(msg: Message): void {
214
- super.onActivateRequest(msg);
215
- this.node.focus();
216
- }
217
-
218
- getResourceUri(): URI | undefined {
219
- return this.props.uri;
220
- }
221
-
222
- createMoveToUri(resourceUri: URI): URI | undefined {
223
- return this.model?.uri.withPath(resourceUri.path);
224
- }
225
-
226
- undo(): void {
227
- this._model?.undo();
228
- }
229
-
230
- redo(): void {
231
- this._model?.redo();
232
- }
233
-
234
- protected render(): ReactNode {
235
- if (this._model) {
236
- return <div className='theia-notebook-main-container' tabIndex={-1}>
237
- <div className='theia-notebook-overlay'>
238
- <NotebookFindWidget
239
- ref={this._findWidgetRef}
240
- hidden={!this._findWidgetVisible}
241
- onClose={() => {
242
- this._findWidgetVisible = false;
243
- this._model?.findMatches({
244
- activeFilters: [],
245
- matchCase: false,
246
- regex: false,
247
- search: '',
248
- wholeWord: false
249
- });
250
- this.update();
251
- }}
252
- onSearch={options => this._model?.findMatches(options) ?? []}
253
- onReplace={(matches, replaceText) => this._model?.replaceAll(matches, replaceText)}
254
- />
255
- </div>
256
- {this.notebookMainToolbarRenderer.render(this._model, this.node)}
257
- <div
258
- className='theia-notebook-viewport'
259
- ref={(ref: HTMLDivElement) => this.viewportService.viewportElement = ref}
260
- >
261
- <PerfectScrollbar className='theia-notebook-scroll-container'
262
- ref={this.scrollBarRef}
263
- onScrollY={(e: HTMLDivElement) => this.viewportService.onScroll(e)}>
264
- <NotebookCellListView renderers={this.renderers}
265
- notebookModel={this._model}
266
- notebookContext={this.notebookContextManager}
267
- toolbarRenderer={this.cellToolbarFactory}
268
- commandRegistry={this.commandRegistry}
269
- menuRegistry={this.menuRegistry} />
270
- </PerfectScrollbar>
271
- </div>
272
- </div>;
273
- } else {
274
- return <div className='theia-notebook-main-container'>
275
- <div className='theia-notebook-main-loading-indicator'></div>
276
- </div>;
277
- }
278
- }
279
-
280
- protected override onCloseRequest(msg: Message): void {
281
- super.onCloseRequest(msg);
282
- this.notebookEditorService.removeNotebookEditor(this);
283
- }
284
-
285
- postKernelMessage(message: unknown): void {
286
- this.onDidPostKernelMessageEmitter.fire(message);
287
- }
288
-
289
- postRendererMessage(rendererId: string, message: unknown): void {
290
- this.onPostRendererMessageEmitter.fire({ rendererId, message });
291
- }
292
-
293
- recieveKernelMessage(message: unknown): void {
294
- this.onDidReceiveKernelMessageEmitter.fire(message);
295
- }
296
-
297
- outputInputFocusChanged(focused: boolean): void {
298
- this.onDidChangeOutputInputFocusEmitter.fire(focused);
299
- }
300
-
301
- showFindWidget(): void {
302
- if (!this._findWidgetVisible) {
303
- this._findWidgetVisible = true;
304
- this.update();
305
- }
306
- this._findWidgetRef.current?.focusSearch(this._model?.selectedText);
307
- }
308
-
309
- override dispose(): void {
310
- this.notebookContextManager.dispose();
311
- this.onDidChangeModelEmitter.dispose();
312
- this.onDidPostKernelMessageEmitter.dispose();
313
- this.onDidReceiveKernelMessageEmitter.dispose();
314
- this.onPostRendererMessageEmitter.dispose();
315
- this.onDidChangeOutputInputFocusEmitter.dispose();
316
- this.viewportService.dispose();
317
- this._model?.dispose();
318
- super.dispose();
319
- }
320
-
321
- protected override onAfterShow(msg: Message): void {
322
- super.onAfterShow(msg);
323
- this.notebookEditorService.notebookEditorFocusChanged(this, true);
324
- }
325
-
326
- protected override onAfterHide(msg: Message): void {
327
- super.onAfterHide(msg);
328
- this.notebookEditorService.notebookEditorFocusChanged(this, false);
329
- }
330
- }
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, DelegatingSaveable, lock, unlock, animationFrame } 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, postConstruct } from '@theia/core/shared/inversify';
28
+ import { Emitter } from '@theia/core/shared/vscode-languageserver-protocol';
29
+ import { NotebookEditorWidgetService } from './service/notebook-editor-widget-service';
30
+ import { NotebookMainToolbarRenderer } from './view/notebook-main-toolbar';
31
+ import { Deferred } from '@theia/core/lib/common/promise-util';
32
+ import { MarkdownString } from '@theia/core/lib/common/markdown-rendering';
33
+ import { NotebookContextManager } from './service/notebook-context-manager';
34
+ import { NotebookViewportService } from './view/notebook-viewport-service';
35
+ import { NotebookCellCommands } from './contributions/notebook-cell-actions-contribution';
36
+ import { NotebookFindWidget } from './view/notebook-find-widget';
37
+ import debounce = require('lodash/debounce');
38
+ const PerfectScrollbar = require('react-perfect-scrollbar');
39
+
40
+ export const NotebookEditorWidgetContainerFactory = Symbol('NotebookEditorWidgetContainerFactory');
41
+
42
+ export function createNotebookEditorWidgetContainer(parent: interfaces.Container, props: NotebookEditorProps): interfaces.Container {
43
+ const child = parent.createChild();
44
+
45
+ child.bind(NotebookEditorProps).toConstantValue(props);
46
+
47
+ child.bind(NotebookContextManager).toSelf().inSingletonScope();
48
+ child.bind(NotebookMainToolbarRenderer).toSelf().inSingletonScope();
49
+ child.bind(NotebookCellToolbarFactory).toSelf().inSingletonScope();
50
+ child.bind(NotebookCodeCellRenderer).toSelf().inSingletonScope();
51
+ child.bind(NotebookMarkdownCellRenderer).toSelf().inSingletonScope();
52
+ child.bind(NotebookViewportService).toSelf().inSingletonScope();
53
+
54
+ child.bind(NotebookEditorWidget).toSelf();
55
+
56
+ return child;
57
+ }
58
+
59
+ export const NotebookEditorProps = Symbol('NotebookEditorProps');
60
+
61
+ interface RenderMessage {
62
+ rendererId: string;
63
+ message: unknown;
64
+ }
65
+
66
+ export interface NotebookEditorProps {
67
+ uri: URI,
68
+ readonly notebookType: string,
69
+ notebookData: Promise<NotebookModel>
70
+ }
71
+ export const NOTEBOOK_EDITOR_ID_PREFIX = 'notebook:';
72
+
73
+ @injectable()
74
+ export class NotebookEditorWidget extends ReactWidget implements Navigatable, SaveableSource {
75
+ static readonly ID = 'notebook';
76
+
77
+ readonly saveable = new DelegatingSaveable();
78
+
79
+ @inject(NotebookCellToolbarFactory)
80
+ protected readonly cellToolbarFactory: NotebookCellToolbarFactory;
81
+
82
+ @inject(CommandRegistry)
83
+ protected commandRegistry: CommandRegistry;
84
+
85
+ @inject(MenuModelRegistry)
86
+ protected menuRegistry: MenuModelRegistry;
87
+
88
+ @inject(NotebookEditorWidgetService)
89
+ protected notebookEditorService: NotebookEditorWidgetService;
90
+
91
+ @inject(NotebookMainToolbarRenderer)
92
+ protected notebookMainToolbarRenderer: NotebookMainToolbarRenderer;
93
+
94
+ @inject(NotebookContextManager)
95
+ protected notebookContextManager: NotebookContextManager;
96
+
97
+ @inject(NotebookCodeCellRenderer)
98
+ protected codeCellRenderer: NotebookCodeCellRenderer;
99
+ @inject(NotebookMarkdownCellRenderer)
100
+ protected markdownCellRenderer: NotebookMarkdownCellRenderer;
101
+ @inject(NotebookEditorProps)
102
+ protected readonly props: NotebookEditorProps;
103
+
104
+ @inject(NotebookViewportService)
105
+ protected readonly viewportService: NotebookViewportService;
106
+
107
+ protected readonly onDidChangeModelEmitter = new Emitter<void>();
108
+ readonly onDidChangeModel = this.onDidChangeModelEmitter.event;
109
+
110
+ protected readonly onDidChangeReadOnlyEmitter = new Emitter<boolean | MarkdownString>();
111
+ readonly onDidChangeReadOnly = this.onDidChangeReadOnlyEmitter.event;
112
+
113
+ protected readonly onPostKernelMessageEmitter = new Emitter<unknown>();
114
+ readonly onPostKernelMessage = this.onPostKernelMessageEmitter.event;
115
+
116
+ protected readonly onDidPostKernelMessageEmitter = new Emitter<unknown>();
117
+ readonly onDidPostKernelMessage = this.onDidPostKernelMessageEmitter.event;
118
+
119
+ protected readonly onPostRendererMessageEmitter = new Emitter<RenderMessage>();
120
+ readonly onPostRendererMessage = this.onPostRendererMessageEmitter.event;
121
+
122
+ protected readonly onDidReceiveKernelMessageEmitter = new Emitter<unknown>();
123
+ readonly onDidReceiveKernelMessage = this.onDidReceiveKernelMessageEmitter.event;
124
+
125
+ protected readonly onDidChangeOutputInputFocusEmitter = new Emitter<boolean>();
126
+ readonly onDidChangeOutputInputFocus = this.onDidChangeOutputInputFocusEmitter.event;
127
+
128
+ protected readonly renderers = new Map<CellKind, CellRenderer>();
129
+ protected _model?: NotebookModel;
130
+ protected _ready: Deferred<NotebookModel> = new Deferred();
131
+ protected _findWidgetVisible = false;
132
+ protected _findWidgetRef = React.createRef<NotebookFindWidget>();
133
+ protected scrollBarRef = React.createRef<{ updateScroll(): void }>();
134
+ protected debounceFind = debounce(() => {
135
+ this._findWidgetRef.current?.search({});
136
+ }, 30, {
137
+ trailing: true,
138
+ maxWait: 100,
139
+ leading: false
140
+ });
141
+
142
+ get notebookType(): string {
143
+ return this.props.notebookType;
144
+ }
145
+
146
+ get ready(): Promise<NotebookModel> {
147
+ return this._ready.promise;
148
+ }
149
+
150
+ get model(): NotebookModel | undefined {
151
+ return this._model;
152
+ }
153
+
154
+ @postConstruct()
155
+ protected init(): void {
156
+ this.id = NOTEBOOK_EDITOR_ID_PREFIX + this.props.uri.toString();
157
+
158
+ this.scrollOptions = {
159
+ suppressScrollY: true
160
+ };
161
+
162
+ this.title.closable = true;
163
+ this.update();
164
+
165
+ this.toDispose.push(this.onDidChangeModelEmitter);
166
+ this.toDispose.push(this.onDidChangeReadOnlyEmitter);
167
+
168
+ this.renderers.set(CellKind.Markup, this.markdownCellRenderer);
169
+ this.renderers.set(CellKind.Code, this.codeCellRenderer);
170
+ this._ready.resolve(this.waitForData());
171
+ this.ready.then(model => {
172
+ if (model.cells.length === 1 && model.cells[0].source === '') {
173
+ this.commandRegistry.executeCommand(NotebookCellCommands.EDIT_COMMAND.id, model, model.cells[0]);
174
+ model.setSelectedCell(model.cells[0]);
175
+ }
176
+ });
177
+ }
178
+
179
+ protected async waitForData(): Promise<NotebookModel> {
180
+ this._model = await this.props.notebookData;
181
+ this.saveable.delegate = this._model;
182
+ this.toDispose.push(this._model);
183
+ this.toDispose.push(this._model.onDidChangeContent(() => {
184
+ // Update the scroll bar content after the content has changed
185
+ // Wait one frame to ensure that the content has been rendered
186
+ animationFrame().then(() => this.scrollBarRef.current?.updateScroll());
187
+ }));
188
+ this.toDispose.push(this._model.onContentChanged(() => {
189
+ if (this._findWidgetVisible) {
190
+ this.debounceFind();
191
+ }
192
+ }));
193
+ this.toDispose.push(this._model.onDidChangeReadOnly(readOnly => {
194
+ if (readOnly) {
195
+ lock(this.title);
196
+ } else {
197
+ unlock(this.title);
198
+ }
199
+ this.onDidChangeReadOnlyEmitter.fire(readOnly);
200
+ this.update();
201
+ }));
202
+ if (this._model.readOnly) {
203
+ lock(this.title);
204
+ }
205
+ // Ensure that the model is loaded before adding the editor
206
+ this.notebookEditorService.addNotebookEditor(this);
207
+ this._model.selectedCell = this._model.cells[0];
208
+ this.update();
209
+ this.notebookContextManager.init(this);
210
+ return this._model;
211
+ }
212
+
213
+ protected override onActivateRequest(msg: Message): void {
214
+ super.onActivateRequest(msg);
215
+ this.node.focus();
216
+ }
217
+
218
+ getResourceUri(): URI | undefined {
219
+ return this.props.uri;
220
+ }
221
+
222
+ createMoveToUri(resourceUri: URI): URI | undefined {
223
+ return this.model?.uri.withPath(resourceUri.path);
224
+ }
225
+
226
+ undo(): void {
227
+ this._model?.undo();
228
+ }
229
+
230
+ redo(): void {
231
+ this._model?.redo();
232
+ }
233
+
234
+ protected render(): ReactNode {
235
+ if (this._model) {
236
+ return <div className='theia-notebook-main-container' tabIndex={-1}>
237
+ <div className='theia-notebook-overlay'>
238
+ <NotebookFindWidget
239
+ ref={this._findWidgetRef}
240
+ hidden={!this._findWidgetVisible}
241
+ onClose={() => {
242
+ this._findWidgetVisible = false;
243
+ this._model?.findMatches({
244
+ activeFilters: [],
245
+ matchCase: false,
246
+ regex: false,
247
+ search: '',
248
+ wholeWord: false
249
+ });
250
+ this.update();
251
+ }}
252
+ onSearch={options => this._model?.findMatches(options) ?? []}
253
+ onReplace={(matches, replaceText) => this._model?.replaceAll(matches, replaceText)}
254
+ />
255
+ </div>
256
+ {this.notebookMainToolbarRenderer.render(this._model, this.node)}
257
+ <div
258
+ className='theia-notebook-viewport'
259
+ ref={(ref: HTMLDivElement) => this.viewportService.viewportElement = ref}
260
+ >
261
+ <PerfectScrollbar className='theia-notebook-scroll-container'
262
+ ref={this.scrollBarRef}
263
+ onScrollY={(e: HTMLDivElement) => this.viewportService.onScroll(e)}>
264
+ <NotebookCellListView renderers={this.renderers}
265
+ notebookModel={this._model}
266
+ notebookContext={this.notebookContextManager}
267
+ toolbarRenderer={this.cellToolbarFactory}
268
+ commandRegistry={this.commandRegistry}
269
+ menuRegistry={this.menuRegistry} />
270
+ </PerfectScrollbar>
271
+ </div>
272
+ </div>;
273
+ } else {
274
+ return <div className='theia-notebook-main-container'>
275
+ <div className='theia-notebook-main-loading-indicator'></div>
276
+ </div>;
277
+ }
278
+ }
279
+
280
+ protected override onCloseRequest(msg: Message): void {
281
+ super.onCloseRequest(msg);
282
+ this.notebookEditorService.removeNotebookEditor(this);
283
+ }
284
+
285
+ postKernelMessage(message: unknown): void {
286
+ this.onDidPostKernelMessageEmitter.fire(message);
287
+ }
288
+
289
+ postRendererMessage(rendererId: string, message: unknown): void {
290
+ this.onPostRendererMessageEmitter.fire({ rendererId, message });
291
+ }
292
+
293
+ recieveKernelMessage(message: unknown): void {
294
+ this.onDidReceiveKernelMessageEmitter.fire(message);
295
+ }
296
+
297
+ outputInputFocusChanged(focused: boolean): void {
298
+ this.onDidChangeOutputInputFocusEmitter.fire(focused);
299
+ }
300
+
301
+ showFindWidget(): void {
302
+ if (!this._findWidgetVisible) {
303
+ this._findWidgetVisible = true;
304
+ this.update();
305
+ }
306
+ this._findWidgetRef.current?.focusSearch(this._model?.selectedText);
307
+ }
308
+
309
+ override dispose(): void {
310
+ this.notebookContextManager.dispose();
311
+ this.onDidChangeModelEmitter.dispose();
312
+ this.onDidPostKernelMessageEmitter.dispose();
313
+ this.onDidReceiveKernelMessageEmitter.dispose();
314
+ this.onPostRendererMessageEmitter.dispose();
315
+ this.onDidChangeOutputInputFocusEmitter.dispose();
316
+ this.viewportService.dispose();
317
+ this._model?.dispose();
318
+ super.dispose();
319
+ }
320
+
321
+ protected override onAfterShow(msg: Message): void {
322
+ super.onAfterShow(msg);
323
+ this.notebookEditorService.notebookEditorFocusChanged(this, true);
324
+ }
325
+
326
+ protected override onAfterHide(msg: Message): void {
327
+ super.onAfterHide(msg);
328
+ this.notebookEditorService.notebookEditorFocusChanged(this, false);
329
+ }
330
+ }