@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,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
+ }