@theia/notebook 1.67.0-next.3 → 1.67.0-next.59
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.
- package/README.md +1 -1
- package/lib/browser/contributions/notebook-actions-contribution.d.ts.map +1 -1
- package/lib/browser/contributions/notebook-actions-contribution.js +29 -26
- package/lib/browser/contributions/notebook-actions-contribution.js.map +1 -1
- package/lib/browser/contributions/notebook-cell-actions-contribution.d.ts.map +1 -1
- package/lib/browser/contributions/notebook-cell-actions-contribution.js +23 -9
- package/lib/browser/contributions/notebook-cell-actions-contribution.js.map +1 -1
- package/lib/browser/contributions/notebook-label-provider-contribution.d.ts.map +1 -1
- package/lib/browser/contributions/notebook-label-provider-contribution.js +2 -1
- package/lib/browser/contributions/notebook-label-provider-contribution.js.map +1 -1
- package/lib/browser/contributions/notebook-outline-contribution.d.ts +3 -2
- package/lib/browser/contributions/notebook-outline-contribution.d.ts.map +1 -1
- package/lib/browser/contributions/notebook-outline-contribution.js +7 -5
- package/lib/browser/contributions/notebook-outline-contribution.js.map +1 -1
- package/lib/browser/contributions/notebook-status-bar-contribution.d.ts.map +1 -1
- package/lib/browser/contributions/notebook-status-bar-contribution.js +4 -6
- package/lib/browser/contributions/notebook-status-bar-contribution.js.map +1 -1
- package/lib/browser/index.d.ts +1 -0
- package/lib/browser/index.d.ts.map +1 -1
- package/lib/browser/index.js +1 -0
- package/lib/browser/index.js.map +1 -1
- package/lib/browser/notebook-cell-open-handler.js +3 -2
- package/lib/browser/notebook-cell-open-handler.js.map +1 -1
- package/lib/browser/notebook-editor-split-contribution.d.ts +14 -0
- package/lib/browser/notebook-editor-split-contribution.d.ts.map +1 -0
- package/lib/browser/notebook-editor-split-contribution.js +51 -0
- package/lib/browser/notebook-editor-split-contribution.js.map +1 -0
- package/lib/browser/notebook-editor-widget-factory.d.ts +1 -0
- package/lib/browser/notebook-editor-widget-factory.d.ts.map +1 -1
- package/lib/browser/notebook-editor-widget-factory.js +10 -2
- package/lib/browser/notebook-editor-widget-factory.js.map +1 -1
- package/lib/browser/notebook-editor-widget.d.ts +3 -0
- package/lib/browser/notebook-editor-widget.d.ts.map +1 -1
- package/lib/browser/notebook-editor-widget.js +17 -4
- package/lib/browser/notebook-editor-widget.js.map +1 -1
- package/lib/browser/notebook-frontend-module.d.ts.map +1 -1
- package/lib/browser/notebook-frontend-module.js +4 -0
- package/lib/browser/notebook-frontend-module.js.map +1 -1
- package/lib/browser/notebook-open-handler.d.ts +6 -0
- package/lib/browser/notebook-open-handler.d.ts.map +1 -1
- package/lib/browser/notebook-open-handler.js +17 -11
- package/lib/browser/notebook-open-handler.js.map +1 -1
- package/lib/browser/notebook-types.d.ts +1 -0
- package/lib/browser/notebook-types.d.ts.map +1 -1
- package/lib/browser/notebook-types.js.map +1 -1
- package/lib/browser/service/notebook-context-manager.d.ts +2 -0
- package/lib/browser/service/notebook-context-manager.d.ts.map +1 -1
- package/lib/browser/service/notebook-context-manager.js +14 -10
- package/lib/browser/service/notebook-context-manager.js.map +1 -1
- package/lib/browser/view/notebook-cell-editor.d.ts +2 -0
- package/lib/browser/view/notebook-cell-editor.d.ts.map +1 -1
- package/lib/browser/view/notebook-cell-editor.js +9 -5
- package/lib/browser/view/notebook-cell-editor.js.map +1 -1
- package/lib/browser/view/notebook-cell-list-view.d.ts +2 -0
- package/lib/browser/view/notebook-cell-list-view.d.ts.map +1 -1
- package/lib/browser/view/notebook-cell-list-view.js +34 -31
- package/lib/browser/view/notebook-cell-list-view.js.map +1 -1
- package/lib/browser/view/notebook-cell-toolbar-factory.d.ts.map +1 -1
- package/lib/browser/view/notebook-cell-toolbar-factory.js +5 -5
- package/lib/browser/view/notebook-cell-toolbar-factory.js.map +1 -1
- package/lib/browser/view/notebook-code-cell-view.d.ts +2 -0
- package/lib/browser/view/notebook-code-cell-view.d.ts.map +1 -1
- package/lib/browser/view/notebook-code-cell-view.js +7 -2
- package/lib/browser/view/notebook-code-cell-view.js.map +1 -1
- package/lib/browser/view/notebook-markdown-cell-view.d.ts +2 -0
- package/lib/browser/view/notebook-markdown-cell-view.d.ts.map +1 -1
- package/lib/browser/view/notebook-markdown-cell-view.js +27 -9
- package/lib/browser/view/notebook-markdown-cell-view.js.map +1 -1
- package/lib/browser/view-model/notebook-cell-model.d.ts +2 -14
- package/lib/browser/view-model/notebook-cell-model.d.ts.map +1 -1
- package/lib/browser/view-model/notebook-cell-model.js +7 -31
- package/lib/browser/view-model/notebook-cell-model.js.map +1 -1
- package/lib/browser/view-model/notebook-model.d.ts +1 -9
- package/lib/browser/view-model/notebook-model.d.ts.map +1 -1
- package/lib/browser/view-model/notebook-model.js +2 -24
- package/lib/browser/view-model/notebook-model.js.map +1 -1
- package/lib/browser/view-model/notebook-view-model.d.ts +40 -0
- package/lib/browser/view-model/notebook-view-model.d.ts.map +1 -0
- package/lib/browser/view-model/notebook-view-model.js +120 -0
- package/lib/browser/view-model/notebook-view-model.js.map +1 -0
- package/package.json +7 -7
- package/src/browser/contributions/notebook-actions-contribution.ts +25 -22
- package/src/browser/contributions/notebook-cell-actions-contribution.ts +20 -9
- package/src/browser/contributions/notebook-label-provider-contribution.ts +2 -1
- package/src/browser/contributions/notebook-outline-contribution.ts +8 -6
- package/src/browser/contributions/notebook-status-bar-contribution.ts +4 -6
- package/src/browser/index.ts +1 -0
- package/src/browser/notebook-cell-open-handler.ts +3 -3
- package/src/browser/notebook-editor-split-contribution.ts +51 -0
- package/src/browser/notebook-editor-widget-factory.ts +11 -1
- package/src/browser/notebook-editor-widget.tsx +18 -3
- package/src/browser/notebook-frontend-module.ts +5 -0
- package/src/browser/notebook-open-handler.ts +19 -11
- package/src/browser/notebook-types.ts +1 -0
- package/src/browser/service/notebook-context-manager.ts +17 -9
- package/src/browser/view/notebook-cell-editor.tsx +13 -5
- package/src/browser/view/notebook-cell-list-view.tsx +15 -12
- package/src/browser/view/notebook-cell-toolbar-factory.tsx +5 -4
- package/src/browser/view/notebook-code-cell-view.tsx +6 -1
- package/src/browser/view/notebook-markdown-cell-view.tsx +27 -7
- package/src/browser/view-model/notebook-cell-model.ts +8 -41
- package/src/browser/view-model/notebook-model.ts +2 -33
- package/src/browser/view-model/notebook-view-model.ts +138 -0
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
// *****************************************************************************
|
|
2
|
+
// Copyright (C) 2025 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 { injectable } from '@theia/core/shared/inversify';
|
|
18
|
+
import { NotebookCellModel } from './notebook-cell-model';
|
|
19
|
+
import { Disposable, Emitter } from '@theia/core';
|
|
20
|
+
import { NotebookModel } from './notebook-model';
|
|
21
|
+
|
|
22
|
+
export interface SelectedCellChangeEvent {
|
|
23
|
+
cell: NotebookCellModel | undefined;
|
|
24
|
+
scrollIntoView: boolean;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export type CellEditorFocusRequest = number | 'lastLine' | undefined;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Model containing the editor state/view information of a notebook editor. The actual notebook data can be found in the {@link NotebookModel}.
|
|
31
|
+
*/
|
|
32
|
+
@injectable()
|
|
33
|
+
export class NotebookViewModel implements Disposable {
|
|
34
|
+
|
|
35
|
+
protected readonly onDidChangeSelectedCellEmitter = new Emitter<SelectedCellChangeEvent>();
|
|
36
|
+
readonly onDidChangeSelectedCell = this.onDidChangeSelectedCellEmitter.event;
|
|
37
|
+
|
|
38
|
+
selectedCell?: NotebookCellModel;
|
|
39
|
+
get selectedCellViewModel(): CellViewModel | undefined {
|
|
40
|
+
if (this.selectedCell) {
|
|
41
|
+
return this.cellViewModels.get(this.selectedCell.handle);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// Cell handle to CellViewModel mapping
|
|
46
|
+
readonly cellViewModels: Map<number, CellViewModel> = new Map();
|
|
47
|
+
|
|
48
|
+
initDataModel(model: NotebookModel): void {
|
|
49
|
+
model.onDidAddOrRemoveCell(e => {
|
|
50
|
+
|
|
51
|
+
for (const cellId of e.newCellIds || []) {
|
|
52
|
+
const cell = model.getCellByHandle(cellId);
|
|
53
|
+
if (cell) {
|
|
54
|
+
this.cellViewModels.set(cell.handle, new CellViewModel(cell, () => {
|
|
55
|
+
this.cellViewModels.delete(cell.handle);
|
|
56
|
+
}));
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (e.newCellIds && e.newCellIds?.length > 0 && e.externalEvent) {
|
|
61
|
+
const lastNewCellHandle = e.newCellIds[e.newCellIds.length - 1];
|
|
62
|
+
const newSelectedCell = model.getCellByHandle(lastNewCellHandle)!;
|
|
63
|
+
this.setSelectedCell(newSelectedCell, true);
|
|
64
|
+
this.cellViewModels.get(newSelectedCell.handle)?.requestEdit();
|
|
65
|
+
} else if (this.selectedCell && !model.getCellByHandle(this.selectedCell.handle)) {
|
|
66
|
+
const newSelectedIndex = e.rawEvent.changes[e.rawEvent.changes.length - 1].start;
|
|
67
|
+
const newSelectedCell = model.cells[Math.min(newSelectedIndex, model.cells.length - 1)];
|
|
68
|
+
this.setSelectedCell(newSelectedCell, false);
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
for (const cell of model.cells) {
|
|
73
|
+
this.cellViewModels.set(cell.handle, new CellViewModel(cell, () => {
|
|
74
|
+
this.cellViewModels.delete(cell.handle);
|
|
75
|
+
}));
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
setSelectedCell(cell: NotebookCellModel, scrollIntoView: boolean = true): void {
|
|
80
|
+
if (this.selectedCell !== cell) {
|
|
81
|
+
this.selectedCell = cell;
|
|
82
|
+
this.onDidChangeSelectedCellEmitter.fire({ cell, scrollIntoView });
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
dispose(): void {
|
|
87
|
+
this.onDidChangeSelectedCellEmitter.dispose();
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export class CellViewModel implements Disposable {
|
|
93
|
+
|
|
94
|
+
protected readonly onDidRequestCellEditChangeEmitter = new Emitter<boolean>();
|
|
95
|
+
readonly onDidRequestCellEditChange = this.onDidRequestCellEditChangeEmitter.event;
|
|
96
|
+
|
|
97
|
+
protected readonly onWillFocusCellEditorEmitter = new Emitter<CellEditorFocusRequest>();
|
|
98
|
+
readonly onWillFocusCellEditor = this.onWillFocusCellEditorEmitter.event;
|
|
99
|
+
|
|
100
|
+
protected readonly onWillBlurCellEditorEmitter = new Emitter<void>();
|
|
101
|
+
readonly onWillBlurCellEditor = this.onWillBlurCellEditorEmitter.event;
|
|
102
|
+
|
|
103
|
+
protected _editing: boolean = false;
|
|
104
|
+
get editing(): boolean {
|
|
105
|
+
return this._editing;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
constructor(protected readonly cell: NotebookCellModel, protected onDispose: () => void) {
|
|
109
|
+
cell.toDispose.push(this);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
requestEdit(): void {
|
|
113
|
+
if (this.cell.isTextModelWritable) {
|
|
114
|
+
this._editing = true;
|
|
115
|
+
this.onDidRequestCellEditChangeEmitter.fire(true);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
requestStopEdit(): void {
|
|
120
|
+
this._editing = false;
|
|
121
|
+
this.onDidRequestCellEditChangeEmitter.fire(false);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
requestFocusEditor(focusRequest?: CellEditorFocusRequest): void {
|
|
125
|
+
this.requestEdit();
|
|
126
|
+
this.onWillFocusCellEditorEmitter.fire(focusRequest);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
requestBlurEditor(): void {
|
|
130
|
+
this.requestStopEdit();
|
|
131
|
+
this.onWillBlurCellEditorEmitter.fire();
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
dispose(): void {
|
|
135
|
+
this.onDispose();
|
|
136
|
+
this.onDidRequestCellEditChangeEmitter.dispose();
|
|
137
|
+
}
|
|
138
|
+
}
|