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

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 (99) hide show
  1. package/README.md +30 -30
  2. package/lib/browser/contributions/cell-operations.d.ts.map +1 -1
  3. package/lib/browser/contributions/cell-operations.js +8 -1
  4. package/lib/browser/contributions/cell-operations.js.map +1 -1
  5. package/lib/browser/contributions/notebook-actions-contribution.d.ts +1 -0
  6. package/lib/browser/contributions/notebook-actions-contribution.d.ts.map +1 -1
  7. package/lib/browser/contributions/notebook-actions-contribution.js +31 -6
  8. package/lib/browser/contributions/notebook-actions-contribution.js.map +1 -1
  9. package/lib/browser/contributions/notebook-cell-actions-contribution.d.ts +4 -0
  10. package/lib/browser/contributions/notebook-cell-actions-contribution.d.ts.map +1 -1
  11. package/lib/browser/contributions/notebook-cell-actions-contribution.js +49 -12
  12. package/lib/browser/contributions/notebook-cell-actions-contribution.js.map +1 -1
  13. package/lib/browser/contributions/notebook-status-bar-contribution.d.ts +14 -0
  14. package/lib/browser/contributions/notebook-status-bar-contribution.d.ts.map +1 -0
  15. package/lib/browser/contributions/notebook-status-bar-contribution.js +75 -0
  16. package/lib/browser/contributions/notebook-status-bar-contribution.js.map +1 -0
  17. package/lib/browser/notebook-editor-widget.d.ts.map +1 -1
  18. package/lib/browser/notebook-editor-widget.js +3 -5
  19. package/lib/browser/notebook-editor-widget.js.map +1 -1
  20. package/lib/browser/notebook-frontend-module.d.ts.map +1 -1
  21. package/lib/browser/notebook-frontend-module.js +3 -0
  22. package/lib/browser/notebook-frontend-module.js.map +1 -1
  23. package/lib/browser/notebook-open-handler.d.ts +3 -2
  24. package/lib/browser/notebook-open-handler.d.ts.map +1 -1
  25. package/lib/browser/notebook-open-handler.js +12 -5
  26. package/lib/browser/notebook-open-handler.js.map +1 -1
  27. package/lib/browser/service/notebook-options.d.ts +1 -0
  28. package/lib/browser/service/notebook-options.d.ts.map +1 -1
  29. package/lib/browser/service/notebook-options.js +1 -0
  30. package/lib/browser/service/notebook-options.js.map +1 -1
  31. package/lib/browser/service/notebook-service.d.ts +1 -0
  32. package/lib/browser/service/notebook-service.d.ts.map +1 -1
  33. package/lib/browser/service/notebook-service.js +7 -0
  34. package/lib/browser/service/notebook-service.js.map +1 -1
  35. package/lib/browser/view/notebook-cell-editor.d.ts +1 -0
  36. package/lib/browser/view/notebook-cell-editor.d.ts.map +1 -1
  37. package/lib/browser/view/notebook-cell-editor.js +30 -16
  38. package/lib/browser/view/notebook-cell-editor.js.map +1 -1
  39. package/lib/browser/view/notebook-cell-list-view.d.ts +7 -4
  40. package/lib/browser/view/notebook-cell-list-view.d.ts.map +1 -1
  41. package/lib/browser/view/notebook-cell-list-view.js +39 -29
  42. package/lib/browser/view/notebook-cell-list-view.js.map +1 -1
  43. package/lib/browser/view-model/notebook-cell-model.d.ts +3 -0
  44. package/lib/browser/view-model/notebook-cell-model.d.ts.map +1 -1
  45. package/lib/browser/view-model/notebook-cell-model.js +5 -0
  46. package/lib/browser/view-model/notebook-cell-model.js.map +1 -1
  47. package/package.json +8 -8
  48. package/src/browser/contributions/cell-operations.ts +44 -39
  49. package/src/browser/contributions/notebook-actions-contribution.ts +379 -351
  50. package/src/browser/contributions/notebook-cell-actions-contribution.ts +525 -485
  51. package/src/browser/contributions/notebook-color-contribution.ts +268 -268
  52. package/src/browser/contributions/notebook-context-keys.ts +113 -113
  53. package/src/browser/contributions/notebook-label-provider-contribution.ts +85 -85
  54. package/src/browser/contributions/notebook-outline-contribution.ts +114 -114
  55. package/src/browser/contributions/notebook-output-action-contribution.ts +82 -82
  56. package/src/browser/contributions/notebook-preferences.ts +92 -92
  57. package/src/browser/contributions/notebook-status-bar-contribution.ts +77 -0
  58. package/src/browser/contributions/notebook-undo-redo-handler.ts +41 -41
  59. package/src/browser/index.ts +27 -27
  60. package/src/browser/notebook-cell-resource-resolver.ts +130 -130
  61. package/src/browser/notebook-editor-widget-factory.ts +82 -82
  62. package/src/browser/notebook-editor-widget.tsx +330 -331
  63. package/src/browser/notebook-frontend-module.ts +119 -115
  64. package/src/browser/notebook-open-handler.ts +120 -114
  65. package/src/browser/notebook-output-utils.ts +119 -119
  66. package/src/browser/notebook-renderer-registry.ts +85 -85
  67. package/src/browser/notebook-type-registry.ts +54 -54
  68. package/src/browser/notebook-types.ts +186 -186
  69. package/src/browser/renderers/cell-output-webview.ts +33 -33
  70. package/src/browser/service/notebook-clipboard-service.ts +43 -43
  71. package/src/browser/service/notebook-context-manager.ts +162 -162
  72. package/src/browser/service/notebook-editor-widget-service.ts +101 -101
  73. package/src/browser/service/notebook-execution-service.ts +139 -139
  74. package/src/browser/service/notebook-execution-state-service.ts +311 -311
  75. package/src/browser/service/notebook-kernel-history-service.ts +124 -124
  76. package/src/browser/service/notebook-kernel-quick-pick-service.ts +479 -479
  77. package/src/browser/service/notebook-kernel-service.ts +357 -357
  78. package/src/browser/service/notebook-model-resolver-service.ts +160 -160
  79. package/src/browser/service/notebook-monaco-text-model-service.ts +48 -48
  80. package/src/browser/service/notebook-options.ts +155 -154
  81. package/src/browser/service/notebook-renderer-messaging-service.ts +121 -121
  82. package/src/browser/service/notebook-service.ts +215 -209
  83. package/src/browser/style/index.css +483 -467
  84. package/src/browser/view/notebook-cell-editor.tsx +263 -247
  85. package/src/browser/view/notebook-cell-list-view.tsx +279 -259
  86. package/src/browser/view/notebook-cell-toolbar-factory.tsx +102 -102
  87. package/src/browser/view/notebook-cell-toolbar.tsx +74 -74
  88. package/src/browser/view/notebook-code-cell-view.tsx +350 -350
  89. package/src/browser/view/notebook-find-widget.tsx +335 -335
  90. package/src/browser/view/notebook-main-toolbar.tsx +235 -235
  91. package/src/browser/view/notebook-markdown-cell-view.tsx +208 -208
  92. package/src/browser/view/notebook-viewport-service.ts +61 -61
  93. package/src/browser/view-model/notebook-cell-model.ts +473 -466
  94. package/src/browser/view-model/notebook-cell-output-model.ts +100 -100
  95. package/src/browser/view-model/notebook-model.ts +550 -550
  96. package/src/common/index.ts +18 -18
  97. package/src/common/notebook-common.ts +337 -337
  98. package/src/common/notebook-protocol.ts +35 -35
  99. package/src/common/notebook-range.ts +30 -30
@@ -1,337 +1,337 @@
1
- // *****************************************************************************
2
- // Copyright (C) 2023 TypeFox and others.
3
- //
4
- // This program and the accompanying materials are made available under the
5
- // terms of the Eclipse Public License v. 2.0 which is available at
6
- // http://www.eclipse.org/legal/epl-2.0.
7
- //
8
- // This Source Code may also be made available under the following Secondary
9
- // Licenses when the conditions for such availability set forth in the Eclipse
10
- // Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
- // with the GNU Classpath Exception which is available at
12
- // https://www.gnu.org/software/classpath/license.html.
13
- //
14
- // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
- // *****************************************************************************
16
-
17
- import { Command, URI, isObject } from '@theia/core';
18
- import { MarkdownString } from '@theia/core/lib/common/markdown-rendering/markdown-string';
19
- import { BinaryBuffer } from '@theia/core/lib/common/buffer';
20
- import { UriComponents } from '@theia/core/lib/common/uri';
21
-
22
- export interface NotebookCommand extends Command {
23
- title?: string;
24
- tooltip?: string;
25
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
26
- arguments?: any[];
27
- }
28
-
29
- export enum CellKind {
30
- Markup = 1,
31
- Code = 2
32
- }
33
-
34
- export interface NotebookCellMetadata {
35
- /**
36
- * custom metadata
37
- */
38
- [key: string]: unknown;
39
- }
40
-
41
- export interface NotebookCellInternalMetadata {
42
- executionId?: string;
43
- executionOrder?: number;
44
- lastRunSuccess?: boolean;
45
- runStartTime?: number;
46
- runStartTimeAdjustment?: number;
47
- runEndTime?: number;
48
- renderDuration?: { [key: string]: number };
49
- }
50
-
51
- export type NotebookDocumentMetadata = Record<string, unknown>;
52
-
53
- export interface NotebookCellStatusBarItem {
54
- readonly alignment: CellStatusbarAlignment;
55
- readonly priority?: number;
56
- readonly text: string;
57
- // readonly color?: string | ThemeColor;
58
- // readonly backgroundColor?: string | ThemeColor;
59
- readonly tooltip?: string | MarkdownString;
60
- readonly command?: string | Command;
61
- // readonly accessibilityInformation?: IAccessibilityInformation;
62
- readonly opacity?: string;
63
- readonly onlyShowWhenActive?: boolean;
64
- }
65
-
66
- export const enum CellStatusbarAlignment {
67
- Left = 1,
68
- Right = 2
69
- }
70
-
71
- export type TransientCellMetadata = { readonly [K in keyof NotebookCellMetadata]?: boolean };
72
- export type CellContentMetadata = { readonly [K in keyof NotebookCellMetadata]?: boolean };
73
- export type TransientDocumentMetadata = { readonly [K in keyof NotebookDocumentMetadata]?: boolean };
74
-
75
- export interface TransientOptions {
76
- readonly transientOutputs: boolean;
77
- readonly transientCellMetadata: TransientCellMetadata;
78
- readonly transientDocumentMetadata: TransientDocumentMetadata;
79
- }
80
-
81
- export interface CellOutputItem {
82
- readonly mime: string;
83
- readonly data: BinaryBuffer;
84
- }
85
-
86
- export interface CellOutput {
87
- outputId: string;
88
- outputs: CellOutputItem[];
89
- metadata?: Record<string, unknown>;
90
- }
91
-
92
- export interface NotebookCellCollapseState {
93
- inputCollapsed?: boolean;
94
- outputCollapsed?: boolean;
95
- }
96
-
97
- export interface CellData {
98
- source: string;
99
- language: string;
100
- cellKind: CellKind;
101
- outputs: CellOutput[];
102
- metadata?: NotebookCellMetadata;
103
- internalMetadata?: NotebookCellInternalMetadata;
104
- collapseState?: NotebookCellCollapseState;
105
- }
106
-
107
- export interface NotebookDocumentMetadataEdit {
108
- editType: CellEditType.DocumentMetadata;
109
- metadata: NotebookDocumentMetadata;
110
- }
111
-
112
- export interface NotebookData {
113
- readonly cells: CellData[];
114
- readonly metadata: NotebookDocumentMetadata;
115
- }
116
-
117
- export interface NotebookContributionData {
118
- extension?: string;
119
- providerDisplayName: string;
120
- displayName: string;
121
- filenamePattern: (string)[];
122
- exclusive: boolean;
123
- }
124
-
125
- export interface NotebookCellTextModelSplice<T> {
126
- start: number,
127
- deleteCount: number,
128
- newItems: T[]
129
- };
130
-
131
- export enum NotebookCellsChangeType {
132
- ModelChange = 1,
133
- Move = 2,
134
- ChangeCellLanguage = 5,
135
- Initialize = 6,
136
- ChangeCellMetadata = 7,
137
- Output = 8,
138
- OutputItem = 9,
139
- ChangeCellContent = 10,
140
- ChangeDocumentMetadata = 11,
141
- ChangeCellInternalMetadata = 12,
142
- // ChangeCellMime = 13,
143
- Unknown = 100
144
- }
145
-
146
- export interface NotebookCellsChangeLanguageEvent {
147
- readonly kind: NotebookCellsChangeType.ChangeCellLanguage;
148
- readonly index: number;
149
- readonly language: string;
150
- }
151
-
152
- export interface NotebookCellsChangeMetadataEvent {
153
- readonly kind: NotebookCellsChangeType.ChangeCellMetadata;
154
- readonly index: number;
155
- readonly metadata: NotebookCellMetadata;
156
- }
157
-
158
- export interface NotebookCellsChangeInternalMetadataEvent {
159
- readonly kind: NotebookCellsChangeType.ChangeCellInternalMetadata;
160
- readonly index: number;
161
- readonly internalMetadata: NotebookCellInternalMetadata;
162
- }
163
-
164
- export interface NotebookCellContentChangeEvent {
165
- readonly kind: NotebookCellsChangeType.ChangeCellContent;
166
- readonly index: number;
167
- }
168
-
169
- export interface NotebookModelResource {
170
- notebookModelUri: URI;
171
- }
172
-
173
- export namespace NotebookModelResource {
174
- export function is(item: unknown): item is NotebookModelResource {
175
- return isObject<NotebookModelResource>(item) && item.notebookModelUri instanceof URI;
176
- }
177
- export function create(uri: URI): NotebookModelResource {
178
- return { notebookModelUri: uri };
179
- }
180
- }
181
-
182
- export interface NotebookCellModelResource {
183
- notebookCellModelUri: URI;
184
- }
185
-
186
- export namespace NotebookCellModelResource {
187
- export function is(item: unknown): item is NotebookCellModelResource {
188
- return isObject<NotebookCellModelResource>(item) && item.notebookCellModelUri instanceof URI;
189
- }
190
- export function create(uri: URI): NotebookCellModelResource {
191
- return { notebookCellModelUri: uri };
192
- }
193
- }
194
-
195
- export enum NotebookCellExecutionState {
196
- Unconfirmed = 1,
197
- Pending = 2,
198
- Executing = 3
199
- }
200
-
201
- export enum CellExecutionUpdateType {
202
- Output = 1,
203
- OutputItems = 2,
204
- ExecutionState = 3,
205
- }
206
-
207
- export interface CellExecuteOutputEdit {
208
- editType: CellExecutionUpdateType.Output;
209
- cellHandle: number;
210
- append?: boolean;
211
- outputs: CellOutput[];
212
- }
213
-
214
- export interface CellExecuteOutputItemEdit {
215
- editType: CellExecutionUpdateType.OutputItems;
216
- append?: boolean;
217
- outputId: string,
218
- items: CellOutputItem[];
219
- }
220
-
221
- export interface CellExecutionStateUpdateDto {
222
- editType: CellExecutionUpdateType.ExecutionState;
223
- executionOrder?: number;
224
- runStartTime?: number;
225
- didPause?: boolean;
226
- isPaused?: boolean;
227
- }
228
-
229
- export interface CellMetadataEdit {
230
- editType: CellEditType.Metadata;
231
- index: number;
232
- metadata: NotebookCellMetadata;
233
- }
234
-
235
- export const enum CellEditType {
236
- Replace = 1,
237
- Output = 2,
238
- Metadata = 3,
239
- CellLanguage = 4,
240
- DocumentMetadata = 5,
241
- Move = 6,
242
- OutputItems = 7,
243
- PartialMetadata = 8,
244
- PartialInternalMetadata = 9,
245
- }
246
-
247
- export interface NotebookKernelSourceAction {
248
- readonly label: string;
249
- readonly description?: string;
250
- readonly detail?: string;
251
- readonly command?: string | Command;
252
- readonly documentation?: UriComponents | string;
253
- }
254
-
255
- /**
256
- * Whether the provided mime type is a text stream like `stdout`, `stderr`.
257
- */
258
- export function isTextStreamMime(mimeType: string): boolean {
259
- return ['application/vnd.code.notebook.stdout', 'application/vnd.code.notebook.stderr'].includes(mimeType);
260
- }
261
-
262
- export namespace CellUri {
263
-
264
- export const cellUriScheme = 'vscode-notebook-cell';
265
- export const outputUriScheme = 'vscode-notebook-cell-output';
266
-
267
- const _lengths = ['W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f'];
268
- const _padRegexp = new RegExp(`^[${_lengths.join('')}]+`);
269
- const _radix = 7;
270
-
271
- export function generate(notebook: URI, handle: number): URI {
272
-
273
- const s = handle.toString(_radix);
274
- const p = s.length < _lengths.length ? _lengths[s.length - 1] : 'z';
275
-
276
- const fragment = `${p}${s}s${Buffer.from(BinaryBuffer.fromString(notebook.scheme).buffer).toString('base64')}`;
277
- return notebook.withScheme(cellUriScheme).withFragment(fragment);
278
- }
279
-
280
- export function parse(cell: URI): { notebook: URI; handle: number } | undefined {
281
- if (cell.scheme !== cellUriScheme) {
282
- return undefined;
283
- }
284
-
285
- const idx = cell.fragment.indexOf('s');
286
- if (idx < 0) {
287
- return undefined;
288
- }
289
-
290
- const handle = parseInt(cell.fragment.substring(0, idx).replace(_padRegexp, ''), _radix);
291
- const parsedScheme = Buffer.from(cell.fragment.substring(idx + 1), 'base64').toString();
292
-
293
- if (isNaN(handle)) {
294
- return undefined;
295
- }
296
- return {
297
- handle,
298
- notebook: cell.withScheme(parsedScheme).withoutFragment()
299
- };
300
- }
301
-
302
- export function generateCellOutputUri(notebook: URI, outputId?: string): URI {
303
- return notebook
304
- .withScheme(outputUriScheme)
305
- .withQuery(`op${outputId ?? ''},${notebook.scheme !== 'file' ? notebook.scheme : ''}`);
306
- };
307
-
308
- export function parseCellOutputUri(uri: URI): { notebook: URI; outputId?: string } | undefined {
309
- if (uri.scheme !== outputUriScheme) {
310
- return;
311
- }
312
-
313
- const match = /^op([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})?\,(.*)$/i.exec(uri.query);
314
- if (!match) {
315
- return undefined;
316
- }
317
-
318
- const outputId = match[1] || undefined;
319
- const scheme = match[2];
320
- return {
321
- outputId,
322
- notebook: uri.withScheme(scheme || 'file').withoutQuery()
323
- };
324
- }
325
-
326
- export function generateCellPropertyUri(notebook: URI, handle: number, cellScheme: string): URI {
327
- return CellUri.generate(notebook, handle).withScheme(cellScheme);
328
- }
329
-
330
- export function parseCellPropertyUri(uri: URI, propertyScheme: string): { notebook: URI; handle: number } | undefined {
331
- if (uri.scheme !== propertyScheme) {
332
- return undefined;
333
- }
334
-
335
- return CellUri.parse(uri.withScheme(cellUriScheme));
336
- }
337
- }
1
+ // *****************************************************************************
2
+ // Copyright (C) 2023 TypeFox and others.
3
+ //
4
+ // This program and the accompanying materials are made available under the
5
+ // terms of the Eclipse Public License v. 2.0 which is available at
6
+ // http://www.eclipse.org/legal/epl-2.0.
7
+ //
8
+ // This Source Code may also be made available under the following Secondary
9
+ // Licenses when the conditions for such availability set forth in the Eclipse
10
+ // Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
+ // with the GNU Classpath Exception which is available at
12
+ // https://www.gnu.org/software/classpath/license.html.
13
+ //
14
+ // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
+ // *****************************************************************************
16
+
17
+ import { Command, URI, isObject } from '@theia/core';
18
+ import { MarkdownString } from '@theia/core/lib/common/markdown-rendering/markdown-string';
19
+ import { BinaryBuffer } from '@theia/core/lib/common/buffer';
20
+ import { UriComponents } from '@theia/core/lib/common/uri';
21
+
22
+ export interface NotebookCommand extends Command {
23
+ title?: string;
24
+ tooltip?: string;
25
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
26
+ arguments?: any[];
27
+ }
28
+
29
+ export enum CellKind {
30
+ Markup = 1,
31
+ Code = 2
32
+ }
33
+
34
+ export interface NotebookCellMetadata {
35
+ /**
36
+ * custom metadata
37
+ */
38
+ [key: string]: unknown;
39
+ }
40
+
41
+ export interface NotebookCellInternalMetadata {
42
+ executionId?: string;
43
+ executionOrder?: number;
44
+ lastRunSuccess?: boolean;
45
+ runStartTime?: number;
46
+ runStartTimeAdjustment?: number;
47
+ runEndTime?: number;
48
+ renderDuration?: { [key: string]: number };
49
+ }
50
+
51
+ export type NotebookDocumentMetadata = Record<string, unknown>;
52
+
53
+ export interface NotebookCellStatusBarItem {
54
+ readonly alignment: CellStatusbarAlignment;
55
+ readonly priority?: number;
56
+ readonly text: string;
57
+ // readonly color?: string | ThemeColor;
58
+ // readonly backgroundColor?: string | ThemeColor;
59
+ readonly tooltip?: string | MarkdownString;
60
+ readonly command?: string | Command;
61
+ // readonly accessibilityInformation?: IAccessibilityInformation;
62
+ readonly opacity?: string;
63
+ readonly onlyShowWhenActive?: boolean;
64
+ }
65
+
66
+ export const enum CellStatusbarAlignment {
67
+ Left = 1,
68
+ Right = 2
69
+ }
70
+
71
+ export type TransientCellMetadata = { readonly [K in keyof NotebookCellMetadata]?: boolean };
72
+ export type CellContentMetadata = { readonly [K in keyof NotebookCellMetadata]?: boolean };
73
+ export type TransientDocumentMetadata = { readonly [K in keyof NotebookDocumentMetadata]?: boolean };
74
+
75
+ export interface TransientOptions {
76
+ readonly transientOutputs: boolean;
77
+ readonly transientCellMetadata: TransientCellMetadata;
78
+ readonly transientDocumentMetadata: TransientDocumentMetadata;
79
+ }
80
+
81
+ export interface CellOutputItem {
82
+ readonly mime: string;
83
+ readonly data: BinaryBuffer;
84
+ }
85
+
86
+ export interface CellOutput {
87
+ outputId: string;
88
+ outputs: CellOutputItem[];
89
+ metadata?: Record<string, unknown>;
90
+ }
91
+
92
+ export interface NotebookCellCollapseState {
93
+ inputCollapsed?: boolean;
94
+ outputCollapsed?: boolean;
95
+ }
96
+
97
+ export interface CellData {
98
+ source: string;
99
+ language: string;
100
+ cellKind: CellKind;
101
+ outputs: CellOutput[];
102
+ metadata?: NotebookCellMetadata;
103
+ internalMetadata?: NotebookCellInternalMetadata;
104
+ collapseState?: NotebookCellCollapseState;
105
+ }
106
+
107
+ export interface NotebookDocumentMetadataEdit {
108
+ editType: CellEditType.DocumentMetadata;
109
+ metadata: NotebookDocumentMetadata;
110
+ }
111
+
112
+ export interface NotebookData {
113
+ readonly cells: CellData[];
114
+ readonly metadata: NotebookDocumentMetadata;
115
+ }
116
+
117
+ export interface NotebookContributionData {
118
+ extension?: string;
119
+ providerDisplayName: string;
120
+ displayName: string;
121
+ filenamePattern: (string)[];
122
+ exclusive: boolean;
123
+ }
124
+
125
+ export interface NotebookCellTextModelSplice<T> {
126
+ start: number,
127
+ deleteCount: number,
128
+ newItems: T[]
129
+ };
130
+
131
+ export enum NotebookCellsChangeType {
132
+ ModelChange = 1,
133
+ Move = 2,
134
+ ChangeCellLanguage = 5,
135
+ Initialize = 6,
136
+ ChangeCellMetadata = 7,
137
+ Output = 8,
138
+ OutputItem = 9,
139
+ ChangeCellContent = 10,
140
+ ChangeDocumentMetadata = 11,
141
+ ChangeCellInternalMetadata = 12,
142
+ // ChangeCellMime = 13,
143
+ Unknown = 100
144
+ }
145
+
146
+ export interface NotebookCellsChangeLanguageEvent {
147
+ readonly kind: NotebookCellsChangeType.ChangeCellLanguage;
148
+ readonly index: number;
149
+ readonly language: string;
150
+ }
151
+
152
+ export interface NotebookCellsChangeMetadataEvent {
153
+ readonly kind: NotebookCellsChangeType.ChangeCellMetadata;
154
+ readonly index: number;
155
+ readonly metadata: NotebookCellMetadata;
156
+ }
157
+
158
+ export interface NotebookCellsChangeInternalMetadataEvent {
159
+ readonly kind: NotebookCellsChangeType.ChangeCellInternalMetadata;
160
+ readonly index: number;
161
+ readonly internalMetadata: NotebookCellInternalMetadata;
162
+ }
163
+
164
+ export interface NotebookCellContentChangeEvent {
165
+ readonly kind: NotebookCellsChangeType.ChangeCellContent;
166
+ readonly index: number;
167
+ }
168
+
169
+ export interface NotebookModelResource {
170
+ notebookModelUri: URI;
171
+ }
172
+
173
+ export namespace NotebookModelResource {
174
+ export function is(item: unknown): item is NotebookModelResource {
175
+ return isObject<NotebookModelResource>(item) && item.notebookModelUri instanceof URI;
176
+ }
177
+ export function create(uri: URI): NotebookModelResource {
178
+ return { notebookModelUri: uri };
179
+ }
180
+ }
181
+
182
+ export interface NotebookCellModelResource {
183
+ notebookCellModelUri: URI;
184
+ }
185
+
186
+ export namespace NotebookCellModelResource {
187
+ export function is(item: unknown): item is NotebookCellModelResource {
188
+ return isObject<NotebookCellModelResource>(item) && item.notebookCellModelUri instanceof URI;
189
+ }
190
+ export function create(uri: URI): NotebookCellModelResource {
191
+ return { notebookCellModelUri: uri };
192
+ }
193
+ }
194
+
195
+ export enum NotebookCellExecutionState {
196
+ Unconfirmed = 1,
197
+ Pending = 2,
198
+ Executing = 3
199
+ }
200
+
201
+ export enum CellExecutionUpdateType {
202
+ Output = 1,
203
+ OutputItems = 2,
204
+ ExecutionState = 3,
205
+ }
206
+
207
+ export interface CellExecuteOutputEdit {
208
+ editType: CellExecutionUpdateType.Output;
209
+ cellHandle: number;
210
+ append?: boolean;
211
+ outputs: CellOutput[];
212
+ }
213
+
214
+ export interface CellExecuteOutputItemEdit {
215
+ editType: CellExecutionUpdateType.OutputItems;
216
+ append?: boolean;
217
+ outputId: string,
218
+ items: CellOutputItem[];
219
+ }
220
+
221
+ export interface CellExecutionStateUpdateDto {
222
+ editType: CellExecutionUpdateType.ExecutionState;
223
+ executionOrder?: number;
224
+ runStartTime?: number;
225
+ didPause?: boolean;
226
+ isPaused?: boolean;
227
+ }
228
+
229
+ export interface CellMetadataEdit {
230
+ editType: CellEditType.Metadata;
231
+ index: number;
232
+ metadata: NotebookCellMetadata;
233
+ }
234
+
235
+ export const enum CellEditType {
236
+ Replace = 1,
237
+ Output = 2,
238
+ Metadata = 3,
239
+ CellLanguage = 4,
240
+ DocumentMetadata = 5,
241
+ Move = 6,
242
+ OutputItems = 7,
243
+ PartialMetadata = 8,
244
+ PartialInternalMetadata = 9,
245
+ }
246
+
247
+ export interface NotebookKernelSourceAction {
248
+ readonly label: string;
249
+ readonly description?: string;
250
+ readonly detail?: string;
251
+ readonly command?: string | Command;
252
+ readonly documentation?: UriComponents | string;
253
+ }
254
+
255
+ /**
256
+ * Whether the provided mime type is a text stream like `stdout`, `stderr`.
257
+ */
258
+ export function isTextStreamMime(mimeType: string): boolean {
259
+ return ['application/vnd.code.notebook.stdout', 'application/vnd.code.notebook.stderr'].includes(mimeType);
260
+ }
261
+
262
+ export namespace CellUri {
263
+
264
+ export const cellUriScheme = 'vscode-notebook-cell';
265
+ export const outputUriScheme = 'vscode-notebook-cell-output';
266
+
267
+ const _lengths = ['W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f'];
268
+ const _padRegexp = new RegExp(`^[${_lengths.join('')}]+`);
269
+ const _radix = 7;
270
+
271
+ export function generate(notebook: URI, handle: number): URI {
272
+
273
+ const s = handle.toString(_radix);
274
+ const p = s.length < _lengths.length ? _lengths[s.length - 1] : 'z';
275
+
276
+ const fragment = `${p}${s}s${Buffer.from(BinaryBuffer.fromString(notebook.scheme).buffer).toString('base64')}`;
277
+ return notebook.withScheme(cellUriScheme).withFragment(fragment);
278
+ }
279
+
280
+ export function parse(cell: URI): { notebook: URI; handle: number } | undefined {
281
+ if (cell.scheme !== cellUriScheme) {
282
+ return undefined;
283
+ }
284
+
285
+ const idx = cell.fragment.indexOf('s');
286
+ if (idx < 0) {
287
+ return undefined;
288
+ }
289
+
290
+ const handle = parseInt(cell.fragment.substring(0, idx).replace(_padRegexp, ''), _radix);
291
+ const parsedScheme = Buffer.from(cell.fragment.substring(idx + 1), 'base64').toString();
292
+
293
+ if (isNaN(handle)) {
294
+ return undefined;
295
+ }
296
+ return {
297
+ handle,
298
+ notebook: cell.withScheme(parsedScheme).withoutFragment()
299
+ };
300
+ }
301
+
302
+ export function generateCellOutputUri(notebook: URI, outputId?: string): URI {
303
+ return notebook
304
+ .withScheme(outputUriScheme)
305
+ .withQuery(`op${outputId ?? ''},${notebook.scheme !== 'file' ? notebook.scheme : ''}`);
306
+ };
307
+
308
+ export function parseCellOutputUri(uri: URI): { notebook: URI; outputId?: string } | undefined {
309
+ if (uri.scheme !== outputUriScheme) {
310
+ return;
311
+ }
312
+
313
+ const match = /^op([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})?\,(.*)$/i.exec(uri.query);
314
+ if (!match) {
315
+ return undefined;
316
+ }
317
+
318
+ const outputId = match[1] || undefined;
319
+ const scheme = match[2];
320
+ return {
321
+ outputId,
322
+ notebook: uri.withScheme(scheme || 'file').withoutQuery()
323
+ };
324
+ }
325
+
326
+ export function generateCellPropertyUri(notebook: URI, handle: number, cellScheme: string): URI {
327
+ return CellUri.generate(notebook, handle).withScheme(cellScheme);
328
+ }
329
+
330
+ export function parseCellPropertyUri(uri: URI, propertyScheme: string): { notebook: URI; handle: number } | undefined {
331
+ if (uri.scheme !== propertyScheme) {
332
+ return undefined;
333
+ }
334
+
335
+ return CellUri.parse(uri.withScheme(cellUriScheme));
336
+ }
337
+ }