@theia/notebook 1.53.0-next.5 → 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.
- package/README.md +30 -30
- package/lib/browser/contributions/notebook-actions-contribution.d.ts +1 -0
- package/lib/browser/contributions/notebook-actions-contribution.d.ts.map +1 -1
- package/lib/browser/contributions/notebook-actions-contribution.js +31 -5
- package/lib/browser/contributions/notebook-actions-contribution.js.map +1 -1
- package/lib/browser/contributions/notebook-cell-actions-contribution.d.ts +2 -0
- package/lib/browser/contributions/notebook-cell-actions-contribution.d.ts.map +1 -1
- package/lib/browser/contributions/notebook-cell-actions-contribution.js +41 -7
- package/lib/browser/contributions/notebook-cell-actions-contribution.js.map +1 -1
- package/lib/browser/contributions/notebook-status-bar-contribution.d.ts +14 -0
- package/lib/browser/contributions/notebook-status-bar-contribution.d.ts.map +1 -0
- package/lib/browser/contributions/notebook-status-bar-contribution.js +75 -0
- package/lib/browser/contributions/notebook-status-bar-contribution.js.map +1 -0
- package/lib/browser/notebook-editor-widget.d.ts.map +1 -1
- package/lib/browser/notebook-editor-widget.js +3 -5
- 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 +3 -0
- package/lib/browser/notebook-frontend-module.js.map +1 -1
- package/lib/browser/notebook-open-handler.d.ts +3 -2
- package/lib/browser/notebook-open-handler.d.ts.map +1 -1
- package/lib/browser/notebook-open-handler.js +12 -5
- package/lib/browser/notebook-open-handler.js.map +1 -1
- package/lib/browser/view/notebook-cell-editor.d.ts +1 -0
- package/lib/browser/view/notebook-cell-editor.d.ts.map +1 -1
- package/lib/browser/view/notebook-cell-editor.js +30 -16
- package/lib/browser/view/notebook-cell-editor.js.map +1 -1
- package/lib/browser/view/notebook-cell-list-view.d.ts +6 -4
- package/lib/browser/view/notebook-cell-list-view.d.ts.map +1 -1
- package/lib/browser/view/notebook-cell-list-view.js +20 -13
- package/lib/browser/view/notebook-cell-list-view.js.map +1 -1
- package/lib/browser/view-model/notebook-cell-model.d.ts +3 -0
- package/lib/browser/view-model/notebook-cell-model.d.ts.map +1 -1
- package/lib/browser/view-model/notebook-cell-model.js +5 -0
- package/lib/browser/view-model/notebook-cell-model.js.map +1 -1
- package/package.json +8 -8
- package/src/browser/contributions/cell-operations.ts +44 -44
- package/src/browser/contributions/notebook-actions-contribution.ts +379 -350
- package/src/browser/contributions/notebook-cell-actions-contribution.ts +525 -487
- package/src/browser/contributions/notebook-color-contribution.ts +268 -268
- package/src/browser/contributions/notebook-context-keys.ts +113 -113
- package/src/browser/contributions/notebook-label-provider-contribution.ts +85 -85
- package/src/browser/contributions/notebook-outline-contribution.ts +114 -114
- package/src/browser/contributions/notebook-output-action-contribution.ts +82 -82
- package/src/browser/contributions/notebook-preferences.ts +92 -92
- package/src/browser/contributions/notebook-status-bar-contribution.ts +77 -0
- package/src/browser/contributions/notebook-undo-redo-handler.ts +41 -41
- package/src/browser/index.ts +27 -27
- package/src/browser/notebook-cell-resource-resolver.ts +130 -130
- package/src/browser/notebook-editor-widget-factory.ts +82 -82
- package/src/browser/notebook-editor-widget.tsx +330 -331
- package/src/browser/notebook-frontend-module.ts +119 -115
- package/src/browser/notebook-open-handler.ts +120 -114
- package/src/browser/notebook-output-utils.ts +119 -119
- package/src/browser/notebook-renderer-registry.ts +85 -85
- package/src/browser/notebook-type-registry.ts +54 -54
- package/src/browser/notebook-types.ts +186 -186
- package/src/browser/renderers/cell-output-webview.ts +33 -33
- package/src/browser/service/notebook-clipboard-service.ts +43 -43
- package/src/browser/service/notebook-context-manager.ts +162 -162
- package/src/browser/service/notebook-editor-widget-service.ts +101 -101
- package/src/browser/service/notebook-execution-service.ts +139 -139
- package/src/browser/service/notebook-execution-state-service.ts +311 -311
- package/src/browser/service/notebook-kernel-history-service.ts +124 -124
- package/src/browser/service/notebook-kernel-quick-pick-service.ts +479 -479
- package/src/browser/service/notebook-kernel-service.ts +357 -357
- package/src/browser/service/notebook-model-resolver-service.ts +160 -160
- package/src/browser/service/notebook-monaco-text-model-service.ts +48 -48
- package/src/browser/service/notebook-options.ts +155 -155
- package/src/browser/service/notebook-renderer-messaging-service.ts +121 -121
- package/src/browser/service/notebook-service.ts +215 -215
- package/src/browser/style/index.css +483 -471
- package/src/browser/view/notebook-cell-editor.tsx +263 -247
- package/src/browser/view/notebook-cell-list-view.tsx +279 -262
- package/src/browser/view/notebook-cell-toolbar-factory.tsx +102 -102
- package/src/browser/view/notebook-cell-toolbar.tsx +74 -74
- package/src/browser/view/notebook-code-cell-view.tsx +350 -350
- package/src/browser/view/notebook-find-widget.tsx +335 -335
- package/src/browser/view/notebook-main-toolbar.tsx +235 -235
- package/src/browser/view/notebook-markdown-cell-view.tsx +208 -208
- package/src/browser/view/notebook-viewport-service.ts +61 -61
- package/src/browser/view-model/notebook-cell-model.ts +473 -466
- package/src/browser/view-model/notebook-cell-output-model.ts +100 -100
- package/src/browser/view-model/notebook-model.ts +550 -550
- package/src/common/index.ts +18 -18
- package/src/common/notebook-common.ts +337 -337
- package/src/common/notebook-protocol.ts +35 -35
- package/src/common/notebook-range.ts +30 -30
|
@@ -1,262 +1,279 @@
|
|
|
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
|
-
import * as React from '@theia/core/shared/react';
|
|
17
|
-
import { CellEditType, CellKind, NotebookCellsChangeType } from '../../common';
|
|
18
|
-
import { NotebookCellModel } from '../view-model/notebook-cell-model';
|
|
19
|
-
import { NotebookModel } from '../view-model/notebook-model';
|
|
20
|
-
import { NotebookCellToolbarFactory } from './notebook-cell-toolbar-factory';
|
|
21
|
-
import { animationFrame,
|
|
22
|
-
import { CommandRegistry, DisposableCollection, nls } from '@theia/core';
|
|
23
|
-
import { NotebookCommands } from '../contributions/notebook-actions-contribution';
|
|
24
|
-
import { NotebookCellActionContribution } from '../contributions/notebook-cell-actions-contribution';
|
|
25
|
-
import { NotebookContextManager } from '../service/notebook-context-manager';
|
|
26
|
-
|
|
27
|
-
export interface CellRenderer {
|
|
28
|
-
render(notebookData: NotebookModel, cell: NotebookCellModel, index: number): React.ReactNode
|
|
29
|
-
renderDragImage(cell: NotebookCellModel): HTMLElement
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
interface CellListProps {
|
|
33
|
-
renderers: Map<CellKind, CellRenderer>;
|
|
34
|
-
notebookModel: NotebookModel;
|
|
35
|
-
notebookContext: NotebookContextManager;
|
|
36
|
-
toolbarRenderer: NotebookCellToolbarFactory;
|
|
37
|
-
commandRegistry: CommandRegistry
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
protected
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
this.
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
let
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
this.props.notebookContext.
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
event.
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
event.
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
protected
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
protected
|
|
228
|
-
|
|
229
|
-
this.
|
|
230
|
-
this.
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
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
|
+
import * as React from '@theia/core/shared/react';
|
|
17
|
+
import { CellEditType, CellKind, NotebookCellsChangeType } from '../../common';
|
|
18
|
+
import { NotebookCellModel } from '../view-model/notebook-cell-model';
|
|
19
|
+
import { NotebookModel } from '../view-model/notebook-model';
|
|
20
|
+
import { NotebookCellToolbarFactory } from './notebook-cell-toolbar-factory';
|
|
21
|
+
import { animationFrame, onDomEvent } from '@theia/core/lib/browser';
|
|
22
|
+
import { CommandRegistry, DisposableCollection, MenuModelRegistry, MenuNode, nls } from '@theia/core';
|
|
23
|
+
import { NotebookCommands, NotebookMenus } from '../contributions/notebook-actions-contribution';
|
|
24
|
+
import { NotebookCellActionContribution } from '../contributions/notebook-cell-actions-contribution';
|
|
25
|
+
import { NotebookContextManager } from '../service/notebook-context-manager';
|
|
26
|
+
|
|
27
|
+
export interface CellRenderer {
|
|
28
|
+
render(notebookData: NotebookModel, cell: NotebookCellModel, index: number): React.ReactNode
|
|
29
|
+
renderDragImage(cell: NotebookCellModel): HTMLElement
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
interface CellListProps {
|
|
33
|
+
renderers: Map<CellKind, CellRenderer>;
|
|
34
|
+
notebookModel: NotebookModel;
|
|
35
|
+
notebookContext: NotebookContextManager;
|
|
36
|
+
toolbarRenderer: NotebookCellToolbarFactory;
|
|
37
|
+
commandRegistry: CommandRegistry;
|
|
38
|
+
menuRegistry: MenuModelRegistry;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
interface NotebookCellListState {
|
|
42
|
+
selectedCell?: NotebookCellModel;
|
|
43
|
+
scrollIntoView: boolean;
|
|
44
|
+
dragOverIndicator: { cell: NotebookCellModel, position: 'top' | 'bottom' } | undefined;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export class NotebookCellListView extends React.Component<CellListProps, NotebookCellListState> {
|
|
48
|
+
|
|
49
|
+
protected toDispose = new DisposableCollection();
|
|
50
|
+
|
|
51
|
+
protected static dragGhost: HTMLElement | undefined;
|
|
52
|
+
protected cellListRef: React.RefObject<HTMLUListElement> = React.createRef();
|
|
53
|
+
|
|
54
|
+
constructor(props: CellListProps) {
|
|
55
|
+
super(props);
|
|
56
|
+
this.state = { selectedCell: props.notebookModel.selectedCell, dragOverIndicator: undefined, scrollIntoView: true };
|
|
57
|
+
this.toDispose.push(props.notebookModel.onDidAddOrRemoveCell(e => {
|
|
58
|
+
if (e.newCellIds && e.newCellIds.length > 0) {
|
|
59
|
+
this.setState({
|
|
60
|
+
...this.state,
|
|
61
|
+
selectedCell: this.props.notebookModel.cells.find(model => model.handle === e.newCellIds![e.newCellIds!.length - 1]),
|
|
62
|
+
scrollIntoView: true
|
|
63
|
+
});
|
|
64
|
+
} else {
|
|
65
|
+
this.setState({
|
|
66
|
+
...this.state,
|
|
67
|
+
selectedCell: this.props.notebookModel.cells.find(cell => cell === this.state.selectedCell),
|
|
68
|
+
scrollIntoView: false
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
}));
|
|
72
|
+
|
|
73
|
+
this.toDispose.push(props.notebookModel.onDidChangeContent(events => {
|
|
74
|
+
if (events.some(e => e.kind === NotebookCellsChangeType.Move)) {
|
|
75
|
+
// When a cell has been moved, we need to rerender the whole component
|
|
76
|
+
this.forceUpdate();
|
|
77
|
+
}
|
|
78
|
+
}));
|
|
79
|
+
|
|
80
|
+
this.toDispose.push(props.notebookModel.onDidChangeSelectedCell(e => {
|
|
81
|
+
this.setState({
|
|
82
|
+
...this.state,
|
|
83
|
+
selectedCell: e.cell,
|
|
84
|
+
scrollIntoView: e.scrollIntoView
|
|
85
|
+
});
|
|
86
|
+
}));
|
|
87
|
+
|
|
88
|
+
this.toDispose.push(onDomEvent(document, 'focusin', () => {
|
|
89
|
+
animationFrame().then(() => {
|
|
90
|
+
if (!this.cellListRef.current) {
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
let hasCellFocus = false;
|
|
94
|
+
let hasFocus = false;
|
|
95
|
+
if (this.cellListRef.current.contains(document.activeElement)) {
|
|
96
|
+
if (this.props.notebookModel.selectedCell) {
|
|
97
|
+
hasCellFocus = true;
|
|
98
|
+
}
|
|
99
|
+
hasFocus = true;
|
|
100
|
+
}
|
|
101
|
+
this.props.notebookContext.changeCellFocus(hasCellFocus);
|
|
102
|
+
this.props.notebookContext.changeCellListFocus(hasFocus);
|
|
103
|
+
});
|
|
104
|
+
}));
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
override componentWillUnmount(): void {
|
|
108
|
+
this.toDispose.dispose();
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
override render(): React.ReactNode {
|
|
112
|
+
return <ul className='theia-notebook-cell-list' ref={this.cellListRef}>
|
|
113
|
+
{this.props.notebookModel.cells
|
|
114
|
+
.map((cell, index) =>
|
|
115
|
+
<React.Fragment key={'cell-' + cell.handle}>
|
|
116
|
+
<NotebookCellDivider
|
|
117
|
+
menuRegistry={this.props.menuRegistry}
|
|
118
|
+
isVisible={() => this.isEnabled()}
|
|
119
|
+
onAddNewCell={(commandId: string) => this.onAddNewCell(commandId, index)}
|
|
120
|
+
onDrop={e => this.onDrop(e, index)}
|
|
121
|
+
onDragOver={e => this.onDragOver(e, cell, 'top')} />
|
|
122
|
+
{this.shouldRenderDragOverIndicator(cell, 'top') && <CellDropIndicator />}
|
|
123
|
+
<li className={'theia-notebook-cell' + (this.state.selectedCell === cell ? ' focused' : '') + (this.isEnabled() ? ' draggable' : '')}
|
|
124
|
+
onClick={e => {
|
|
125
|
+
this.setState({ ...this.state, selectedCell: cell });
|
|
126
|
+
this.props.notebookModel.setSelectedCell(cell, false);
|
|
127
|
+
}}
|
|
128
|
+
onDragStart={e => this.onDragStart(e, index, cell)}
|
|
129
|
+
onDragEnd={e => {
|
|
130
|
+
NotebookCellListView.dragGhost?.remove();
|
|
131
|
+
this.setState({ ...this.state, dragOverIndicator: undefined });
|
|
132
|
+
}}
|
|
133
|
+
onDragOver={e => this.onDragOver(e, cell)}
|
|
134
|
+
onDrop={e => this.onDrop(e, index)}
|
|
135
|
+
draggable={true}
|
|
136
|
+
tabIndex={-1}
|
|
137
|
+
ref={ref => {
|
|
138
|
+
if (ref && cell === this.state.selectedCell && this.state.scrollIntoView) {
|
|
139
|
+
ref.scrollIntoView({ block: 'nearest' });
|
|
140
|
+
if (cell.cellKind === CellKind.Markup && !cell.editing) {
|
|
141
|
+
ref.focus();
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}}>
|
|
145
|
+
<div className={'theia-notebook-cell-marker' + (this.state.selectedCell === cell ? ' theia-notebook-cell-marker-selected' : '')}></div>
|
|
146
|
+
<div className='theia-notebook-cell-content'>
|
|
147
|
+
{this.renderCellContent(cell, index)}
|
|
148
|
+
</div>
|
|
149
|
+
{this.state.selectedCell === cell &&
|
|
150
|
+
this.props.toolbarRenderer.renderCellToolbar(NotebookCellActionContribution.ACTION_MENU, cell, {
|
|
151
|
+
contextMenuArgs: () => [cell], commandArgs: () => [this.props.notebookModel]
|
|
152
|
+
})
|
|
153
|
+
}
|
|
154
|
+
</li>
|
|
155
|
+
{this.shouldRenderDragOverIndicator(cell, 'bottom') && <CellDropIndicator />}
|
|
156
|
+
</React.Fragment>
|
|
157
|
+
)
|
|
158
|
+
}
|
|
159
|
+
<NotebookCellDivider
|
|
160
|
+
menuRegistry={this.props.menuRegistry}
|
|
161
|
+
isVisible={() => this.isEnabled()}
|
|
162
|
+
onAddNewCell={(commandId: string) => this.onAddNewCell(commandId, this.props.notebookModel.cells.length)}
|
|
163
|
+
onDrop={e => this.onDrop(e, this.props.notebookModel.cells.length - 1)}
|
|
164
|
+
onDragOver={e => this.onDragOver(e, this.props.notebookModel.cells[this.props.notebookModel.cells.length - 1], 'bottom')} />
|
|
165
|
+
</ul>;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
renderCellContent(cell: NotebookCellModel, index: number): React.ReactNode {
|
|
169
|
+
const renderer = this.props.renderers.get(cell.cellKind);
|
|
170
|
+
if (!renderer) {
|
|
171
|
+
throw new Error(`No renderer found for cell type ${cell.cellKind}`);
|
|
172
|
+
}
|
|
173
|
+
return renderer.render(this.props.notebookModel, cell, index);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
protected onDragStart(event: React.DragEvent<HTMLLIElement>, index: number, cell: NotebookCellModel): void {
|
|
177
|
+
event.stopPropagation();
|
|
178
|
+
if (!this.isEnabled()) {
|
|
179
|
+
event.preventDefault();
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
NotebookCellListView.dragGhost = document.createElement('div');
|
|
184
|
+
NotebookCellListView.dragGhost.classList.add('theia-notebook-drag-ghost-image');
|
|
185
|
+
NotebookCellListView.dragGhost.appendChild(this.props.renderers.get(cell.cellKind)?.renderDragImage(cell) ?? document.createElement('div'));
|
|
186
|
+
document.body.appendChild(NotebookCellListView.dragGhost);
|
|
187
|
+
event.dataTransfer.setDragImage(NotebookCellListView.dragGhost, -10, 0);
|
|
188
|
+
|
|
189
|
+
event.dataTransfer.setData('text/theia-notebook-cell-index', index.toString());
|
|
190
|
+
event.dataTransfer.setData('text/plain', this.props.notebookModel.cells[index].source);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
protected onDragOver(event: React.DragEvent<HTMLLIElement>, cell: NotebookCellModel, position?: 'top' | 'bottom'): void {
|
|
194
|
+
if (!this.isEnabled()) {
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
event.preventDefault();
|
|
198
|
+
event.stopPropagation();
|
|
199
|
+
// show indicator
|
|
200
|
+
this.setState({ ...this.state, dragOverIndicator: { cell, position: position ?? event.nativeEvent.offsetY < event.currentTarget.clientHeight / 2 ? 'top' : 'bottom' } });
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
protected isEnabled(): boolean {
|
|
204
|
+
return !Boolean(this.props.notebookModel.readOnly);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
protected onDrop(event: React.DragEvent<HTMLLIElement>, dropElementIndex: number): void {
|
|
208
|
+
if (!this.isEnabled()) {
|
|
209
|
+
this.setState({ dragOverIndicator: undefined });
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
const index = parseInt(event.dataTransfer.getData('text/theia-notebook-cell-index'));
|
|
213
|
+
const isTargetBelow = index < dropElementIndex;
|
|
214
|
+
let newIdx = this.state.dragOverIndicator?.position === 'top' ? dropElementIndex : dropElementIndex + 1;
|
|
215
|
+
newIdx = isTargetBelow ? newIdx - 1 : newIdx;
|
|
216
|
+
if (index !== undefined && index !== dropElementIndex) {
|
|
217
|
+
this.props.notebookModel.applyEdits([{
|
|
218
|
+
editType: CellEditType.Move,
|
|
219
|
+
length: 1,
|
|
220
|
+
index,
|
|
221
|
+
newIdx
|
|
222
|
+
}], true);
|
|
223
|
+
}
|
|
224
|
+
this.setState({ ...this.state, dragOverIndicator: undefined });
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
protected onAddNewCell(commandId: string, index: number): void {
|
|
228
|
+
if (this.isEnabled()) {
|
|
229
|
+
this.props.commandRegistry.executeCommand(NotebookCommands.CHANGE_SELECTED_CELL.id, index - 1);
|
|
230
|
+
this.props.commandRegistry.executeCommand(commandId,
|
|
231
|
+
this.props.notebookModel,
|
|
232
|
+
index
|
|
233
|
+
);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
protected shouldRenderDragOverIndicator(cell: NotebookCellModel, position: 'top' | 'bottom'): boolean {
|
|
238
|
+
return this.isEnabled() &&
|
|
239
|
+
this.state.dragOverIndicator !== undefined &&
|
|
240
|
+
this.state.dragOverIndicator.cell === cell &&
|
|
241
|
+
this.state.dragOverIndicator.position === position;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
export interface NotebookCellDividerProps {
|
|
247
|
+
isVisible: () => boolean;
|
|
248
|
+
onAddNewCell: (commandId: string) => void;
|
|
249
|
+
onDrop: (event: React.DragEvent<HTMLLIElement>) => void;
|
|
250
|
+
onDragOver: (event: React.DragEvent<HTMLLIElement>) => void;
|
|
251
|
+
menuRegistry: MenuModelRegistry;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
export function NotebookCellDivider({ isVisible, onAddNewCell, onDrop, onDragOver, menuRegistry }: NotebookCellDividerProps): React.JSX.Element {
|
|
255
|
+
const [hover, setHover] = React.useState(false);
|
|
256
|
+
|
|
257
|
+
const menuPath = NotebookMenus.NOTEBOOK_MAIN_TOOLBAR_CELL_ADD_GROUP;
|
|
258
|
+
const menuItems = menuRegistry.getMenuNode(menuPath).children;
|
|
259
|
+
|
|
260
|
+
const renderItem = (item: MenuNode): React.ReactNode => <button
|
|
261
|
+
key={item.id}
|
|
262
|
+
className='theia-notebook-add-cell-button'
|
|
263
|
+
onClick={() => onAddNewCell(item.command || '')}
|
|
264
|
+
title={nls.localizeByDefault(`Add ${item.label} Cell`)}
|
|
265
|
+
>
|
|
266
|
+
<div className={item.icon + ' theia-notebook-add-cell-button-icon'} />
|
|
267
|
+
<div className='theia-notebook-add-cell-button-text'>{item.label}</div>
|
|
268
|
+
</button>;
|
|
269
|
+
|
|
270
|
+
return <li className='theia-notebook-cell-divider' onMouseEnter={() => setHover(true)} onMouseLeave={() => setHover(false)} onDrop={onDrop} onDragOver={onDragOver}>
|
|
271
|
+
{hover && isVisible() && <div className='theia-notebook-add-cell-buttons'>
|
|
272
|
+
{menuItems.map((item: MenuNode) => renderItem(item))}
|
|
273
|
+
</div>}
|
|
274
|
+
</li>;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
function CellDropIndicator(): React.JSX.Element {
|
|
278
|
+
return <div className='theia-notebook-cell-drop-indicator' />;
|
|
279
|
+
}
|