@jupyterlab/cell-toolbar 4.0.0-alpha.18 → 4.0.0-alpha.20
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/lib/celltoolbartracker.js +8 -2
- package/lib/celltoolbartracker.js.map +1 -1
- package/package.json +16 -15
- package/src/celltoolbartracker.ts +433 -0
- package/src/index.ts +9 -0
- package/style/base.css +3 -7
|
@@ -36,7 +36,12 @@ export class CellToolbarTracker {
|
|
|
36
36
|
this._onToolbarChanged();
|
|
37
37
|
this._toolbar.changed.connect(this._onToolbarChanged, this);
|
|
38
38
|
// Only add the toolbar to the notebook's active cell (if any) once it has fully rendered and been revealed.
|
|
39
|
-
void panel.revealed.then(() =>
|
|
39
|
+
void panel.revealed.then(() => {
|
|
40
|
+
// Wait one frame (at 60 fps) for the panel to render the first cell, then display the cell toolbar on it if possible.
|
|
41
|
+
setTimeout(() => {
|
|
42
|
+
this._onActiveCellChanged(panel.content);
|
|
43
|
+
}, 1000 / 60);
|
|
44
|
+
});
|
|
40
45
|
// Check whether the toolbar should be rendered upon a layout change
|
|
41
46
|
panel.content.renderingLayoutChanged.connect(this._onActiveCellChanged, this);
|
|
42
47
|
// Handle subsequent changes of active cell.
|
|
@@ -311,7 +316,7 @@ const defaultToolbarItems = [
|
|
|
311
316
|
* Widget extension that creates a CellToolbarTracker each time a notebook is
|
|
312
317
|
* created.
|
|
313
318
|
*/
|
|
314
|
-
|
|
319
|
+
class CellBarExtension {
|
|
315
320
|
constructor(commands, toolbarFactory) {
|
|
316
321
|
this._commands = commands;
|
|
317
322
|
this._toolbarFactory = toolbarFactory !== null && toolbarFactory !== void 0 ? toolbarFactory : this.defaultToolbarFactory;
|
|
@@ -332,4 +337,5 @@ export class CellBarExtension {
|
|
|
332
337
|
}
|
|
333
338
|
}
|
|
334
339
|
CellBarExtension.FACTORY_NAME = 'Cell';
|
|
340
|
+
export { CellBarExtension };
|
|
335
341
|
//# sourceMappingURL=celltoolbartracker.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"celltoolbartracker.js","sourceRoot":"","sources":["../src/celltoolbartracker.ts"],"names":[],"mappings":"AAAA;;;+EAG+E;AAC/E,OAAO,EAAE,oBAAoB,EAAmB,MAAM,sBAAsB,CAAC;AAI7E,OAAO,EAAmB,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAC1E,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAGzC,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAG3C;;GAEG;AACH,MAAM,eAAe,GAAG;IACtB,YAAY;IACZ,gCAAgC;IAChC,gCAAgC;CACjC,CAAC;AAEF;;GAEG;AACH,MAAM,kBAAkB,GAAG,iBAAiB,CAAC;AAC7C,MAAM,eAAe,GAAG,cAAc,CAAC;AAEvC;;GAEG;AACH,MAAM,qBAAqB,GAAG,oBAAoB,CAAC;AAEnD;;GAEG;AACH,MAAM,OAAO,kBAAkB;IAC7B,YACE,KAAoB,EACpB,OAAsD;
|
|
1
|
+
{"version":3,"file":"celltoolbartracker.js","sourceRoot":"","sources":["../src/celltoolbartracker.ts"],"names":[],"mappings":"AAAA;;;+EAG+E;AAC/E,OAAO,EAAE,oBAAoB,EAAmB,MAAM,sBAAsB,CAAC;AAI7E,OAAO,EAAmB,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAC1E,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAGzC,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAG3C;;GAEG;AACH,MAAM,eAAe,GAAG;IACtB,YAAY;IACZ,gCAAgC;IAChC,gCAAgC;CACjC,CAAC;AAEF;;GAEG;AACH,MAAM,kBAAkB,GAAG,iBAAiB,CA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EAAE,mBAAmB;KAC1B;IACD;QACE,OAAO,EAAE,sBAAsB;QAC/B,IAAI,EAAE,aAAa;KACpB;CACF,CAAC;AAEF;;;GAGG;AACH,MAAa,gBAAgB;IAG3B,YACE,QAAyB,EACzB,cAEkD;QAElD,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC;QAC1B,IAAI,CAAC,eAAe,GAAG,cAAc,aAAd,cAAc,cAAd,cAAc,GAAI,IAAI,CAAC,qBAAqB,CAAC;IACtE,CAAC;IAED,IAAc,qBAAqB;QAGjC,MAAM,WAAW,GAAG,oBAAoB,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QACzD,OAAO,CAAC,MAAc,EAAE,EAAE,CACxB,IAAI,cAAc,CAAC;YACjB,MAAM,EAAE,mBAAmB,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE;gBACrC,OAAO;oBACL,IAAI,EAAE,IAAI,CAAC,IAAI;oBACf,MAAM,EAAE,WAAW,CAAC,gBAAgB,CAAC,YAAY,EAAE,MAAM,EAAE,IAAI,CAAC;iBACjE,CAAC;YACJ,CAAC,CAAC;SACH,CAAC,CAAC;IACP,CAAC;IAED,SAAS,CAAC,KAAoB;QAC5B,OAAO,IAAI,kBAAkB,CAAC,KAAK,EAAE,IAAI,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC,CAAC;IACpE,CAAC;;AA7BM,6BAAY,GAAG,MAAM,CAAC;SADlB,gBAAgB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jupyterlab/cell-toolbar",
|
|
3
|
-
"version": "4.0.0-alpha.
|
|
3
|
+
"version": "4.0.0-alpha.20",
|
|
4
4
|
"description": "Contextual cell toolbar adapted from jlab-enhanced-cell-toolbar",
|
|
5
5
|
"homepage": "https://github.com/jupyterlab/jupyterlab",
|
|
6
6
|
"bugs": {
|
|
@@ -26,7 +26,8 @@
|
|
|
26
26
|
"lib/**/*.{d.ts,eot,gif,html,jpg,js,js.map,json,png,svg,woff2,ttf}",
|
|
27
27
|
"schema/*.json",
|
|
28
28
|
"style/**/*.{css,eot,gif,html,jpg,json,png,svg,woff2,ttf}",
|
|
29
|
-
"style/index.js"
|
|
29
|
+
"style/index.js",
|
|
30
|
+
"src/**/*.{ts,tsx}"
|
|
30
31
|
],
|
|
31
32
|
"scripts": {
|
|
32
33
|
"build": "tsc -b",
|
|
@@ -39,23 +40,23 @@
|
|
|
39
40
|
"watch": "tsc -b --watch"
|
|
40
41
|
},
|
|
41
42
|
"dependencies": {
|
|
42
|
-
"@jupyterlab/apputils": "^4.0.0-alpha.
|
|
43
|
-
"@jupyterlab/cells": "^4.0.0-alpha.
|
|
44
|
-
"@jupyterlab/docregistry": "^4.0.0-alpha.
|
|
45
|
-
"@jupyterlab/notebook": "^4.0.0-alpha.
|
|
46
|
-
"@jupyterlab/observables": "^5.0.0-alpha.
|
|
47
|
-
"@jupyterlab/ui-components": "^4.0.0-alpha.
|
|
48
|
-
"@lumino/algorithm": "^2.0.0-
|
|
49
|
-
"@lumino/commands": "^2.0.0-
|
|
50
|
-
"@lumino/disposable": "^2.0.0-
|
|
51
|
-
"@lumino/signaling": "^2.0.0-
|
|
52
|
-
"@lumino/widgets": "^2.0.0-
|
|
43
|
+
"@jupyterlab/apputils": "^4.0.0-alpha.20",
|
|
44
|
+
"@jupyterlab/cells": "^4.0.0-alpha.20",
|
|
45
|
+
"@jupyterlab/docregistry": "^4.0.0-alpha.20",
|
|
46
|
+
"@jupyterlab/notebook": "^4.0.0-alpha.20",
|
|
47
|
+
"@jupyterlab/observables": "^5.0.0-alpha.20",
|
|
48
|
+
"@jupyterlab/ui-components": "^4.0.0-alpha.35",
|
|
49
|
+
"@lumino/algorithm": "^2.0.0-rc.0",
|
|
50
|
+
"@lumino/commands": "^2.0.0-rc.0",
|
|
51
|
+
"@lumino/disposable": "^2.0.0-rc.0",
|
|
52
|
+
"@lumino/signaling": "^2.0.0-rc.0",
|
|
53
|
+
"@lumino/widgets": "^2.0.0-rc.0"
|
|
53
54
|
},
|
|
54
55
|
"devDependencies": {
|
|
55
|
-
"@jupyterlab/testing": "^4.0.0-alpha.
|
|
56
|
+
"@jupyterlab/testing": "^4.0.0-alpha.20",
|
|
56
57
|
"@types/jest": "^29.2.0",
|
|
57
58
|
"rimraf": "~3.0.0",
|
|
58
|
-
"typescript": "~
|
|
59
|
+
"typescript": "~5.0.0-beta"
|
|
59
60
|
},
|
|
60
61
|
"publishConfig": {
|
|
61
62
|
"access": "public"
|
|
@@ -0,0 +1,433 @@
|
|
|
1
|
+
/* -----------------------------------------------------------------------------
|
|
2
|
+
| Copyright (c) Jupyter Development Team.
|
|
3
|
+
| Distributed under the terms of the Modified BSD License.
|
|
4
|
+
|----------------------------------------------------------------------------*/
|
|
5
|
+
import { createDefaultFactory, ToolbarRegistry } from '@jupyterlab/apputils';
|
|
6
|
+
import { Cell, CodeCell, ICellModel, MarkdownCell } from '@jupyterlab/cells';
|
|
7
|
+
import { DocumentRegistry } from '@jupyterlab/docregistry';
|
|
8
|
+
import { Notebook, NotebookPanel } from '@jupyterlab/notebook';
|
|
9
|
+
import { IObservableList, ObservableList } from '@jupyterlab/observables';
|
|
10
|
+
import { ReactWidget, Toolbar } from '@jupyterlab/ui-components';
|
|
11
|
+
import { some } from '@lumino/algorithm';
|
|
12
|
+
import { CommandRegistry } from '@lumino/commands';
|
|
13
|
+
import { IDisposable } from '@lumino/disposable';
|
|
14
|
+
import { Signal } from '@lumino/signaling';
|
|
15
|
+
import { PanelLayout, Widget } from '@lumino/widgets';
|
|
16
|
+
|
|
17
|
+
/*
|
|
18
|
+
* Text mime types
|
|
19
|
+
*/
|
|
20
|
+
const TEXT_MIME_TYPES = [
|
|
21
|
+
'text/plain',
|
|
22
|
+
'application/vnd.jupyter.stdout',
|
|
23
|
+
'application/vnd.jupyter.stderr'
|
|
24
|
+
];
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Widget cell toolbar classes
|
|
28
|
+
*/
|
|
29
|
+
const CELL_TOOLBAR_CLASS = 'jp-cell-toolbar';
|
|
30
|
+
const CELL_MENU_CLASS = 'jp-cell-menu';
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Class for a cell whose contents overlap with the cell toolbar
|
|
34
|
+
*/
|
|
35
|
+
const TOOLBAR_OVERLAP_CLASS = 'jp-toolbar-overlap';
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Watch a notebook so that a cell toolbar appears on the active cell
|
|
39
|
+
*/
|
|
40
|
+
export class CellToolbarTracker implements IDisposable {
|
|
41
|
+
constructor(
|
|
42
|
+
panel: NotebookPanel,
|
|
43
|
+
toolbar: IObservableList<ToolbarRegistry.IToolbarItem>
|
|
44
|
+
) {
|
|
45
|
+
this._panel = panel;
|
|
46
|
+
this._previousActiveCell = this._panel.content.activeCell;
|
|
47
|
+
this._toolbar = toolbar;
|
|
48
|
+
|
|
49
|
+
this._onToolbarChanged();
|
|
50
|
+
this._toolbar.changed.connect(this._onToolbarChanged, this);
|
|
51
|
+
|
|
52
|
+
// Only add the toolbar to the notebook's active cell (if any) once it has fully rendered and been revealed.
|
|
53
|
+
void panel.revealed.then(() => {
|
|
54
|
+
// Wait one frame (at 60 fps) for the panel to render the first cell, then display the cell toolbar on it if possible.
|
|
55
|
+
setTimeout(() => {
|
|
56
|
+
this._onActiveCellChanged(panel.content);
|
|
57
|
+
}, 1000 / 60);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
// Check whether the toolbar should be rendered upon a layout change
|
|
61
|
+
panel.content.renderingLayoutChanged.connect(
|
|
62
|
+
this._onActiveCellChanged,
|
|
63
|
+
this
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
// Handle subsequent changes of active cell.
|
|
67
|
+
panel.content.activeCellChanged.connect(this._onActiveCellChanged, this);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
_onActiveCellChanged(notebook: Notebook): void {
|
|
71
|
+
if (this._previousActiveCell && !this._previousActiveCell.isDisposed) {
|
|
72
|
+
// Disposed cells do not have a model anymore.
|
|
73
|
+
this._removeToolbar(this._previousActiveCell.model);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const activeCell = notebook.activeCell;
|
|
77
|
+
if (activeCell === null || activeCell.inputHidden) {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
this._addToolbar(activeCell.model);
|
|
82
|
+
this._previousActiveCell = activeCell;
|
|
83
|
+
|
|
84
|
+
this._updateCellForToolbarOverlap(activeCell);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
get isDisposed(): boolean {
|
|
88
|
+
return this._isDisposed;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
dispose(): void {
|
|
92
|
+
if (this.isDisposed) {
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
this._isDisposed = true;
|
|
96
|
+
|
|
97
|
+
this._toolbar.changed.disconnect(this._onToolbarChanged, this);
|
|
98
|
+
|
|
99
|
+
const cells = this._panel?.context.model.cells;
|
|
100
|
+
if (cells) {
|
|
101
|
+
for (const model of cells) {
|
|
102
|
+
this._removeToolbar(model);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
this._panel = null;
|
|
107
|
+
|
|
108
|
+
Signal.clearData(this);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
private _addToolbar(model: ICellModel): void {
|
|
112
|
+
const cell = this._getCell(model);
|
|
113
|
+
|
|
114
|
+
if (cell) {
|
|
115
|
+
const toolbarWidget = new Toolbar();
|
|
116
|
+
toolbarWidget.addClass(CELL_MENU_CLASS);
|
|
117
|
+
|
|
118
|
+
const promises: Promise<void>[] = [];
|
|
119
|
+
for (const { name, widget } of this._toolbar) {
|
|
120
|
+
toolbarWidget.addItem(name, widget);
|
|
121
|
+
if (
|
|
122
|
+
widget instanceof ReactWidget &&
|
|
123
|
+
(widget as ReactWidget).renderPromise !== undefined
|
|
124
|
+
) {
|
|
125
|
+
promises.push((widget as ReactWidget).renderPromise!);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// Wait for all the buttons to be rendered before attaching the toolbar.
|
|
130
|
+
Promise.all(promises)
|
|
131
|
+
.then(() => {
|
|
132
|
+
toolbarWidget.addClass(CELL_TOOLBAR_CLASS);
|
|
133
|
+
(cell.layout as PanelLayout).insertWidget(0, toolbarWidget);
|
|
134
|
+
|
|
135
|
+
// For rendered markdown, watch for resize events.
|
|
136
|
+
cell.displayChanged.connect(this._resizeEventCallback, this);
|
|
137
|
+
|
|
138
|
+
// Watch for changes in the cell's contents.
|
|
139
|
+
cell.model.contentChanged.connect(this._changedEventCallback, this);
|
|
140
|
+
})
|
|
141
|
+
.catch(() => {
|
|
142
|
+
console.error('Error rendering buttons of the cell toolbar');
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
private _getCell(model: ICellModel): Cell | undefined {
|
|
148
|
+
return this._panel?.content.widgets.find(widget => widget.model === model);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
private _findToolbarWidgets(cell: Cell): Widget[] {
|
|
152
|
+
const widgets = (cell.layout as PanelLayout).widgets;
|
|
153
|
+
|
|
154
|
+
// Search for header using the CSS class or use the first one if not found.
|
|
155
|
+
return widgets.filter(widget => widget.hasClass(CELL_TOOLBAR_CLASS)) || [];
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
private _removeToolbar(model: ICellModel): void {
|
|
159
|
+
const cell = this._getCell(model);
|
|
160
|
+
if (cell) {
|
|
161
|
+
this._findToolbarWidgets(cell).forEach(widget => {
|
|
162
|
+
widget.dispose();
|
|
163
|
+
});
|
|
164
|
+
// Attempt to remove the resize and changed event handlers.
|
|
165
|
+
cell.displayChanged.disconnect(this._resizeEventCallback, this);
|
|
166
|
+
}
|
|
167
|
+
model.contentChanged.disconnect(this._changedEventCallback, this);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Call back on settings changes
|
|
172
|
+
*/
|
|
173
|
+
private _onToolbarChanged(): void {
|
|
174
|
+
// Reset toolbar when settings changes
|
|
175
|
+
const activeCell: Cell<ICellModel> | null | undefined =
|
|
176
|
+
this._panel?.content.activeCell;
|
|
177
|
+
if (activeCell) {
|
|
178
|
+
this._removeToolbar(activeCell.model);
|
|
179
|
+
this._addToolbar(activeCell.model);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
private _changedEventCallback(): void {
|
|
184
|
+
const activeCell = this._panel?.content.activeCell;
|
|
185
|
+
if (activeCell === null || activeCell === undefined) {
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
this._updateCellForToolbarOverlap(activeCell);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
private _resizeEventCallback(): void {
|
|
193
|
+
const activeCell = this._panel?.content.activeCell;
|
|
194
|
+
if (activeCell === null || activeCell === undefined) {
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
this._updateCellForToolbarOverlap(activeCell);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
private _updateCellForToolbarOverlap(activeCell: Cell<ICellModel>) {
|
|
202
|
+
// Remove the "toolbar overlap" class from the cell, rendering the cell's toolbar
|
|
203
|
+
const activeCellElement = activeCell.node;
|
|
204
|
+
activeCellElement.classList.remove(TOOLBAR_OVERLAP_CLASS);
|
|
205
|
+
|
|
206
|
+
if (this._cellToolbarOverlapsContents(activeCell)) {
|
|
207
|
+
// Add the "toolbar overlap" class to the cell, completely concealing the toolbar,
|
|
208
|
+
// if the first line of the content overlaps with it at all
|
|
209
|
+
activeCellElement.classList.add(TOOLBAR_OVERLAP_CLASS);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
private _cellToolbarOverlapsContents(activeCell: Cell<ICellModel>): boolean {
|
|
214
|
+
const cellType = activeCell.model.type;
|
|
215
|
+
|
|
216
|
+
// If the toolbar is too large for the current cell, hide it.
|
|
217
|
+
const cellLeft = this._cellEditorWidgetLeft(activeCell);
|
|
218
|
+
const cellRight = this._cellEditorWidgetRight(activeCell);
|
|
219
|
+
const toolbarLeft = this._cellToolbarLeft(activeCell);
|
|
220
|
+
|
|
221
|
+
if (toolbarLeft === null) {
|
|
222
|
+
return false;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
// The toolbar should not take up more than 50% of the cell.
|
|
226
|
+
if ((cellLeft + cellRight) / 2 > toolbarLeft) {
|
|
227
|
+
return true;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
if (cellType === 'markdown' && (activeCell as MarkdownCell).rendered) {
|
|
231
|
+
// Check for overlap in rendered markdown content
|
|
232
|
+
return this._markdownOverlapsToolbar(activeCell as MarkdownCell);
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
// Check for overlap in code content
|
|
236
|
+
if (this._panel?.content.renderingLayout === 'default') {
|
|
237
|
+
return this._codeOverlapsToolbar(activeCell);
|
|
238
|
+
} else {
|
|
239
|
+
return this._outputOverlapsToolbar(activeCell);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* Check for overlap between rendered Markdown and the cell toolbar
|
|
245
|
+
*
|
|
246
|
+
* @param activeCell A rendered MarkdownCell
|
|
247
|
+
* @returns `true` if the first line of the output overlaps with the cell toolbar, `false` otherwise
|
|
248
|
+
*/
|
|
249
|
+
private _markdownOverlapsToolbar(activeCell: MarkdownCell): boolean {
|
|
250
|
+
const markdownOutput = activeCell.inputArea; // Rendered markdown appears in the input area
|
|
251
|
+
if (!markdownOutput) {
|
|
252
|
+
return false;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
// Get the rendered markdown as a widget.
|
|
256
|
+
const markdownOutputWidget = markdownOutput.renderedInput;
|
|
257
|
+
const markdownOutputElement = markdownOutputWidget.node;
|
|
258
|
+
|
|
259
|
+
const firstOutputElementChild =
|
|
260
|
+
markdownOutputElement.firstElementChild as HTMLElement;
|
|
261
|
+
if (firstOutputElementChild === null) {
|
|
262
|
+
return false;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
// Temporarily set the element's max width so that the bounding client rectangle only encompasses the content.
|
|
266
|
+
const oldMaxWidth = firstOutputElementChild.style.maxWidth;
|
|
267
|
+
firstOutputElementChild.style.maxWidth = 'max-content';
|
|
268
|
+
|
|
269
|
+
const lineRight = firstOutputElementChild.getBoundingClientRect().right;
|
|
270
|
+
|
|
271
|
+
// Reinstate the old max width.
|
|
272
|
+
firstOutputElementChild.style.maxWidth = oldMaxWidth;
|
|
273
|
+
|
|
274
|
+
const toolbarLeft = this._cellToolbarLeft(activeCell);
|
|
275
|
+
|
|
276
|
+
return toolbarLeft === null ? false : lineRight > toolbarLeft;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
private _outputOverlapsToolbar(activeCell: Cell<ICellModel>): boolean {
|
|
280
|
+
const outputArea = (activeCell as CodeCell).outputArea.node;
|
|
281
|
+
if (outputArea) {
|
|
282
|
+
const outputs = outputArea.querySelectorAll('[data-mime-type]');
|
|
283
|
+
const toolbarRect = this._cellToolbarRect(activeCell);
|
|
284
|
+
if (toolbarRect) {
|
|
285
|
+
const { left: toolbarLeft, bottom: toolbarBottom } = toolbarRect;
|
|
286
|
+
return some(outputs, output => {
|
|
287
|
+
const node = output.firstElementChild;
|
|
288
|
+
if (node) {
|
|
289
|
+
const range = new Range();
|
|
290
|
+
if (
|
|
291
|
+
TEXT_MIME_TYPES.includes(
|
|
292
|
+
output.getAttribute('data-mime-type') || ''
|
|
293
|
+
)
|
|
294
|
+
) {
|
|
295
|
+
// If the node is plain text, it's in a <pre>. To get the true bounding box of the
|
|
296
|
+
// text, the node contents need to be selected.
|
|
297
|
+
range.selectNodeContents(node);
|
|
298
|
+
} else {
|
|
299
|
+
range.selectNode(node);
|
|
300
|
+
}
|
|
301
|
+
const { right: nodeRight, top: nodeTop } =
|
|
302
|
+
range.getBoundingClientRect();
|
|
303
|
+
|
|
304
|
+
// Note: y-coordinate increases toward the bottom of page
|
|
305
|
+
return nodeRight > toolbarLeft && nodeTop < toolbarBottom;
|
|
306
|
+
}
|
|
307
|
+
return false;
|
|
308
|
+
});
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
return false;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
private _codeOverlapsToolbar(activeCell: Cell<ICellModel>): boolean {
|
|
315
|
+
const editorWidget = activeCell.editorWidget;
|
|
316
|
+
const editor = activeCell.editor;
|
|
317
|
+
if (!editorWidget || !editor) {
|
|
318
|
+
return false;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
if (editor.lineCount < 1) {
|
|
322
|
+
return false; // Nothing in the editor
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
const codeMirrorLines =
|
|
326
|
+
editorWidget.node.getElementsByClassName('CodeMirror-line');
|
|
327
|
+
if (codeMirrorLines.length < 1) {
|
|
328
|
+
return false; // No lines present
|
|
329
|
+
}
|
|
330
|
+
const lineRight = codeMirrorLines[0].children[0] // First span under first pre
|
|
331
|
+
.getBoundingClientRect().right;
|
|
332
|
+
|
|
333
|
+
const toolbarLeft = this._cellToolbarLeft(activeCell);
|
|
334
|
+
|
|
335
|
+
return toolbarLeft === null ? false : lineRight > toolbarLeft;
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
private _cellEditorWidgetLeft(activeCell: Cell<ICellModel>): number {
|
|
339
|
+
return activeCell.editorWidget?.node.getBoundingClientRect().left ?? 0;
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
private _cellEditorWidgetRight(activeCell: Cell<ICellModel>): number {
|
|
343
|
+
return activeCell.editorWidget?.node.getBoundingClientRect().right ?? 0;
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
private _cellToolbarRect(activeCell: Cell<ICellModel>): DOMRect | null {
|
|
347
|
+
const toolbarWidgets = this._findToolbarWidgets(activeCell);
|
|
348
|
+
if (toolbarWidgets.length < 1) {
|
|
349
|
+
return null;
|
|
350
|
+
}
|
|
351
|
+
const activeCellToolbar = toolbarWidgets[0].node;
|
|
352
|
+
|
|
353
|
+
return activeCellToolbar.getBoundingClientRect();
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
private _cellToolbarLeft(activeCell: Cell<ICellModel>): number | null {
|
|
357
|
+
return this._cellToolbarRect(activeCell)?.left || null;
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
private _isDisposed = false;
|
|
361
|
+
private _panel: NotebookPanel | null;
|
|
362
|
+
private _previousActiveCell: Cell<ICellModel> | null;
|
|
363
|
+
private _toolbar: IObservableList<ToolbarRegistry.IToolbarItem>;
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
const defaultToolbarItems: ToolbarRegistry.IWidget[] = [
|
|
367
|
+
{
|
|
368
|
+
command: 'notebook:duplicate-below',
|
|
369
|
+
name: 'duplicate-cell'
|
|
370
|
+
},
|
|
371
|
+
{
|
|
372
|
+
command: 'notebook:move-cell-up',
|
|
373
|
+
name: 'move-cell-up'
|
|
374
|
+
},
|
|
375
|
+
{
|
|
376
|
+
command: 'notebook:move-cell-down',
|
|
377
|
+
name: 'move-cell-down'
|
|
378
|
+
},
|
|
379
|
+
{
|
|
380
|
+
command: 'notebook:insert-cell-above',
|
|
381
|
+
name: 'insert-cell-above'
|
|
382
|
+
},
|
|
383
|
+
{
|
|
384
|
+
command: 'notebook:insert-cell-below',
|
|
385
|
+
name: 'insert-cell-below'
|
|
386
|
+
},
|
|
387
|
+
{
|
|
388
|
+
command: 'notebook:delete-cell',
|
|
389
|
+
name: 'delete-cell'
|
|
390
|
+
}
|
|
391
|
+
];
|
|
392
|
+
|
|
393
|
+
/**
|
|
394
|
+
* Widget extension that creates a CellToolbarTracker each time a notebook is
|
|
395
|
+
* created.
|
|
396
|
+
*/
|
|
397
|
+
export class CellBarExtension implements DocumentRegistry.WidgetExtension {
|
|
398
|
+
static FACTORY_NAME = 'Cell';
|
|
399
|
+
|
|
400
|
+
constructor(
|
|
401
|
+
commands: CommandRegistry,
|
|
402
|
+
toolbarFactory?: (
|
|
403
|
+
widget: Widget
|
|
404
|
+
) => IObservableList<ToolbarRegistry.IToolbarItem>
|
|
405
|
+
) {
|
|
406
|
+
this._commands = commands;
|
|
407
|
+
this._toolbarFactory = toolbarFactory ?? this.defaultToolbarFactory;
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
protected get defaultToolbarFactory(): (
|
|
411
|
+
widget: Widget
|
|
412
|
+
) => IObservableList<ToolbarRegistry.IToolbarItem> {
|
|
413
|
+
const itemFactory = createDefaultFactory(this._commands);
|
|
414
|
+
return (widget: Widget) =>
|
|
415
|
+
new ObservableList({
|
|
416
|
+
values: defaultToolbarItems.map(item => {
|
|
417
|
+
return {
|
|
418
|
+
name: item.name,
|
|
419
|
+
widget: itemFactory(CellBarExtension.FACTORY_NAME, widget, item)
|
|
420
|
+
};
|
|
421
|
+
})
|
|
422
|
+
});
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
createNew(panel: NotebookPanel): IDisposable {
|
|
426
|
+
return new CellToolbarTracker(panel, this._toolbarFactory(panel));
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
private _commands: CommandRegistry;
|
|
430
|
+
private _toolbarFactory: (
|
|
431
|
+
widget: Widget
|
|
432
|
+
) => IObservableList<ToolbarRegistry.IToolbarItem>;
|
|
433
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/* -----------------------------------------------------------------------------
|
|
2
|
+
| Copyright (c) Jupyter Development Team.
|
|
3
|
+
| Distributed under the terms of the Modified BSD License.
|
|
4
|
+
|----------------------------------------------------------------------------*/
|
|
5
|
+
/**
|
|
6
|
+
* @packageDocumentation
|
|
7
|
+
* @module cell-toolbar
|
|
8
|
+
*/
|
|
9
|
+
export * from './celltoolbartracker';
|
package/style/base.css
CHANGED
|
@@ -31,14 +31,10 @@
|
|
|
31
31
|
box-shadow: inherit;
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
/* Overrides for mobile view
|
|
34
|
+
/* Overrides for mobile view hiding cell toolbar */
|
|
35
35
|
@media only screen and (max-width: 760px) {
|
|
36
|
-
.jp-
|
|
37
|
-
display:
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
.jp-cell-toolbar {
|
|
41
|
-
top: -5px;
|
|
36
|
+
.jp-cell-menu.jp-cell-toolbar {
|
|
37
|
+
display: none;
|
|
42
38
|
}
|
|
43
39
|
}
|
|
44
40
|
|