@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,160 +1,160 @@
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 { Emitter, Resource, ResourceProvider, UNTITLED_SCHEME, URI } from '@theia/core';
18
- import { inject, injectable } from '@theia/core/shared/inversify';
19
- import { UriComponents } from '@theia/core/lib/common/uri';
20
- import { FileService } from '@theia/filesystem/lib/browser/file-service';
21
- import { NotebookData } from '../../common';
22
- import { NotebookModel } from '../view-model/notebook-model';
23
- import { NotebookService } from './notebook-service';
24
- import { NotebookTypeRegistry } from '../notebook-type-registry';
25
- import { NotebookFileSelector } from '../../common/notebook-protocol';
26
- import { match } from '@theia/core/lib/common/glob';
27
-
28
- export interface UntitledResource {
29
- untitledResource: URI | undefined
30
- }
31
-
32
- @injectable()
33
- export class NotebookModelResolverService {
34
-
35
- @inject(FileService)
36
- protected fileService: FileService;
37
-
38
- @inject(ResourceProvider)
39
- protected resourceProvider: ResourceProvider;
40
-
41
- @inject(NotebookService)
42
- protected notebookService: NotebookService;
43
-
44
- @inject(NotebookTypeRegistry)
45
- protected notebookTypeRegistry: NotebookTypeRegistry;
46
-
47
- protected onDidChangeDirtyEmitter = new Emitter<NotebookModel>();
48
- readonly onDidChangeDirty = this.onDidChangeDirtyEmitter.event;
49
- protected onDidSaveNotebookEmitter = new Emitter<UriComponents>();
50
- readonly onDidSaveNotebook = this.onDidSaveNotebookEmitter.event;
51
-
52
- async resolve(resource: URI, viewType?: string): Promise<NotebookModel> {
53
- const existingModel = this.notebookService.getNotebookEditorModel(resource);
54
- if (!viewType) {
55
- if (existingModel) {
56
- return existingModel;
57
- } else {
58
- viewType = this.findViewTypeForResource(resource);
59
- }
60
- } else if (existingModel?.viewType === viewType) {
61
- return existingModel;
62
- }
63
-
64
- if (!viewType) {
65
- throw new Error(`Missing viewType for '${resource}'`);
66
- }
67
-
68
- const actualResource = await this.resourceProvider(resource);
69
- const notebookData = await this.resolveExistingNotebookData(actualResource, viewType!);
70
- const notebookModel = await this.notebookService.createNotebookModel(notebookData, viewType, actualResource);
71
-
72
- notebookModel.onDirtyChanged(() => this.onDidChangeDirtyEmitter.fire(notebookModel));
73
- notebookModel.onDidSaveNotebook(() => this.onDidSaveNotebookEmitter.fire(notebookModel.uri.toComponents()));
74
-
75
- return notebookModel;
76
- }
77
-
78
- async resolveUntitledResource(arg: UntitledResource, viewType: string): Promise<NotebookModel> {
79
- let resource: URI;
80
- // let hasAssociatedFilePath = false;
81
- arg = arg as UntitledResource;
82
- if (!arg.untitledResource) {
83
- const notebookTypeInfo = this.notebookTypeRegistry.notebookTypes.find(info => info.type === viewType);
84
- if (!notebookTypeInfo) {
85
- throw new Error('UNKNOWN view type: ' + viewType);
86
- }
87
-
88
- const suffix = this.getPossibleFileEnding(notebookTypeInfo.selector ?? []) ?? '';
89
- for (let counter = 1; ; counter++) {
90
- const candidate = new URI()
91
- .withScheme(UNTITLED_SCHEME)
92
- .withPath(`Untitled-notebook-${counter}${suffix}`)
93
- .withQuery(viewType);
94
- if (!this.notebookService.getNotebookEditorModel(candidate)) {
95
- resource = candidate;
96
- break;
97
- }
98
- }
99
- } else if (arg.untitledResource.scheme === UNTITLED_SCHEME) {
100
- resource = arg.untitledResource;
101
- } else {
102
- throw new Error('Invalid untitled resource: ' + arg.untitledResource.toString() + ' untitled resources with associated file path are not supported yet');
103
- // TODO implement associated file path support
104
- // resource = arg.untitledResource.withScheme('untitled');
105
- // hasAssociatedFilePath = true;
106
- }
107
-
108
- return this.resolve(resource, viewType);
109
- }
110
-
111
- async resolveExistingNotebookData(resource: Resource, viewType: string): Promise<NotebookData> {
112
- if (resource.uri.scheme === 'untitled') {
113
- return {
114
- cells: [],
115
- metadata: {}
116
- };
117
- } else {
118
- const [dataProvider, contents] = await Promise.all([
119
- this.notebookService.getNotebookDataProvider(viewType),
120
- this.fileService.readFile(resource.uri)
121
- ]);
122
- const notebook = await dataProvider.serializer.toNotebook(contents.value);
123
-
124
- return notebook;
125
- }
126
- }
127
-
128
- protected getPossibleFileEnding(selectors: readonly NotebookFileSelector[]): string | undefined {
129
- for (const selector of selectors) {
130
- const ending = this.possibleFileEnding(selector);
131
- if (ending) {
132
- return ending;
133
- }
134
- }
135
- return undefined;
136
- }
137
-
138
- protected possibleFileEnding(selector: NotebookFileSelector): string | undefined {
139
-
140
- const pattern = /^.*(\.[a-zA-Z0-9_-]+)$/;
141
-
142
- const candidate = typeof selector === 'string' ? selector : selector.filenamePattern;
143
-
144
- if (candidate) {
145
- const matches = pattern.exec(candidate);
146
- if (matches) {
147
- return matches[1];
148
- }
149
- }
150
-
151
- return undefined;
152
- }
153
-
154
- protected findViewTypeForResource(resource: URI): string | undefined {
155
- return this.notebookTypeRegistry.notebookTypes.find(info =>
156
- info.selector?.some(selector => selector.filenamePattern && match(selector.filenamePattern, resource.path.name + resource.path.ext))
157
- )?.type;
158
- }
159
-
160
- }
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 { Emitter, Resource, ResourceProvider, UNTITLED_SCHEME, URI } from '@theia/core';
18
+ import { inject, injectable } from '@theia/core/shared/inversify';
19
+ import { UriComponents } from '@theia/core/lib/common/uri';
20
+ import { FileService } from '@theia/filesystem/lib/browser/file-service';
21
+ import { NotebookData } from '../../common';
22
+ import { NotebookModel } from '../view-model/notebook-model';
23
+ import { NotebookService } from './notebook-service';
24
+ import { NotebookTypeRegistry } from '../notebook-type-registry';
25
+ import { NotebookFileSelector } from '../../common/notebook-protocol';
26
+ import { match } from '@theia/core/lib/common/glob';
27
+
28
+ export interface UntitledResource {
29
+ untitledResource: URI | undefined
30
+ }
31
+
32
+ @injectable()
33
+ export class NotebookModelResolverService {
34
+
35
+ @inject(FileService)
36
+ protected fileService: FileService;
37
+
38
+ @inject(ResourceProvider)
39
+ protected resourceProvider: ResourceProvider;
40
+
41
+ @inject(NotebookService)
42
+ protected notebookService: NotebookService;
43
+
44
+ @inject(NotebookTypeRegistry)
45
+ protected notebookTypeRegistry: NotebookTypeRegistry;
46
+
47
+ protected onDidChangeDirtyEmitter = new Emitter<NotebookModel>();
48
+ readonly onDidChangeDirty = this.onDidChangeDirtyEmitter.event;
49
+ protected onDidSaveNotebookEmitter = new Emitter<UriComponents>();
50
+ readonly onDidSaveNotebook = this.onDidSaveNotebookEmitter.event;
51
+
52
+ async resolve(resource: URI, viewType?: string): Promise<NotebookModel> {
53
+ const existingModel = this.notebookService.getNotebookEditorModel(resource);
54
+ if (!viewType) {
55
+ if (existingModel) {
56
+ return existingModel;
57
+ } else {
58
+ viewType = this.findViewTypeForResource(resource);
59
+ }
60
+ } else if (existingModel?.viewType === viewType) {
61
+ return existingModel;
62
+ }
63
+
64
+ if (!viewType) {
65
+ throw new Error(`Missing viewType for '${resource}'`);
66
+ }
67
+
68
+ const actualResource = await this.resourceProvider(resource);
69
+ const notebookData = await this.resolveExistingNotebookData(actualResource, viewType!);
70
+ const notebookModel = await this.notebookService.createNotebookModel(notebookData, viewType, actualResource);
71
+
72
+ notebookModel.onDirtyChanged(() => this.onDidChangeDirtyEmitter.fire(notebookModel));
73
+ notebookModel.onDidSaveNotebook(() => this.onDidSaveNotebookEmitter.fire(notebookModel.uri.toComponents()));
74
+
75
+ return notebookModel;
76
+ }
77
+
78
+ async resolveUntitledResource(arg: UntitledResource, viewType: string): Promise<NotebookModel> {
79
+ let resource: URI;
80
+ // let hasAssociatedFilePath = false;
81
+ arg = arg as UntitledResource;
82
+ if (!arg.untitledResource) {
83
+ const notebookTypeInfo = this.notebookTypeRegistry.notebookTypes.find(info => info.type === viewType);
84
+ if (!notebookTypeInfo) {
85
+ throw new Error('UNKNOWN view type: ' + viewType);
86
+ }
87
+
88
+ const suffix = this.getPossibleFileEnding(notebookTypeInfo.selector ?? []) ?? '';
89
+ for (let counter = 1; ; counter++) {
90
+ const candidate = new URI()
91
+ .withScheme(UNTITLED_SCHEME)
92
+ .withPath(`Untitled-notebook-${counter}${suffix}`)
93
+ .withQuery(viewType);
94
+ if (!this.notebookService.getNotebookEditorModel(candidate)) {
95
+ resource = candidate;
96
+ break;
97
+ }
98
+ }
99
+ } else if (arg.untitledResource.scheme === UNTITLED_SCHEME) {
100
+ resource = arg.untitledResource;
101
+ } else {
102
+ throw new Error('Invalid untitled resource: ' + arg.untitledResource.toString() + ' untitled resources with associated file path are not supported yet');
103
+ // TODO implement associated file path support
104
+ // resource = arg.untitledResource.withScheme('untitled');
105
+ // hasAssociatedFilePath = true;
106
+ }
107
+
108
+ return this.resolve(resource, viewType);
109
+ }
110
+
111
+ async resolveExistingNotebookData(resource: Resource, viewType: string): Promise<NotebookData> {
112
+ if (resource.uri.scheme === 'untitled') {
113
+ return {
114
+ cells: [],
115
+ metadata: {}
116
+ };
117
+ } else {
118
+ const [dataProvider, contents] = await Promise.all([
119
+ this.notebookService.getNotebookDataProvider(viewType),
120
+ this.fileService.readFile(resource.uri)
121
+ ]);
122
+ const notebook = await dataProvider.serializer.toNotebook(contents.value);
123
+
124
+ return notebook;
125
+ }
126
+ }
127
+
128
+ protected getPossibleFileEnding(selectors: readonly NotebookFileSelector[]): string | undefined {
129
+ for (const selector of selectors) {
130
+ const ending = this.possibleFileEnding(selector);
131
+ if (ending) {
132
+ return ending;
133
+ }
134
+ }
135
+ return undefined;
136
+ }
137
+
138
+ protected possibleFileEnding(selector: NotebookFileSelector): string | undefined {
139
+
140
+ const pattern = /^.*(\.[a-zA-Z0-9_-]+)$/;
141
+
142
+ const candidate = typeof selector === 'string' ? selector : selector.filenamePattern;
143
+
144
+ if (candidate) {
145
+ const matches = pattern.exec(candidate);
146
+ if (matches) {
147
+ return matches[1];
148
+ }
149
+ }
150
+
151
+ return undefined;
152
+ }
153
+
154
+ protected findViewTypeForResource(resource: URI): string | undefined {
155
+ return this.notebookTypeRegistry.notebookTypes.find(info =>
156
+ info.selector?.some(selector => selector.filenamePattern && match(selector.filenamePattern, resource.path.name + resource.path.ext))
157
+ )?.type;
158
+ }
159
+
160
+ }
@@ -1,48 +1,48 @@
1
- // *****************************************************************************
2
- // Copyright (C) 2024 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 { ReferenceCollection, URI, Reference, Event } from '@theia/core';
18
- import { inject, injectable } from '@theia/core/shared/inversify';
19
- import { MonacoTextModelService } from '@theia/monaco/lib/browser/monaco-text-model-service';
20
- import { MonacoEditorModel } from '@theia/monaco/lib/browser/monaco-editor-model';
21
- import { NotebookModel } from '../view-model/notebook-model';
22
-
23
- /**
24
- * special service for creating monaco textmodels for notebook cells.
25
- * Its for optimization purposes since there is alot of overhead otherwise with calling the backend to create a document for each cell and other smaller things.
26
- */
27
- @injectable()
28
- export class NotebookMonacoTextModelService {
29
-
30
- @inject(MonacoTextModelService)
31
- protected readonly monacoTextModelService: MonacoTextModelService;
32
-
33
- protected readonly cellmodels = new ReferenceCollection<string, MonacoEditorModel>(
34
- uri => this.monacoTextModelService.createUnmanagedModel(new URI(uri))
35
- );
36
-
37
- getOrCreateNotebookCellModelReference(uri: URI): Promise<Reference<MonacoEditorModel>> {
38
- return this.cellmodels.acquire(uri.toString());
39
- }
40
-
41
- async createTextModelsForNotebook(notebook: NotebookModel): Promise<void> {
42
- await Promise.all(notebook.cells.map(cell => cell.resolveTextModel()));
43
- }
44
-
45
- get onDidCreateNotebookCellModel(): Event<MonacoEditorModel> {
46
- return this.cellmodels.onDidCreate;
47
- }
48
- }
1
+ // *****************************************************************************
2
+ // Copyright (C) 2024 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 { ReferenceCollection, URI, Reference, Event } from '@theia/core';
18
+ import { inject, injectable } from '@theia/core/shared/inversify';
19
+ import { MonacoTextModelService } from '@theia/monaco/lib/browser/monaco-text-model-service';
20
+ import { MonacoEditorModel } from '@theia/monaco/lib/browser/monaco-editor-model';
21
+ import { NotebookModel } from '../view-model/notebook-model';
22
+
23
+ /**
24
+ * special service for creating monaco textmodels for notebook cells.
25
+ * Its for optimization purposes since there is alot of overhead otherwise with calling the backend to create a document for each cell and other smaller things.
26
+ */
27
+ @injectable()
28
+ export class NotebookMonacoTextModelService {
29
+
30
+ @inject(MonacoTextModelService)
31
+ protected readonly monacoTextModelService: MonacoTextModelService;
32
+
33
+ protected readonly cellmodels = new ReferenceCollection<string, MonacoEditorModel>(
34
+ uri => this.monacoTextModelService.createUnmanagedModel(new URI(uri))
35
+ );
36
+
37
+ getOrCreateNotebookCellModelReference(uri: URI): Promise<Reference<MonacoEditorModel>> {
38
+ return this.cellmodels.acquire(uri.toString());
39
+ }
40
+
41
+ async createTextModelsForNotebook(notebook: NotebookModel): Promise<void> {
42
+ await Promise.all(notebook.cells.map(cell => cell.resolveTextModel()));
43
+ }
44
+
45
+ get onDidCreateNotebookCellModel(): Event<MonacoEditorModel> {
46
+ return this.cellmodels.onDidCreate;
47
+ }
48
+ }