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