@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,119 +1,119 @@
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
- * Copyright (c) Microsoft Corporation. All rights reserved.
18
- * Licensed under the MIT License. See License.txt in the project root for license information.
19
- * Copied from commit 18b2c92451b076943e5b508380e0eba66ba7d934 from file src\vs\workbench\contrib\notebook\common\notebookCommon.ts
20
- *--------------------------------------------------------------------------------------------*/
21
-
22
- import { BinaryBuffer } from '@theia/core/lib/common/buffer';
23
-
24
- const textDecoder = new TextDecoder();
25
-
26
- /**
27
- * Given a stream of individual stdout outputs, this function will return the compressed lines, escaping some of the common terminal escape codes.
28
- * E.g. some terminal escape codes would result in the previous line getting cleared, such if we had 3 lines and
29
- * last line contained such a code, then the result string would be just the first two lines.
30
- * @returns a single VSBuffer with the concatenated and compressed data, and whether any compression was done.
31
- */
32
- export function compressOutputItemStreams(outputs: Uint8Array[]): { data: BinaryBuffer, didCompression: boolean } {
33
- const buffers: Uint8Array[] = [];
34
- let startAppending = false;
35
-
36
- // Pick the first set of outputs with the same mime type.
37
- for (const output of outputs) {
38
- if ((buffers.length === 0 || startAppending)) {
39
- buffers.push(output);
40
- startAppending = true;
41
- }
42
- }
43
-
44
- let didCompression = compressStreamBuffer(buffers);
45
- const concatenated = BinaryBuffer.concat(buffers.map(buffer => BinaryBuffer.wrap(buffer)));
46
- const data = formatStreamText(concatenated);
47
- didCompression = didCompression || data.byteLength !== concatenated.byteLength;
48
- return { data, didCompression };
49
- }
50
-
51
- export const MOVE_CURSOR_1_LINE_COMMAND = `${String.fromCharCode(27)}[A`;
52
- const MOVE_CURSOR_1_LINE_COMMAND_BYTES = MOVE_CURSOR_1_LINE_COMMAND.split('').map(c => c.charCodeAt(0));
53
- const LINE_FEED = 10;
54
- function compressStreamBuffer(streams: Uint8Array[]): boolean {
55
- let didCompress = false;
56
- streams.forEach((stream, index) => {
57
- if (index === 0 || stream.length < MOVE_CURSOR_1_LINE_COMMAND.length) {
58
- return;
59
- }
60
-
61
- const previousStream = streams[index - 1];
62
-
63
- // Remove the previous line if required.
64
- const command = stream.subarray(0, MOVE_CURSOR_1_LINE_COMMAND.length);
65
- if (command[0] === MOVE_CURSOR_1_LINE_COMMAND_BYTES[0] && command[1] === MOVE_CURSOR_1_LINE_COMMAND_BYTES[1] && command[2] === MOVE_CURSOR_1_LINE_COMMAND_BYTES[2]) {
66
- const lastIndexOfLineFeed = previousStream.lastIndexOf(LINE_FEED);
67
- if (lastIndexOfLineFeed === -1) {
68
- return;
69
- }
70
-
71
- didCompress = true;
72
- streams[index - 1] = previousStream.subarray(0, lastIndexOfLineFeed);
73
- streams[index] = stream.subarray(MOVE_CURSOR_1_LINE_COMMAND.length);
74
- }
75
- });
76
- return didCompress;
77
- }
78
-
79
- const BACKSPACE_CHARACTER = '\b'.charCodeAt(0);
80
- const CARRIAGE_RETURN_CHARACTER = '\r'.charCodeAt(0);
81
- function formatStreamText(buffer: BinaryBuffer): BinaryBuffer {
82
- // We have special handling for backspace and carriage return characters.
83
- // Don't unnecessary decode the bytes if we don't need to perform any processing.
84
- if (!buffer.buffer.includes(BACKSPACE_CHARACTER) && !buffer.buffer.includes(CARRIAGE_RETURN_CHARACTER)) {
85
- return buffer;
86
- }
87
- // Do the same thing jupyter is doing
88
- return BinaryBuffer.fromString(fixCarriageReturn(fixBackspace(textDecoder.decode(buffer.buffer))));
89
- }
90
-
91
- /**
92
- * Took this from jupyter/notebook
93
- * https://github.com/jupyter/notebook/blob/b8b66332e2023e83d2ee04f83d8814f567e01a4e/notebook/static/base/js/utils.js
94
- * Remove characters that are overridden by backspace characters
95
- */
96
- function fixBackspace(txt: string): string {
97
- let tmp = txt;
98
- do {
99
- txt = tmp;
100
- // Cancel out anything-but-newline followed by backspace
101
- tmp = txt.replace(/[^\n]\x08/gm, '');
102
- } while (tmp.length < txt.length);
103
- return txt;
104
- }
105
-
106
- /**
107
- * Remove chunks that should be overridden by the effect of carriage return characters
108
- * From https://github.com/jupyter/notebook/blob/master/notebook/static/base/js/utils.js
109
- */
110
- function fixCarriageReturn(txt: string): string {
111
- txt = txt.replace(/\r+\n/gm, '\n'); // \r followed by \n --> newline
112
- while (txt.search(/\r[^$]/g) > -1) {
113
- const base = txt.match(/^(.*)\r+/m)![1];
114
- let insert = txt.match(/\r+(.*)$/m)![1];
115
- insert = insert + base.slice(insert.length, base.length);
116
- txt = txt.replace(/\r+.*$/m, '\r').replace(/^.*\r/m, insert);
117
- }
118
- return txt;
119
- }
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
+ * Copyright (c) Microsoft Corporation. All rights reserved.
18
+ * Licensed under the MIT License. See License.txt in the project root for license information.
19
+ * Copied from commit 18b2c92451b076943e5b508380e0eba66ba7d934 from file src\vs\workbench\contrib\notebook\common\notebookCommon.ts
20
+ *--------------------------------------------------------------------------------------------*/
21
+
22
+ import { BinaryBuffer } from '@theia/core/lib/common/buffer';
23
+
24
+ const textDecoder = new TextDecoder();
25
+
26
+ /**
27
+ * Given a stream of individual stdout outputs, this function will return the compressed lines, escaping some of the common terminal escape codes.
28
+ * E.g. some terminal escape codes would result in the previous line getting cleared, such if we had 3 lines and
29
+ * last line contained such a code, then the result string would be just the first two lines.
30
+ * @returns a single VSBuffer with the concatenated and compressed data, and whether any compression was done.
31
+ */
32
+ export function compressOutputItemStreams(outputs: Uint8Array[]): { data: BinaryBuffer, didCompression: boolean } {
33
+ const buffers: Uint8Array[] = [];
34
+ let startAppending = false;
35
+
36
+ // Pick the first set of outputs with the same mime type.
37
+ for (const output of outputs) {
38
+ if ((buffers.length === 0 || startAppending)) {
39
+ buffers.push(output);
40
+ startAppending = true;
41
+ }
42
+ }
43
+
44
+ let didCompression = compressStreamBuffer(buffers);
45
+ const concatenated = BinaryBuffer.concat(buffers.map(buffer => BinaryBuffer.wrap(buffer)));
46
+ const data = formatStreamText(concatenated);
47
+ didCompression = didCompression || data.byteLength !== concatenated.byteLength;
48
+ return { data, didCompression };
49
+ }
50
+
51
+ export const MOVE_CURSOR_1_LINE_COMMAND = `${String.fromCharCode(27)}[A`;
52
+ const MOVE_CURSOR_1_LINE_COMMAND_BYTES = MOVE_CURSOR_1_LINE_COMMAND.split('').map(c => c.charCodeAt(0));
53
+ const LINE_FEED = 10;
54
+ function compressStreamBuffer(streams: Uint8Array[]): boolean {
55
+ let didCompress = false;
56
+ streams.forEach((stream, index) => {
57
+ if (index === 0 || stream.length < MOVE_CURSOR_1_LINE_COMMAND.length) {
58
+ return;
59
+ }
60
+
61
+ const previousStream = streams[index - 1];
62
+
63
+ // Remove the previous line if required.
64
+ const command = stream.subarray(0, MOVE_CURSOR_1_LINE_COMMAND.length);
65
+ if (command[0] === MOVE_CURSOR_1_LINE_COMMAND_BYTES[0] && command[1] === MOVE_CURSOR_1_LINE_COMMAND_BYTES[1] && command[2] === MOVE_CURSOR_1_LINE_COMMAND_BYTES[2]) {
66
+ const lastIndexOfLineFeed = previousStream.lastIndexOf(LINE_FEED);
67
+ if (lastIndexOfLineFeed === -1) {
68
+ return;
69
+ }
70
+
71
+ didCompress = true;
72
+ streams[index - 1] = previousStream.subarray(0, lastIndexOfLineFeed);
73
+ streams[index] = stream.subarray(MOVE_CURSOR_1_LINE_COMMAND.length);
74
+ }
75
+ });
76
+ return didCompress;
77
+ }
78
+
79
+ const BACKSPACE_CHARACTER = '\b'.charCodeAt(0);
80
+ const CARRIAGE_RETURN_CHARACTER = '\r'.charCodeAt(0);
81
+ function formatStreamText(buffer: BinaryBuffer): BinaryBuffer {
82
+ // We have special handling for backspace and carriage return characters.
83
+ // Don't unnecessary decode the bytes if we don't need to perform any processing.
84
+ if (!buffer.buffer.includes(BACKSPACE_CHARACTER) && !buffer.buffer.includes(CARRIAGE_RETURN_CHARACTER)) {
85
+ return buffer;
86
+ }
87
+ // Do the same thing jupyter is doing
88
+ return BinaryBuffer.fromString(fixCarriageReturn(fixBackspace(textDecoder.decode(buffer.buffer))));
89
+ }
90
+
91
+ /**
92
+ * Took this from jupyter/notebook
93
+ * https://github.com/jupyter/notebook/blob/b8b66332e2023e83d2ee04f83d8814f567e01a4e/notebook/static/base/js/utils.js
94
+ * Remove characters that are overridden by backspace characters
95
+ */
96
+ function fixBackspace(txt: string): string {
97
+ let tmp = txt;
98
+ do {
99
+ txt = tmp;
100
+ // Cancel out anything-but-newline followed by backspace
101
+ tmp = txt.replace(/[^\n]\x08/gm, '');
102
+ } while (tmp.length < txt.length);
103
+ return txt;
104
+ }
105
+
106
+ /**
107
+ * Remove chunks that should be overridden by the effect of carriage return characters
108
+ * From https://github.com/jupyter/notebook/blob/master/notebook/static/base/js/utils.js
109
+ */
110
+ function fixCarriageReturn(txt: string): string {
111
+ txt = txt.replace(/\r+\n/gm, '\n'); // \r followed by \n --> newline
112
+ while (txt.search(/\r[^$]/g) > -1) {
113
+ const base = txt.match(/^(.*)\r+/m)![1];
114
+ let insert = txt.match(/\r+(.*)$/m)![1];
115
+ insert = insert + base.slice(insert.length, base.length);
116
+ txt = txt.replace(/\r+.*$/m, '\r').replace(/^.*\r/m, insert);
117
+ }
118
+ return txt;
119
+ }
@@ -1,85 +1,85 @@
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
- * Copyright (c) Microsoft Corporation. All rights reserved.
18
- * Licensed under the MIT License. See License.txt in the project root for license information.
19
- *--------------------------------------------------------------------------------------------*/
20
-
21
- import { Disposable, Path } from '@theia/core';
22
- import { injectable } from '@theia/core/shared/inversify';
23
- import { NotebookRendererDescriptor } from '../common/notebook-protocol';
24
-
25
- export interface NotebookRendererInfo {
26
- readonly id: string;
27
- readonly displayName: string;
28
- readonly mimeTypes: string[];
29
- readonly entrypoint: { readonly extends?: string; readonly uri: string };
30
- readonly requiresMessaging: boolean;
31
- }
32
-
33
- export interface NotebookPreloadInfo {
34
- readonly type: string;
35
- readonly entrypoint: string;
36
- }
37
-
38
- @injectable()
39
- export class NotebookRendererRegistry {
40
-
41
- private readonly _notebookRenderers: NotebookRendererInfo[] = [];
42
-
43
- get notebookRenderers(): readonly NotebookRendererInfo[] {
44
- return this._notebookRenderers;
45
- }
46
-
47
- private readonly _staticNotebookPreloads: NotebookPreloadInfo[] = [];
48
-
49
- get staticNotebookPreloads(): readonly NotebookPreloadInfo[] {
50
- return this._staticNotebookPreloads;
51
- }
52
-
53
- registerNotebookRenderer(type: NotebookRendererDescriptor, basePath: string): Disposable {
54
- let entrypoint;
55
- if (typeof type.entrypoint === 'string') {
56
- entrypoint = {
57
- uri: new Path(basePath).join(type.entrypoint).toString()
58
- };
59
- } else {
60
- entrypoint = {
61
- uri: new Path(basePath).join(type.entrypoint.path).toString(),
62
- extends: type.entrypoint.extends
63
- };
64
- }
65
-
66
- this._notebookRenderers.push({
67
- ...type,
68
- mimeTypes: type.mimeTypes || [],
69
- requiresMessaging: type.requiresMessaging === 'always' || type.requiresMessaging === 'optional',
70
- entrypoint
71
- });
72
- return Disposable.create(() => {
73
- this._notebookRenderers.splice(this._notebookRenderers.findIndex(renderer => renderer.id === type.id), 1);
74
- });
75
- }
76
-
77
- registerStaticNotebookPreload(type: string, entrypoint: string, basePath: string): Disposable {
78
- const staticPreload = { type, entrypoint: new Path(basePath).join(entrypoint).toString() };
79
- this._staticNotebookPreloads.push(staticPreload);
80
- return Disposable.create(() => {
81
- this._staticNotebookPreloads.splice(this._staticNotebookPreloads.indexOf(staticPreload), 1);
82
- });
83
- }
84
- }
85
-
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
+ * Copyright (c) Microsoft Corporation. All rights reserved.
18
+ * Licensed under the MIT License. See License.txt in the project root for license information.
19
+ *--------------------------------------------------------------------------------------------*/
20
+
21
+ import { Disposable, Path } from '@theia/core';
22
+ import { injectable } from '@theia/core/shared/inversify';
23
+ import { NotebookRendererDescriptor } from '../common/notebook-protocol';
24
+
25
+ export interface NotebookRendererInfo {
26
+ readonly id: string;
27
+ readonly displayName: string;
28
+ readonly mimeTypes: string[];
29
+ readonly entrypoint: { readonly extends?: string; readonly uri: string };
30
+ readonly requiresMessaging: boolean;
31
+ }
32
+
33
+ export interface NotebookPreloadInfo {
34
+ readonly type: string;
35
+ readonly entrypoint: string;
36
+ }
37
+
38
+ @injectable()
39
+ export class NotebookRendererRegistry {
40
+
41
+ private readonly _notebookRenderers: NotebookRendererInfo[] = [];
42
+
43
+ get notebookRenderers(): readonly NotebookRendererInfo[] {
44
+ return this._notebookRenderers;
45
+ }
46
+
47
+ private readonly _staticNotebookPreloads: NotebookPreloadInfo[] = [];
48
+
49
+ get staticNotebookPreloads(): readonly NotebookPreloadInfo[] {
50
+ return this._staticNotebookPreloads;
51
+ }
52
+
53
+ registerNotebookRenderer(type: NotebookRendererDescriptor, basePath: string): Disposable {
54
+ let entrypoint;
55
+ if (typeof type.entrypoint === 'string') {
56
+ entrypoint = {
57
+ uri: new Path(basePath).join(type.entrypoint).toString()
58
+ };
59
+ } else {
60
+ entrypoint = {
61
+ uri: new Path(basePath).join(type.entrypoint.path).toString(),
62
+ extends: type.entrypoint.extends
63
+ };
64
+ }
65
+
66
+ this._notebookRenderers.push({
67
+ ...type,
68
+ mimeTypes: type.mimeTypes || [],
69
+ requiresMessaging: type.requiresMessaging === 'always' || type.requiresMessaging === 'optional',
70
+ entrypoint
71
+ });
72
+ return Disposable.create(() => {
73
+ this._notebookRenderers.splice(this._notebookRenderers.findIndex(renderer => renderer.id === type.id), 1);
74
+ });
75
+ }
76
+
77
+ registerStaticNotebookPreload(type: string, entrypoint: string, basePath: string): Disposable {
78
+ const staticPreload = { type, entrypoint: new Path(basePath).join(entrypoint).toString() };
79
+ this._staticNotebookPreloads.push(staticPreload);
80
+ return Disposable.create(() => {
81
+ this._staticNotebookPreloads.splice(this._staticNotebookPreloads.indexOf(staticPreload), 1);
82
+ });
83
+ }
84
+ }
85
+
@@ -1,54 +1,54 @@
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 { Disposable, DisposableCollection } from '@theia/core';
18
- import { inject, injectable } from '@theia/core/shared/inversify';
19
- import { OpenWithService } from '@theia/core/lib/browser';
20
- import { NotebookTypeDescriptor } from '../common/notebook-protocol';
21
- import { NotebookOpenHandler } from './notebook-open-handler';
22
-
23
- @injectable()
24
- export class NotebookTypeRegistry {
25
-
26
- @inject(OpenWithService)
27
- protected readonly openWithService: OpenWithService;
28
-
29
- @inject(NotebookOpenHandler)
30
- protected readonly notebookOpenHandler: NotebookOpenHandler;
31
-
32
- private readonly _notebookTypes: NotebookTypeDescriptor[] = [];
33
-
34
- get notebookTypes(): readonly NotebookTypeDescriptor[] {
35
- return this._notebookTypes;
36
- }
37
-
38
- registerNotebookType(type: NotebookTypeDescriptor, providerName: string): Disposable {
39
- const toDispose = new DisposableCollection();
40
- toDispose.push(Disposable.create(() => {
41
- this._notebookTypes.splice(this._notebookTypes.indexOf(type), 1);
42
- }));
43
- this._notebookTypes.push(type);
44
- toDispose.push(this.notebookOpenHandler.registerNotebookType(type));
45
- toDispose.push(this.openWithService.registerHandler({
46
- id: type.type,
47
- label: type.displayName,
48
- providerName,
49
- canHandle: uri => this.notebookOpenHandler.canHandleType(uri, type),
50
- open: uri => this.notebookOpenHandler.open(uri, { notebookType: type.type })
51
- }));
52
- return toDispose;
53
- }
54
- }
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 { Disposable, DisposableCollection } from '@theia/core';
18
+ import { inject, injectable } from '@theia/core/shared/inversify';
19
+ import { OpenWithService } from '@theia/core/lib/browser';
20
+ import { NotebookTypeDescriptor } from '../common/notebook-protocol';
21
+ import { NotebookOpenHandler } from './notebook-open-handler';
22
+
23
+ @injectable()
24
+ export class NotebookTypeRegistry {
25
+
26
+ @inject(OpenWithService)
27
+ protected readonly openWithService: OpenWithService;
28
+
29
+ @inject(NotebookOpenHandler)
30
+ protected readonly notebookOpenHandler: NotebookOpenHandler;
31
+
32
+ private readonly _notebookTypes: NotebookTypeDescriptor[] = [];
33
+
34
+ get notebookTypes(): readonly NotebookTypeDescriptor[] {
35
+ return this._notebookTypes;
36
+ }
37
+
38
+ registerNotebookType(type: NotebookTypeDescriptor, providerName: string): Disposable {
39
+ const toDispose = new DisposableCollection();
40
+ toDispose.push(Disposable.create(() => {
41
+ this._notebookTypes.splice(this._notebookTypes.indexOf(type), 1);
42
+ }));
43
+ this._notebookTypes.push(type);
44
+ toDispose.push(this.notebookOpenHandler.registerNotebookType(type));
45
+ toDispose.push(this.openWithService.registerHandler({
46
+ id: type.type,
47
+ label: type.displayName,
48
+ providerName,
49
+ canHandle: uri => this.notebookOpenHandler.canHandleType(uri, type),
50
+ open: uri => this.notebookOpenHandler.open(uri, { notebookType: type.type })
51
+ }));
52
+ return toDispose;
53
+ }
54
+ }