@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.
- package/README.md +30 -30
- package/lib/browser/index.d.ts +1 -0
- package/lib/browser/index.d.ts.map +1 -1
- package/lib/browser/index.js +1 -0
- package/lib/browser/index.js.map +1 -1
- package/lib/browser/notebook-frontend-module.d.ts.map +1 -1
- package/lib/browser/notebook-frontend-module.js +2 -0
- package/lib/browser/notebook-frontend-module.js.map +1 -1
- package/lib/browser/service/notebook-cell-editor-service.d.ts +16 -0
- package/lib/browser/service/notebook-cell-editor-service.d.ts.map +1 -0
- package/lib/browser/service/notebook-cell-editor-service.js +53 -0
- package/lib/browser/service/notebook-cell-editor-service.js.map +1 -0
- package/lib/browser/view/notebook-cell-editor.d.ts +2 -0
- package/lib/browser/view/notebook-cell-editor.d.ts.map +1 -1
- package/lib/browser/view/notebook-cell-editor.js +12 -1
- package/lib/browser/view/notebook-cell-editor.js.map +1 -1
- package/lib/browser/view/notebook-code-cell-view.d.ts +2 -0
- package/lib/browser/view/notebook-code-cell-view.d.ts.map +1 -1
- package/lib/browser/view/notebook-code-cell-view.js +6 -1
- package/lib/browser/view/notebook-code-cell-view.js.map +1 -1
- package/lib/browser/view/notebook-markdown-cell-view.d.ts +2 -0
- package/lib/browser/view/notebook-markdown-cell-view.d.ts.map +1 -1
- package/lib/browser/view/notebook-markdown-cell-view.js +8 -3
- package/lib/browser/view/notebook-markdown-cell-view.js.map +1 -1
- package/package.json +7 -7
- package/src/browser/contributions/cell-operations.ts +44 -44
- package/src/browser/contributions/notebook-actions-contribution.ts +379 -379
- package/src/browser/contributions/notebook-cell-actions-contribution.ts +525 -525
- package/src/browser/contributions/notebook-color-contribution.ts +268 -268
- package/src/browser/contributions/notebook-context-keys.ts +113 -113
- package/src/browser/contributions/notebook-label-provider-contribution.ts +85 -85
- package/src/browser/contributions/notebook-outline-contribution.ts +114 -114
- package/src/browser/contributions/notebook-output-action-contribution.ts +82 -82
- package/src/browser/contributions/notebook-preferences.ts +92 -92
- package/src/browser/contributions/notebook-status-bar-contribution.ts +77 -77
- package/src/browser/contributions/notebook-undo-redo-handler.ts +41 -41
- package/src/browser/index.ts +28 -27
- package/src/browser/notebook-cell-resource-resolver.ts +130 -130
- package/src/browser/notebook-editor-widget-factory.ts +82 -82
- package/src/browser/notebook-editor-widget.tsx +330 -330
- package/src/browser/notebook-frontend-module.ts +121 -119
- package/src/browser/notebook-open-handler.ts +120 -120
- package/src/browser/notebook-output-utils.ts +119 -119
- package/src/browser/notebook-renderer-registry.ts +85 -85
- package/src/browser/notebook-type-registry.ts +54 -54
- package/src/browser/notebook-types.ts +186 -186
- package/src/browser/renderers/cell-output-webview.ts +33 -33
- package/src/browser/service/notebook-cell-editor-service.ts +56 -0
- package/src/browser/service/notebook-clipboard-service.ts +43 -43
- package/src/browser/service/notebook-context-manager.ts +162 -162
- package/src/browser/service/notebook-editor-widget-service.ts +101 -101
- package/src/browser/service/notebook-execution-service.ts +139 -139
- package/src/browser/service/notebook-execution-state-service.ts +311 -311
- package/src/browser/service/notebook-kernel-history-service.ts +124 -124
- package/src/browser/service/notebook-kernel-quick-pick-service.ts +479 -479
- package/src/browser/service/notebook-kernel-service.ts +357 -357
- package/src/browser/service/notebook-model-resolver-service.ts +160 -160
- package/src/browser/service/notebook-monaco-text-model-service.ts +48 -48
- package/src/browser/service/notebook-options.ts +155 -155
- package/src/browser/service/notebook-renderer-messaging-service.ts +121 -121
- package/src/browser/service/notebook-service.ts +215 -215
- package/src/browser/style/index.css +484 -483
- package/src/browser/view/notebook-cell-editor.tsx +276 -263
- package/src/browser/view/notebook-cell-list-view.tsx +279 -279
- package/src/browser/view/notebook-cell-toolbar-factory.tsx +102 -102
- package/src/browser/view/notebook-cell-toolbar.tsx +74 -74
- package/src/browser/view/notebook-code-cell-view.tsx +355 -350
- package/src/browser/view/notebook-find-widget.tsx +335 -335
- package/src/browser/view/notebook-main-toolbar.tsx +235 -235
- package/src/browser/view/notebook-markdown-cell-view.tsx +215 -208
- package/src/browser/view/notebook-viewport-service.ts +61 -61
- package/src/browser/view-model/notebook-cell-model.ts +473 -473
- package/src/browser/view-model/notebook-cell-output-model.ts +100 -100
- package/src/browser/view-model/notebook-model.ts +550 -550
- package/src/common/index.ts +18 -18
- package/src/common/notebook-common.ts +337 -337
- package/src/common/notebook-protocol.ts +35 -35
- package/src/common/notebook-range.ts +30 -30
|
@@ -1,350 +1,355 @@
|
|
|
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 { inject, injectable } from '@theia/core/shared/inversify';
|
|
18
|
-
import * as React from '@theia/core/shared/react';
|
|
19
|
-
import { MonacoEditorServices } from '@theia/monaco/lib/browser/monaco-editor';
|
|
20
|
-
import { CellOutputWebviewFactory, CellOutputWebview } from '../renderers/cell-output-webview';
|
|
21
|
-
import { NotebookRendererRegistry } from '../notebook-renderer-registry';
|
|
22
|
-
import { NotebookCellModel } from '../view-model/notebook-cell-model';
|
|
23
|
-
import { NotebookModel } from '../view-model/notebook-model';
|
|
24
|
-
import { CellEditor } from './notebook-cell-editor';
|
|
25
|
-
import { CellRenderer } from './notebook-cell-list-view';
|
|
26
|
-
import { NotebookCellToolbarFactory } from './notebook-cell-toolbar-factory';
|
|
27
|
-
import { NotebookCellActionContribution, NotebookCellCommands } from '../contributions/notebook-cell-actions-contribution';
|
|
28
|
-
import { CellExecution, NotebookExecutionStateService } from '../service/notebook-execution-state-service';
|
|
29
|
-
import { codicon } from '@theia/core/lib/browser';
|
|
30
|
-
import { NotebookCellExecutionState } from '../../common';
|
|
31
|
-
import { CommandRegistry, DisposableCollection, nls } from '@theia/core';
|
|
32
|
-
import { NotebookContextManager } from '../service/notebook-context-manager';
|
|
33
|
-
import { NotebookViewportService } from './notebook-viewport-service';
|
|
34
|
-
import { EditorPreferences } from '@theia/editor/lib/browser';
|
|
35
|
-
import { NotebookOptionsService } from '../service/notebook-options';
|
|
36
|
-
import { MarkdownRenderer } from '@theia/core/lib/browser/markdown-rendering/markdown-renderer';
|
|
37
|
-
import { MarkdownString } from '@theia/monaco-editor-core/esm/vs/base/common/htmlContent';
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
dragImage.
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
fakeEditor.
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
current
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
export
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
</div>
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
} else if (state ===
|
|
230
|
-
iconClasses =
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
this.
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
this.
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
this.
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
this.forceUpdate();
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
override
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
}
|
|
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 { inject, injectable } from '@theia/core/shared/inversify';
|
|
18
|
+
import * as React from '@theia/core/shared/react';
|
|
19
|
+
import { MonacoEditorServices } from '@theia/monaco/lib/browser/monaco-editor';
|
|
20
|
+
import { CellOutputWebviewFactory, CellOutputWebview } from '../renderers/cell-output-webview';
|
|
21
|
+
import { NotebookRendererRegistry } from '../notebook-renderer-registry';
|
|
22
|
+
import { NotebookCellModel } from '../view-model/notebook-cell-model';
|
|
23
|
+
import { NotebookModel } from '../view-model/notebook-model';
|
|
24
|
+
import { CellEditor } from './notebook-cell-editor';
|
|
25
|
+
import { CellRenderer } from './notebook-cell-list-view';
|
|
26
|
+
import { NotebookCellToolbarFactory } from './notebook-cell-toolbar-factory';
|
|
27
|
+
import { NotebookCellActionContribution, NotebookCellCommands } from '../contributions/notebook-cell-actions-contribution';
|
|
28
|
+
import { CellExecution, NotebookExecutionStateService } from '../service/notebook-execution-state-service';
|
|
29
|
+
import { codicon } from '@theia/core/lib/browser';
|
|
30
|
+
import { NotebookCellExecutionState } from '../../common';
|
|
31
|
+
import { CommandRegistry, DisposableCollection, nls } from '@theia/core';
|
|
32
|
+
import { NotebookContextManager } from '../service/notebook-context-manager';
|
|
33
|
+
import { NotebookViewportService } from './notebook-viewport-service';
|
|
34
|
+
import { EditorPreferences } from '@theia/editor/lib/browser';
|
|
35
|
+
import { NotebookOptionsService } from '../service/notebook-options';
|
|
36
|
+
import { MarkdownRenderer } from '@theia/core/lib/browser/markdown-rendering/markdown-renderer';
|
|
37
|
+
import { MarkdownString } from '@theia/monaco-editor-core/esm/vs/base/common/htmlContent';
|
|
38
|
+
import { NotebookCellEditorService } from '../service/notebook-cell-editor-service';
|
|
39
|
+
|
|
40
|
+
@injectable()
|
|
41
|
+
export class NotebookCodeCellRenderer implements CellRenderer {
|
|
42
|
+
@inject(MonacoEditorServices)
|
|
43
|
+
protected readonly monacoServices: MonacoEditorServices;
|
|
44
|
+
|
|
45
|
+
@inject(NotebookRendererRegistry)
|
|
46
|
+
protected readonly notebookRendererRegistry: NotebookRendererRegistry;
|
|
47
|
+
|
|
48
|
+
@inject(CellOutputWebviewFactory)
|
|
49
|
+
protected readonly cellOutputWebviewFactory: CellOutputWebviewFactory;
|
|
50
|
+
|
|
51
|
+
@inject(NotebookCellToolbarFactory)
|
|
52
|
+
protected readonly notebookCellToolbarFactory: NotebookCellToolbarFactory;
|
|
53
|
+
|
|
54
|
+
@inject(NotebookExecutionStateService)
|
|
55
|
+
protected readonly executionStateService: NotebookExecutionStateService;
|
|
56
|
+
|
|
57
|
+
@inject(NotebookContextManager)
|
|
58
|
+
protected readonly notebookContextManager: NotebookContextManager;
|
|
59
|
+
|
|
60
|
+
@inject(NotebookViewportService)
|
|
61
|
+
protected readonly notebookViewportService: NotebookViewportService;
|
|
62
|
+
|
|
63
|
+
@inject(EditorPreferences)
|
|
64
|
+
protected readonly editorPreferences: EditorPreferences;
|
|
65
|
+
|
|
66
|
+
@inject(NotebookCellEditorService)
|
|
67
|
+
protected readonly notebookCellEditorService: NotebookCellEditorService;
|
|
68
|
+
|
|
69
|
+
@inject(CommandRegistry)
|
|
70
|
+
protected readonly commandRegistry: CommandRegistry;
|
|
71
|
+
|
|
72
|
+
@inject(NotebookOptionsService)
|
|
73
|
+
protected readonly notebookOptionsService: NotebookOptionsService;
|
|
74
|
+
|
|
75
|
+
@inject(MarkdownRenderer)
|
|
76
|
+
protected readonly markdownRenderer: MarkdownRenderer;
|
|
77
|
+
|
|
78
|
+
render(notebookModel: NotebookModel, cell: NotebookCellModel, handle: number): React.ReactNode {
|
|
79
|
+
return <div>
|
|
80
|
+
<div className='theia-notebook-cell-with-sidebar'>
|
|
81
|
+
<div className='theia-notebook-cell-sidebar'>
|
|
82
|
+
{this.notebookCellToolbarFactory.renderSidebar(NotebookCellActionContribution.CODE_CELL_SIDEBAR_MENU, cell, {
|
|
83
|
+
contextMenuArgs: () => [cell], commandArgs: () => [notebookModel, cell]
|
|
84
|
+
})
|
|
85
|
+
}
|
|
86
|
+
<CodeCellExecutionOrder cell={cell} />
|
|
87
|
+
</div>
|
|
88
|
+
<div className='theia-notebook-cell-editor-container'>
|
|
89
|
+
<CellEditor notebookModel={notebookModel} cell={cell}
|
|
90
|
+
monacoServices={this.monacoServices}
|
|
91
|
+
notebookContextManager={this.notebookContextManager}
|
|
92
|
+
notebookViewportService={this.notebookViewportService}
|
|
93
|
+
notebookCellEditorService={this.notebookCellEditorService}
|
|
94
|
+
fontInfo={this.notebookOptionsService.editorFontInfo} />
|
|
95
|
+
<NotebookCodeCellStatus cell={cell} notebook={notebookModel}
|
|
96
|
+
commandRegistry={this.commandRegistry}
|
|
97
|
+
executionStateService={this.executionStateService}
|
|
98
|
+
onClick={() => cell.requestFocusEditor()} />
|
|
99
|
+
</div >
|
|
100
|
+
</div >
|
|
101
|
+
<div className='theia-notebook-cell-with-sidebar'>
|
|
102
|
+
<NotebookCodeCellOutputs cell={cell} notebook={notebookModel} outputWebviewFactory={this.cellOutputWebviewFactory}
|
|
103
|
+
renderSidebar={() =>
|
|
104
|
+
this.notebookCellToolbarFactory.renderSidebar(NotebookCellActionContribution.OUTPUT_SIDEBAR_MENU, cell, {
|
|
105
|
+
contextMenuArgs: () => [notebookModel, cell, cell.outputs[0]]
|
|
106
|
+
})
|
|
107
|
+
} />
|
|
108
|
+
</div>
|
|
109
|
+
</div >;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
renderDragImage(cell: NotebookCellModel): HTMLElement {
|
|
113
|
+
const dragImage = document.createElement('div');
|
|
114
|
+
dragImage.className = 'theia-notebook-drag-image';
|
|
115
|
+
dragImage.style.width = this.notebookContextManager.context?.clientWidth + 'px';
|
|
116
|
+
dragImage.style.height = '100px';
|
|
117
|
+
dragImage.style.display = 'flex';
|
|
118
|
+
|
|
119
|
+
const fakeRunButton = document.createElement('span');
|
|
120
|
+
fakeRunButton.className = `${codicon('play')} theia-notebook-cell-status-item`;
|
|
121
|
+
dragImage.appendChild(fakeRunButton);
|
|
122
|
+
|
|
123
|
+
const fakeEditor = document.createElement('div');
|
|
124
|
+
dragImage.appendChild(fakeEditor);
|
|
125
|
+
const lines = cell.source.split('\n').slice(0, 5).join('\n');
|
|
126
|
+
const codeSequence = this.getMarkdownCodeSequence(lines);
|
|
127
|
+
const firstLine = new MarkdownString(`${codeSequence}${cell.language}\n${lines}\n${codeSequence}`, { supportHtml: true, isTrusted: false });
|
|
128
|
+
fakeEditor.appendChild(this.markdownRenderer.render(firstLine).element);
|
|
129
|
+
fakeEditor.classList.add('theia-notebook-cell-editor-container');
|
|
130
|
+
fakeEditor.style.padding = '10px';
|
|
131
|
+
return dragImage;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
protected getMarkdownCodeSequence(input: string): string {
|
|
135
|
+
// We need a minimum of 3 backticks to start a code block.
|
|
136
|
+
let longest = 2;
|
|
137
|
+
let current = 0;
|
|
138
|
+
for (let i = 0; i < input.length; i++) {
|
|
139
|
+
const char = input.charAt(i);
|
|
140
|
+
if (char === '`') {
|
|
141
|
+
current++;
|
|
142
|
+
if (current > longest) {
|
|
143
|
+
longest = current;
|
|
144
|
+
}
|
|
145
|
+
} else {
|
|
146
|
+
current = 0;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
return Array(longest + 1).fill('`').join('');
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
export interface NotebookCodeCellStatusProps {
|
|
155
|
+
notebook: NotebookModel;
|
|
156
|
+
cell: NotebookCellModel;
|
|
157
|
+
commandRegistry: CommandRegistry;
|
|
158
|
+
executionStateService?: NotebookExecutionStateService;
|
|
159
|
+
onClick: () => void;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
export interface NotebookCodeCellStatusState {
|
|
163
|
+
currentExecution?: CellExecution;
|
|
164
|
+
executionTime: number;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
export class NotebookCodeCellStatus extends React.Component<NotebookCodeCellStatusProps, NotebookCodeCellStatusState> {
|
|
168
|
+
|
|
169
|
+
protected toDispose = new DisposableCollection();
|
|
170
|
+
|
|
171
|
+
constructor(props: NotebookCodeCellStatusProps) {
|
|
172
|
+
super(props);
|
|
173
|
+
|
|
174
|
+
this.state = {
|
|
175
|
+
executionTime: 0
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
let currentInterval: NodeJS.Timeout | undefined;
|
|
179
|
+
if (props.executionStateService) {
|
|
180
|
+
this.toDispose.push(props.executionStateService.onDidChangeExecution(event => {
|
|
181
|
+
if (event.affectsCell(this.props.cell.uri)) {
|
|
182
|
+
this.setState({ currentExecution: event.changed, executionTime: 0 });
|
|
183
|
+
clearInterval(currentInterval);
|
|
184
|
+
if (event.changed?.state === NotebookCellExecutionState.Executing) {
|
|
185
|
+
const startTime = Date.now();
|
|
186
|
+
// The resolution of the time display is only a single digit after the decimal point.
|
|
187
|
+
// Therefore, we only need to update the display every 100ms.
|
|
188
|
+
currentInterval = setInterval(() => {
|
|
189
|
+
this.setState({
|
|
190
|
+
executionTime: Date.now() - startTime
|
|
191
|
+
});
|
|
192
|
+
}, 100);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}));
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
this.toDispose.push(props.cell.onDidChangeLanguage(() => {
|
|
199
|
+
this.forceUpdate();
|
|
200
|
+
}));
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
override componentWillUnmount(): void {
|
|
204
|
+
this.toDispose.dispose();
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
override render(): React.ReactNode {
|
|
208
|
+
return <div className='notebook-cell-status' onClick={() => this.props.onClick()}>
|
|
209
|
+
<div className='notebook-cell-status-left'>
|
|
210
|
+
{this.props.executionStateService && this.renderExecutionState()}
|
|
211
|
+
</div>
|
|
212
|
+
<div className='notebook-cell-status-right'>
|
|
213
|
+
<span className='notebook-cell-language-label' onClick={() => {
|
|
214
|
+
this.props.commandRegistry.executeCommand(NotebookCellCommands.CHANGE_CELL_LANGUAGE.id, this.props.notebook, this.props.cell);
|
|
215
|
+
}}>{this.props.cell.languageName}</span>
|
|
216
|
+
</div>
|
|
217
|
+
</div>;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
private renderExecutionState(): React.ReactNode {
|
|
221
|
+
const state = this.state.currentExecution?.state;
|
|
222
|
+
const { lastRunSuccess } = this.props.cell.internalMetadata;
|
|
223
|
+
|
|
224
|
+
let iconClasses: string | undefined = undefined;
|
|
225
|
+
let color: string | undefined = undefined;
|
|
226
|
+
if (!state && lastRunSuccess) {
|
|
227
|
+
iconClasses = codicon('check');
|
|
228
|
+
color = 'green';
|
|
229
|
+
} else if (!state && lastRunSuccess === false) {
|
|
230
|
+
iconClasses = codicon('error');
|
|
231
|
+
color = 'red';
|
|
232
|
+
} else if (state === NotebookCellExecutionState.Pending || state === NotebookCellExecutionState.Unconfirmed) {
|
|
233
|
+
iconClasses = codicon('clock');
|
|
234
|
+
} else if (state === NotebookCellExecutionState.Executing) {
|
|
235
|
+
iconClasses = `${codicon('sync')} theia-animation-spin`;
|
|
236
|
+
}
|
|
237
|
+
return <>
|
|
238
|
+
{iconClasses &&
|
|
239
|
+
<>
|
|
240
|
+
<span className={`${iconClasses} notebook-cell-status-item`} style={{ color }}></span>
|
|
241
|
+
<div className='notebook-cell-status-item'>{this.renderTime(this.getExecutionTime())}</div>
|
|
242
|
+
</>}
|
|
243
|
+
</>;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
private getExecutionTime(): number {
|
|
247
|
+
const { runStartTime, runEndTime } = this.props.cell.internalMetadata;
|
|
248
|
+
const { executionTime } = this.state;
|
|
249
|
+
if (runStartTime !== undefined && runEndTime !== undefined) {
|
|
250
|
+
return runEndTime - runStartTime;
|
|
251
|
+
}
|
|
252
|
+
return executionTime;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
private renderTime(ms: number): string {
|
|
256
|
+
return `${(ms / 1000).toLocaleString(undefined, { maximumFractionDigits: 1, minimumFractionDigits: 1 })}s`;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
interface NotebookCellOutputProps {
|
|
261
|
+
cell: NotebookCellModel;
|
|
262
|
+
notebook: NotebookModel;
|
|
263
|
+
outputWebviewFactory: CellOutputWebviewFactory;
|
|
264
|
+
renderSidebar: () => React.ReactNode;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
export class NotebookCodeCellOutputs extends React.Component<NotebookCellOutputProps> {
|
|
268
|
+
|
|
269
|
+
protected outputsWebview: CellOutputWebview | undefined;
|
|
270
|
+
protected outputsWebviewPromise: Promise<CellOutputWebview> | undefined;
|
|
271
|
+
|
|
272
|
+
protected toDispose = new DisposableCollection();
|
|
273
|
+
|
|
274
|
+
constructor(props: NotebookCellOutputProps) {
|
|
275
|
+
super(props);
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
override async componentDidMount(): Promise<void> {
|
|
279
|
+
const { cell, notebook, outputWebviewFactory } = this.props;
|
|
280
|
+
this.toDispose.push(cell.onDidChangeOutputs(() => this.updateOutputs()));
|
|
281
|
+
this.toDispose.push(cell.onDidChangeOutputVisibility(visible => {
|
|
282
|
+
if (!visible && this.outputsWebview) {
|
|
283
|
+
this.outputsWebview?.dispose();
|
|
284
|
+
this.outputsWebview = undefined;
|
|
285
|
+
this.outputsWebviewPromise = undefined;
|
|
286
|
+
this.forceUpdate();
|
|
287
|
+
} else {
|
|
288
|
+
this.updateOutputs();
|
|
289
|
+
}
|
|
290
|
+
}));
|
|
291
|
+
if (cell.outputs.length > 0) {
|
|
292
|
+
this.outputsWebviewPromise = outputWebviewFactory(cell, notebook).then(webview => {
|
|
293
|
+
this.outputsWebview = webview;
|
|
294
|
+
this.forceUpdate();
|
|
295
|
+
return webview;
|
|
296
|
+
});
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
protected async updateOutputs(): Promise<void> {
|
|
301
|
+
const { cell, notebook, outputWebviewFactory } = this.props;
|
|
302
|
+
if (!this.outputsWebviewPromise && cell.outputs.length > 0) {
|
|
303
|
+
this.outputsWebviewPromise = outputWebviewFactory(cell, notebook).then(webview => {
|
|
304
|
+
this.outputsWebview = webview;
|
|
305
|
+
this.forceUpdate();
|
|
306
|
+
return webview;
|
|
307
|
+
});
|
|
308
|
+
this.forceUpdate();
|
|
309
|
+
} else if (this.outputsWebviewPromise && cell.outputs.length === 0 && cell.internalMetadata.runEndTime) {
|
|
310
|
+
(await this.outputsWebviewPromise).dispose();
|
|
311
|
+
this.outputsWebview = undefined;
|
|
312
|
+
this.outputsWebviewPromise = undefined;
|
|
313
|
+
this.forceUpdate();
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
override async componentDidUpdate(): Promise<void> {
|
|
318
|
+
if (!(await this.outputsWebviewPromise)?.isAttached()) {
|
|
319
|
+
(await this.outputsWebviewPromise)?.attachWebview();
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
override async componentWillUnmount(): Promise<void> {
|
|
324
|
+
this.toDispose.dispose();
|
|
325
|
+
(await this.outputsWebviewPromise)?.dispose();
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
override render(): React.ReactNode {
|
|
329
|
+
return this.outputsWebview && this.props.cell.outputVisible ?
|
|
330
|
+
<>
|
|
331
|
+
{this.props.renderSidebar()}
|
|
332
|
+
{this.outputsWebview.render()}
|
|
333
|
+
</> :
|
|
334
|
+
this.props.cell.outputs?.length ? <i className='theia-notebook-collapsed-output'>{nls.localizeByDefault('Outputs are collapsed')}</i> : <></>;
|
|
335
|
+
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
interface NotebookCellExecutionOrderProps {
|
|
341
|
+
cell: NotebookCellModel;
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
function CodeCellExecutionOrder({ cell }: NotebookCellExecutionOrderProps): React.JSX.Element {
|
|
345
|
+
const [executionOrder, setExecutionOrder] = React.useState(cell.internalMetadata.executionOrder ?? ' ');
|
|
346
|
+
|
|
347
|
+
React.useEffect(() => {
|
|
348
|
+
const listener = cell.onDidChangeInternalMetadata(e => {
|
|
349
|
+
setExecutionOrder(cell.internalMetadata.executionOrder ?? ' ');
|
|
350
|
+
});
|
|
351
|
+
return () => listener.dispose();
|
|
352
|
+
}, []);
|
|
353
|
+
|
|
354
|
+
return <span className='theia-notebook-code-cell-execution-order'>{`[${executionOrder}]`}</span>;
|
|
355
|
+
}
|