@jupyter-notebook/application 7.0.0-alpha.8 → 7.0.0-alpha.9
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/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/lib/panelhandler.d.ts +212 -0
- package/lib/panelhandler.js +329 -0
- package/lib/shell.d.ts +4 -111
- package/lib/shell.js +7 -271
- package/package.json +7 -7
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
import { ICommandPalette } from '@jupyterlab/apputils';
|
|
2
|
+
import { IDisposable } from '@lumino/disposable';
|
|
3
|
+
import { ISignal } from '@lumino/signaling';
|
|
4
|
+
import { Panel, Widget } from '@lumino/widgets';
|
|
5
|
+
/**
|
|
6
|
+
* A class which manages a panel and sorts its widgets by rank.
|
|
7
|
+
*/
|
|
8
|
+
export declare class PanelHandler {
|
|
9
|
+
constructor();
|
|
10
|
+
/**
|
|
11
|
+
* Get the panel managed by the handler.
|
|
12
|
+
*/
|
|
13
|
+
get panel(): Panel;
|
|
14
|
+
/**
|
|
15
|
+
* Add a widget to the panel.
|
|
16
|
+
*
|
|
17
|
+
* If the widget is already added, it will be moved.
|
|
18
|
+
*/
|
|
19
|
+
addWidget(widget: Widget, rank: number): void;
|
|
20
|
+
/**
|
|
21
|
+
* A message hook for child add/remove messages on the main area dock panel.
|
|
22
|
+
*/
|
|
23
|
+
private _panelChildHook;
|
|
24
|
+
protected _items: Private.IRankItem[];
|
|
25
|
+
protected _panel: Panel;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* A class which manages a side panel that can show at most one widget at a time.
|
|
29
|
+
*/
|
|
30
|
+
export declare class SidePanelHandler extends PanelHandler {
|
|
31
|
+
/**
|
|
32
|
+
* Construct a new side panel handler.
|
|
33
|
+
*/
|
|
34
|
+
constructor(area: SidePanel.Area);
|
|
35
|
+
/**
|
|
36
|
+
* Get the current widget in the sidebar panel.
|
|
37
|
+
*/
|
|
38
|
+
get currentWidget(): Widget | null;
|
|
39
|
+
/**
|
|
40
|
+
* Get the area of the side panel
|
|
41
|
+
*/
|
|
42
|
+
get area(): SidePanel.Area;
|
|
43
|
+
/**
|
|
44
|
+
* Whether the panel is visible
|
|
45
|
+
*/
|
|
46
|
+
get isVisible(): boolean;
|
|
47
|
+
/**
|
|
48
|
+
* Get the stacked panel managed by the handler
|
|
49
|
+
*/
|
|
50
|
+
get panel(): Panel;
|
|
51
|
+
/**
|
|
52
|
+
* Get the widgets list.
|
|
53
|
+
*/
|
|
54
|
+
get widgets(): Readonly<Widget[]>;
|
|
55
|
+
/**
|
|
56
|
+
* Signal fired when a widget is added to the panel
|
|
57
|
+
*/
|
|
58
|
+
get widgetAdded(): ISignal<SidePanelHandler, Widget>;
|
|
59
|
+
/**
|
|
60
|
+
* Signal fired when a widget is removed from the panel
|
|
61
|
+
*/
|
|
62
|
+
get widgetRemoved(): ISignal<SidePanelHandler, Widget>;
|
|
63
|
+
/**
|
|
64
|
+
* Expand the sidebar.
|
|
65
|
+
*
|
|
66
|
+
* #### Notes
|
|
67
|
+
* This will open the most recently used widget, or the first widget
|
|
68
|
+
* if there is no most recently used.
|
|
69
|
+
*/
|
|
70
|
+
expand(id?: string): void;
|
|
71
|
+
/**
|
|
72
|
+
* Activate a widget residing in the stacked panel by ID.
|
|
73
|
+
*
|
|
74
|
+
* @param id - The widget's unique ID.
|
|
75
|
+
*/
|
|
76
|
+
activate(id: string): void;
|
|
77
|
+
/**
|
|
78
|
+
* Test whether the sidebar has the given widget by id.
|
|
79
|
+
*/
|
|
80
|
+
has(id: string): boolean;
|
|
81
|
+
/**
|
|
82
|
+
* Collapse the sidebar so no items are expanded.
|
|
83
|
+
*/
|
|
84
|
+
collapse(): void;
|
|
85
|
+
/**
|
|
86
|
+
* Add a widget and its title to the stacked panel.
|
|
87
|
+
*
|
|
88
|
+
* If the widget is already added, it will be moved.
|
|
89
|
+
*/
|
|
90
|
+
addWidget(widget: Widget, rank: number): void;
|
|
91
|
+
/**
|
|
92
|
+
* Hide the side panel
|
|
93
|
+
*/
|
|
94
|
+
hide(): void;
|
|
95
|
+
/**
|
|
96
|
+
* Show the side panel
|
|
97
|
+
*/
|
|
98
|
+
show(): void;
|
|
99
|
+
/**
|
|
100
|
+
* Find the insertion index for a rank item.
|
|
101
|
+
*/
|
|
102
|
+
private _findInsertIndex;
|
|
103
|
+
/**
|
|
104
|
+
* Find the index of the item with the given widget, or `-1`.
|
|
105
|
+
*/
|
|
106
|
+
private _findWidgetIndex;
|
|
107
|
+
/**
|
|
108
|
+
* Find the widget with the given id, or `null`.
|
|
109
|
+
*/
|
|
110
|
+
private _findWidgetByID;
|
|
111
|
+
/**
|
|
112
|
+
* Refresh the visibility of the stacked panel.
|
|
113
|
+
*/
|
|
114
|
+
private _refreshVisibility;
|
|
115
|
+
private _onWidgetRemoved;
|
|
116
|
+
private _area;
|
|
117
|
+
private _isHiddenByUser;
|
|
118
|
+
private _widgetPanel;
|
|
119
|
+
private _currentWidget;
|
|
120
|
+
private _lastCurrentWidget;
|
|
121
|
+
private _widgetAdded;
|
|
122
|
+
private _widgetRemoved;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* A name space for SideBarPanel functions.
|
|
126
|
+
*/
|
|
127
|
+
export declare namespace SidePanel {
|
|
128
|
+
/**
|
|
129
|
+
* The areas of the sidebar panel
|
|
130
|
+
*/
|
|
131
|
+
type Area = 'left' | 'right';
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* A class to manages the palette entries associated to the side panels.
|
|
135
|
+
*/
|
|
136
|
+
export declare class SidePanelPalette {
|
|
137
|
+
/**
|
|
138
|
+
* Construct a new side panel palette.
|
|
139
|
+
*/
|
|
140
|
+
constructor(options: SidePanelPaletteOption);
|
|
141
|
+
/**
|
|
142
|
+
* Get a command palette item from the widget id and the area.
|
|
143
|
+
*/
|
|
144
|
+
getItem(widget: Readonly<Widget>, area: 'left' | 'right'): SidePanelPaletteItem | null;
|
|
145
|
+
/**
|
|
146
|
+
* Add an item to the command palette.
|
|
147
|
+
*/
|
|
148
|
+
addItem(widget: Readonly<Widget>, area: 'left' | 'right'): void;
|
|
149
|
+
/**
|
|
150
|
+
* Remove an item from the command palette.
|
|
151
|
+
*/
|
|
152
|
+
removeItem(widget: Readonly<Widget>, area: 'left' | 'right'): void;
|
|
153
|
+
_command: string;
|
|
154
|
+
_commandPalette: ICommandPalette;
|
|
155
|
+
_items: SidePanelPaletteItem[];
|
|
156
|
+
}
|
|
157
|
+
declare type SidePanelPaletteItem = {
|
|
158
|
+
/**
|
|
159
|
+
* The ID of the widget associated to the command palette.
|
|
160
|
+
*/
|
|
161
|
+
widgetId: string;
|
|
162
|
+
/**
|
|
163
|
+
* The area of the panel associated to the command palette.
|
|
164
|
+
*/
|
|
165
|
+
area: 'left' | 'right';
|
|
166
|
+
/**
|
|
167
|
+
* The disposable object to remove the item from command palette.
|
|
168
|
+
*/
|
|
169
|
+
disposable: IDisposable;
|
|
170
|
+
};
|
|
171
|
+
/**
|
|
172
|
+
* An interface for the options to include in SideBarPalette constructor.
|
|
173
|
+
*/
|
|
174
|
+
declare type SidePanelPaletteOption = {
|
|
175
|
+
/**
|
|
176
|
+
* The commands palette.
|
|
177
|
+
*/
|
|
178
|
+
commandPalette: ICommandPalette;
|
|
179
|
+
/**
|
|
180
|
+
* The command to call from each side panel menu entry.
|
|
181
|
+
*
|
|
182
|
+
* ### Notes
|
|
183
|
+
* That command required 3 args :
|
|
184
|
+
* side: 'left' | 'right', the area to toggle
|
|
185
|
+
* title: string, label of the command
|
|
186
|
+
* id: string, id of the widget to activate
|
|
187
|
+
*/
|
|
188
|
+
command: string;
|
|
189
|
+
};
|
|
190
|
+
/**
|
|
191
|
+
* A namespace for private module data.
|
|
192
|
+
*/
|
|
193
|
+
declare namespace Private {
|
|
194
|
+
/**
|
|
195
|
+
* An object which holds a widget and its sort rank.
|
|
196
|
+
*/
|
|
197
|
+
interface IRankItem {
|
|
198
|
+
/**
|
|
199
|
+
* The widget for the item.
|
|
200
|
+
*/
|
|
201
|
+
widget: Widget;
|
|
202
|
+
/**
|
|
203
|
+
* The sort rank of the widget.
|
|
204
|
+
*/
|
|
205
|
+
rank: number;
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* A less-than comparison function for side bar rank items.
|
|
209
|
+
*/
|
|
210
|
+
function itemCmp(first: IRankItem, second: IRankItem): number;
|
|
211
|
+
}
|
|
212
|
+
export {};
|
|
@@ -0,0 +1,329 @@
|
|
|
1
|
+
// Copyright (c) Jupyter Development Team.
|
|
2
|
+
// Distributed under the terms of the Modified BSD License.
|
|
3
|
+
import { closeIcon } from '@jupyterlab/ui-components';
|
|
4
|
+
import { ArrayExt, find } from '@lumino/algorithm';
|
|
5
|
+
import { MessageLoop } from '@lumino/messaging';
|
|
6
|
+
import { Signal } from '@lumino/signaling';
|
|
7
|
+
import { Panel, StackedPanel, Widget } from '@lumino/widgets';
|
|
8
|
+
/**
|
|
9
|
+
* A class which manages a panel and sorts its widgets by rank.
|
|
10
|
+
*/
|
|
11
|
+
export class PanelHandler {
|
|
12
|
+
constructor() {
|
|
13
|
+
/**
|
|
14
|
+
* A message hook for child add/remove messages on the main area dock panel.
|
|
15
|
+
*/
|
|
16
|
+
this._panelChildHook = (handler, msg) => {
|
|
17
|
+
switch (msg.type) {
|
|
18
|
+
case 'child-added':
|
|
19
|
+
{
|
|
20
|
+
const widget = msg.child;
|
|
21
|
+
// If we already know about this widget, we're done
|
|
22
|
+
if (this._items.find(v => v.widget === widget)) {
|
|
23
|
+
break;
|
|
24
|
+
}
|
|
25
|
+
// Otherwise, add to the end by default
|
|
26
|
+
const rank = this._items[this._items.length - 1].rank;
|
|
27
|
+
this._items.push({ widget, rank });
|
|
28
|
+
}
|
|
29
|
+
break;
|
|
30
|
+
case 'child-removed':
|
|
31
|
+
{
|
|
32
|
+
const widget = msg.child;
|
|
33
|
+
ArrayExt.removeFirstWhere(this._items, v => v.widget === widget);
|
|
34
|
+
}
|
|
35
|
+
break;
|
|
36
|
+
default:
|
|
37
|
+
break;
|
|
38
|
+
}
|
|
39
|
+
return true;
|
|
40
|
+
};
|
|
41
|
+
this._items = new Array();
|
|
42
|
+
this._panel = new Panel();
|
|
43
|
+
MessageLoop.installMessageHook(this._panel, this._panelChildHook);
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Get the panel managed by the handler.
|
|
47
|
+
*/
|
|
48
|
+
get panel() {
|
|
49
|
+
return this._panel;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Add a widget to the panel.
|
|
53
|
+
*
|
|
54
|
+
* If the widget is already added, it will be moved.
|
|
55
|
+
*/
|
|
56
|
+
addWidget(widget, rank) {
|
|
57
|
+
widget.parent = null;
|
|
58
|
+
const item = { widget, rank };
|
|
59
|
+
const index = ArrayExt.upperBound(this._items, item, Private.itemCmp);
|
|
60
|
+
ArrayExt.insert(this._items, index, item);
|
|
61
|
+
this._panel.insertWidget(index, widget);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* A class which manages a side panel that can show at most one widget at a time.
|
|
66
|
+
*/
|
|
67
|
+
export class SidePanelHandler extends PanelHandler {
|
|
68
|
+
/**
|
|
69
|
+
* Construct a new side panel handler.
|
|
70
|
+
*/
|
|
71
|
+
constructor(area) {
|
|
72
|
+
super();
|
|
73
|
+
this._isHiddenByUser = false;
|
|
74
|
+
this._widgetAdded = new Signal(this);
|
|
75
|
+
this._widgetRemoved = new Signal(this);
|
|
76
|
+
this._area = area;
|
|
77
|
+
this._panel.hide();
|
|
78
|
+
this._currentWidget = null;
|
|
79
|
+
this._lastCurrentWidget = null;
|
|
80
|
+
this._widgetPanel = new StackedPanel();
|
|
81
|
+
this._widgetPanel.widgetRemoved.connect(this._onWidgetRemoved, this);
|
|
82
|
+
const closeButton = document.createElement('button');
|
|
83
|
+
closeIcon.element({
|
|
84
|
+
container: closeButton,
|
|
85
|
+
height: '16px',
|
|
86
|
+
width: 'auto'
|
|
87
|
+
});
|
|
88
|
+
closeButton.onclick = () => {
|
|
89
|
+
this.collapse();
|
|
90
|
+
this.hide();
|
|
91
|
+
};
|
|
92
|
+
closeButton.className = 'jp-Button jp-SidePanel-collapse';
|
|
93
|
+
const icon = new Widget({ node: closeButton });
|
|
94
|
+
this._panel.addWidget(icon);
|
|
95
|
+
this._panel.addWidget(this._widgetPanel);
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Get the current widget in the sidebar panel.
|
|
99
|
+
*/
|
|
100
|
+
get currentWidget() {
|
|
101
|
+
return (this._currentWidget ||
|
|
102
|
+
this._lastCurrentWidget ||
|
|
103
|
+
(this._items.length > 0 ? this._items[0].widget : null));
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Get the area of the side panel
|
|
107
|
+
*/
|
|
108
|
+
get area() {
|
|
109
|
+
return this._area;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Whether the panel is visible
|
|
113
|
+
*/
|
|
114
|
+
get isVisible() {
|
|
115
|
+
return this._panel.isVisible;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Get the stacked panel managed by the handler
|
|
119
|
+
*/
|
|
120
|
+
get panel() {
|
|
121
|
+
return this._panel;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Get the widgets list.
|
|
125
|
+
*/
|
|
126
|
+
get widgets() {
|
|
127
|
+
return this._items.map(obj => obj.widget);
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Signal fired when a widget is added to the panel
|
|
131
|
+
*/
|
|
132
|
+
get widgetAdded() {
|
|
133
|
+
return this._widgetAdded;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Signal fired when a widget is removed from the panel
|
|
137
|
+
*/
|
|
138
|
+
get widgetRemoved() {
|
|
139
|
+
return this._widgetRemoved;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Expand the sidebar.
|
|
143
|
+
*
|
|
144
|
+
* #### Notes
|
|
145
|
+
* This will open the most recently used widget, or the first widget
|
|
146
|
+
* if there is no most recently used.
|
|
147
|
+
*/
|
|
148
|
+
expand(id) {
|
|
149
|
+
if (this._currentWidget) {
|
|
150
|
+
this.collapse();
|
|
151
|
+
}
|
|
152
|
+
if (id) {
|
|
153
|
+
this.activate(id);
|
|
154
|
+
}
|
|
155
|
+
else {
|
|
156
|
+
const visibleWidget = this.currentWidget;
|
|
157
|
+
if (visibleWidget) {
|
|
158
|
+
this._currentWidget = visibleWidget;
|
|
159
|
+
this.activate(visibleWidget.id);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Activate a widget residing in the stacked panel by ID.
|
|
165
|
+
*
|
|
166
|
+
* @param id - The widget's unique ID.
|
|
167
|
+
*/
|
|
168
|
+
activate(id) {
|
|
169
|
+
const widget = this._findWidgetByID(id);
|
|
170
|
+
if (widget) {
|
|
171
|
+
this._currentWidget = widget;
|
|
172
|
+
widget.show();
|
|
173
|
+
widget.activate();
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Test whether the sidebar has the given widget by id.
|
|
178
|
+
*/
|
|
179
|
+
has(id) {
|
|
180
|
+
return this._findWidgetByID(id) !== null;
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Collapse the sidebar so no items are expanded.
|
|
184
|
+
*/
|
|
185
|
+
collapse() {
|
|
186
|
+
var _a;
|
|
187
|
+
(_a = this._currentWidget) === null || _a === void 0 ? void 0 : _a.hide();
|
|
188
|
+
this._currentWidget = null;
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Add a widget and its title to the stacked panel.
|
|
192
|
+
*
|
|
193
|
+
* If the widget is already added, it will be moved.
|
|
194
|
+
*/
|
|
195
|
+
addWidget(widget, rank) {
|
|
196
|
+
widget.parent = null;
|
|
197
|
+
widget.hide();
|
|
198
|
+
const item = { widget, rank };
|
|
199
|
+
const index = this._findInsertIndex(item);
|
|
200
|
+
ArrayExt.insert(this._items, index, item);
|
|
201
|
+
this._widgetPanel.insertWidget(index, widget);
|
|
202
|
+
this._refreshVisibility();
|
|
203
|
+
this._widgetAdded.emit(widget);
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Hide the side panel
|
|
207
|
+
*/
|
|
208
|
+
hide() {
|
|
209
|
+
this._isHiddenByUser = true;
|
|
210
|
+
this._refreshVisibility();
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Show the side panel
|
|
214
|
+
*/
|
|
215
|
+
show() {
|
|
216
|
+
this._isHiddenByUser = false;
|
|
217
|
+
this._refreshVisibility();
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* Find the insertion index for a rank item.
|
|
221
|
+
*/
|
|
222
|
+
_findInsertIndex(item) {
|
|
223
|
+
return ArrayExt.upperBound(this._items, item, Private.itemCmp);
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Find the index of the item with the given widget, or `-1`.
|
|
227
|
+
*/
|
|
228
|
+
_findWidgetIndex(widget) {
|
|
229
|
+
return ArrayExt.findFirstIndex(this._items, i => i.widget === widget);
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Find the widget with the given id, or `null`.
|
|
233
|
+
*/
|
|
234
|
+
_findWidgetByID(id) {
|
|
235
|
+
const item = find(this._items, value => value.widget.id === id);
|
|
236
|
+
return item ? item.widget : null;
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* Refresh the visibility of the stacked panel.
|
|
240
|
+
*/
|
|
241
|
+
_refreshVisibility() {
|
|
242
|
+
this._panel.setHidden(this._isHiddenByUser);
|
|
243
|
+
}
|
|
244
|
+
/*
|
|
245
|
+
* Handle the `widgetRemoved` signal from the panel.
|
|
246
|
+
*/
|
|
247
|
+
_onWidgetRemoved(sender, widget) {
|
|
248
|
+
if (widget === this._lastCurrentWidget) {
|
|
249
|
+
this._lastCurrentWidget = null;
|
|
250
|
+
}
|
|
251
|
+
ArrayExt.removeAt(this._items, this._findWidgetIndex(widget));
|
|
252
|
+
this._refreshVisibility();
|
|
253
|
+
this._widgetRemoved.emit(widget);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* A class to manages the palette entries associated to the side panels.
|
|
258
|
+
*/
|
|
259
|
+
export class SidePanelPalette {
|
|
260
|
+
/**
|
|
261
|
+
* Construct a new side panel palette.
|
|
262
|
+
*/
|
|
263
|
+
constructor(options) {
|
|
264
|
+
this._items = [];
|
|
265
|
+
this._commandPalette = options.commandPalette;
|
|
266
|
+
this._command = options.command;
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* Get a command palette item from the widget id and the area.
|
|
270
|
+
*/
|
|
271
|
+
getItem(widget, area) {
|
|
272
|
+
const itemList = this._items;
|
|
273
|
+
for (let i = 0; i < itemList.length; i++) {
|
|
274
|
+
const item = itemList[i];
|
|
275
|
+
if (item.widgetId === widget.id && item.area === area) {
|
|
276
|
+
return item;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
return null;
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* Add an item to the command palette.
|
|
283
|
+
*/
|
|
284
|
+
addItem(widget, area) {
|
|
285
|
+
// Check if the item does not already exist.
|
|
286
|
+
if (this.getItem(widget, area)) {
|
|
287
|
+
return;
|
|
288
|
+
}
|
|
289
|
+
// Add a new item in command palette.
|
|
290
|
+
const disposableDelegate = this._commandPalette.addItem({
|
|
291
|
+
command: this._command,
|
|
292
|
+
category: 'View',
|
|
293
|
+
args: {
|
|
294
|
+
side: area,
|
|
295
|
+
title: `Show ${widget.title.caption}`,
|
|
296
|
+
id: widget.id
|
|
297
|
+
}
|
|
298
|
+
});
|
|
299
|
+
// Keep the disposableDelegate objet to be able to dispose of the item if the widget
|
|
300
|
+
// is remove from the side panel.
|
|
301
|
+
this._items.push({
|
|
302
|
+
widgetId: widget.id,
|
|
303
|
+
area: area,
|
|
304
|
+
disposable: disposableDelegate
|
|
305
|
+
});
|
|
306
|
+
}
|
|
307
|
+
/**
|
|
308
|
+
* Remove an item from the command palette.
|
|
309
|
+
*/
|
|
310
|
+
removeItem(widget, area) {
|
|
311
|
+
const item = this.getItem(widget, area);
|
|
312
|
+
if (item) {
|
|
313
|
+
item.disposable.dispose();
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
/**
|
|
318
|
+
* A namespace for private module data.
|
|
319
|
+
*/
|
|
320
|
+
var Private;
|
|
321
|
+
(function (Private) {
|
|
322
|
+
/**
|
|
323
|
+
* A less-than comparison function for side bar rank items.
|
|
324
|
+
*/
|
|
325
|
+
function itemCmp(first, second) {
|
|
326
|
+
return first.rank - second.rank;
|
|
327
|
+
}
|
|
328
|
+
Private.itemCmp = itemCmp;
|
|
329
|
+
})(Private || (Private = {}));
|
package/lib/shell.d.ts
CHANGED
|
@@ -2,7 +2,8 @@ import { JupyterFrontEnd } from '@jupyterlab/application';
|
|
|
2
2
|
import { DocumentRegistry } from '@jupyterlab/docregistry';
|
|
3
3
|
import { Token } from '@lumino/coreutils';
|
|
4
4
|
import { ISignal } from '@lumino/signaling';
|
|
5
|
-
import {
|
|
5
|
+
import { Widget } from '@lumino/widgets';
|
|
6
|
+
import { SidePanelHandler } from './panelhandler';
|
|
6
7
|
/**
|
|
7
8
|
* The Jupyter Notebook application shell token.
|
|
8
9
|
*/
|
|
@@ -36,11 +37,11 @@ export declare class NotebookShell extends Widget implements JupyterFrontEnd.ISh
|
|
|
36
37
|
/**
|
|
37
38
|
* Get the left area handler
|
|
38
39
|
*/
|
|
39
|
-
get leftHandler():
|
|
40
|
+
get leftHandler(): SidePanelHandler;
|
|
40
41
|
/**
|
|
41
42
|
* Get the right area handler
|
|
42
43
|
*/
|
|
43
|
-
get rightHandler():
|
|
44
|
+
get rightHandler(): SidePanelHandler;
|
|
44
45
|
/**
|
|
45
46
|
* Is the left sidebar visible?
|
|
46
47
|
*/
|
|
@@ -119,111 +120,3 @@ export declare namespace Shell {
|
|
|
119
120
|
*/
|
|
120
121
|
type Area = 'main' | 'top' | 'left' | 'right' | 'menu';
|
|
121
122
|
}
|
|
122
|
-
/**
|
|
123
|
-
* A name space for SideBarPanel functions.
|
|
124
|
-
*/
|
|
125
|
-
export declare namespace SideBarPanel {
|
|
126
|
-
/**
|
|
127
|
-
* The areas of the sidebar panel
|
|
128
|
-
*/
|
|
129
|
-
type Area = 'left' | 'right';
|
|
130
|
-
}
|
|
131
|
-
/**
|
|
132
|
-
* A class which manages a side bar that can show at most one widget at a time.
|
|
133
|
-
*/
|
|
134
|
-
export declare class SideBarHandler {
|
|
135
|
-
/**
|
|
136
|
-
* Construct a new side bar handler.
|
|
137
|
-
*/
|
|
138
|
-
constructor(area: SideBarPanel.Area);
|
|
139
|
-
/**
|
|
140
|
-
* Get the current widget in the sidebar panel.
|
|
141
|
-
*/
|
|
142
|
-
get currentWidget(): Widget | null;
|
|
143
|
-
/**
|
|
144
|
-
* Get the area of the side panel
|
|
145
|
-
*/
|
|
146
|
-
get area(): SideBarPanel.Area;
|
|
147
|
-
/**
|
|
148
|
-
* Whether the panel is visible
|
|
149
|
-
*/
|
|
150
|
-
get isVisible(): boolean;
|
|
151
|
-
/**
|
|
152
|
-
* Get the stacked panel managed by the handler
|
|
153
|
-
*/
|
|
154
|
-
get panel(): Panel;
|
|
155
|
-
/**
|
|
156
|
-
* Get the widgets list.
|
|
157
|
-
*/
|
|
158
|
-
get widgets(): Readonly<Widget[]>;
|
|
159
|
-
/**
|
|
160
|
-
* Signal fired when a widget is added to the panel
|
|
161
|
-
*/
|
|
162
|
-
get widgetAdded(): ISignal<SideBarHandler, Widget>;
|
|
163
|
-
/**
|
|
164
|
-
* Signal fired when a widget is removed from the panel
|
|
165
|
-
*/
|
|
166
|
-
get widgetRemoved(): ISignal<SideBarHandler, Widget>;
|
|
167
|
-
/**
|
|
168
|
-
* Expand the sidebar.
|
|
169
|
-
*
|
|
170
|
-
* #### Notes
|
|
171
|
-
* This will open the most recently used widget, or the first widget
|
|
172
|
-
* if there is no most recently used.
|
|
173
|
-
*/
|
|
174
|
-
expand(id?: string): void;
|
|
175
|
-
/**
|
|
176
|
-
* Activate a widget residing in the stacked panel by ID.
|
|
177
|
-
*
|
|
178
|
-
* @param id - The widget's unique ID.
|
|
179
|
-
*/
|
|
180
|
-
activate(id: string): void;
|
|
181
|
-
/**
|
|
182
|
-
* Test whether the sidebar has the given widget by id.
|
|
183
|
-
*/
|
|
184
|
-
has(id: string): boolean;
|
|
185
|
-
/**
|
|
186
|
-
* Collapse the sidebar so no items are expanded.
|
|
187
|
-
*/
|
|
188
|
-
collapse(): void;
|
|
189
|
-
/**
|
|
190
|
-
* Add a widget and its title to the stacked panel.
|
|
191
|
-
*
|
|
192
|
-
* If the widget is already added, it will be moved.
|
|
193
|
-
*/
|
|
194
|
-
addWidget(widget: Widget, rank: number): void;
|
|
195
|
-
/**
|
|
196
|
-
* Hide the side panel
|
|
197
|
-
*/
|
|
198
|
-
hide(): void;
|
|
199
|
-
/**
|
|
200
|
-
* Show the side panel
|
|
201
|
-
*/
|
|
202
|
-
show(): void;
|
|
203
|
-
/**
|
|
204
|
-
* Find the insertion index for a rank item.
|
|
205
|
-
*/
|
|
206
|
-
private _findInsertIndex;
|
|
207
|
-
/**
|
|
208
|
-
* Find the index of the item with the given widget, or `-1`.
|
|
209
|
-
*/
|
|
210
|
-
private _findWidgetIndex;
|
|
211
|
-
/**
|
|
212
|
-
* Find the widget with the given id, or `null`.
|
|
213
|
-
*/
|
|
214
|
-
private _findWidgetByID;
|
|
215
|
-
/**
|
|
216
|
-
* Refresh the visibility of the stacked panel.
|
|
217
|
-
*/
|
|
218
|
-
private _refreshVisibility;
|
|
219
|
-
private _onWidgetRemoved;
|
|
220
|
-
private _area;
|
|
221
|
-
private _isHiddenByUser;
|
|
222
|
-
private _items;
|
|
223
|
-
private _panel;
|
|
224
|
-
private _widgetPanel;
|
|
225
|
-
private _currentWidget;
|
|
226
|
-
private _lastCurrentWidget;
|
|
227
|
-
private _widgetAdded;
|
|
228
|
-
private _widgetRemoved;
|
|
229
|
-
}
|
package/lib/shell.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
// Copyright (c) Jupyter Development Team.
|
|
2
2
|
// Distributed under the terms of the Modified BSD License.
|
|
3
|
-
import {
|
|
4
|
-
import { ArrayExt, find } from '@lumino/algorithm';
|
|
3
|
+
import { find } from '@lumino/algorithm';
|
|
5
4
|
import { PromiseDelegate, Token } from '@lumino/coreutils';
|
|
6
|
-
import { MessageLoop } from '@lumino/messaging';
|
|
7
5
|
import { Signal } from '@lumino/signaling';
|
|
8
|
-
import { BoxLayout, Panel, SplitPanel,
|
|
6
|
+
import { BoxLayout, Panel, SplitPanel, Widget } from '@lumino/widgets';
|
|
7
|
+
import { PanelHandler, SidePanelHandler } from './panelhandler';
|
|
9
8
|
/**
|
|
10
9
|
* The Jupyter Notebook application shell token.
|
|
11
10
|
*/
|
|
@@ -23,10 +22,10 @@ export class NotebookShell extends Widget {
|
|
|
23
22
|
this._currentChanged = new Signal(this);
|
|
24
23
|
this._mainWidgetLoaded = new PromiseDelegate();
|
|
25
24
|
this.id = 'main';
|
|
26
|
-
this._topHandler = new
|
|
27
|
-
this._menuHandler = new
|
|
28
|
-
this._leftHandler = new
|
|
29
|
-
this._rightHandler = new
|
|
25
|
+
this._topHandler = new PanelHandler();
|
|
26
|
+
this._menuHandler = new PanelHandler();
|
|
27
|
+
this._leftHandler = new SidePanelHandler('left');
|
|
28
|
+
this._rightHandler = new SidePanelHandler('right');
|
|
30
29
|
this._main = new Panel();
|
|
31
30
|
const topWrapper = (this._topWrapper = new Panel());
|
|
32
31
|
const menuWrapper = (this._menuWrapper = new Panel());
|
|
@@ -263,266 +262,3 @@ export class NotebookShell extends Widget {
|
|
|
263
262
|
this._rightHandler.panel.hide();
|
|
264
263
|
}
|
|
265
264
|
}
|
|
266
|
-
/**
|
|
267
|
-
* A class which manages a side bar that can show at most one widget at a time.
|
|
268
|
-
*/
|
|
269
|
-
export class SideBarHandler {
|
|
270
|
-
/**
|
|
271
|
-
* Construct a new side bar handler.
|
|
272
|
-
*/
|
|
273
|
-
constructor(area) {
|
|
274
|
-
this._isHiddenByUser = false;
|
|
275
|
-
this._items = new Array();
|
|
276
|
-
this._widgetAdded = new Signal(this);
|
|
277
|
-
this._widgetRemoved = new Signal(this);
|
|
278
|
-
this._area = area;
|
|
279
|
-
this._panel = new Panel();
|
|
280
|
-
this._panel.hide();
|
|
281
|
-
this._currentWidget = null;
|
|
282
|
-
this._lastCurrentWidget = null;
|
|
283
|
-
this._widgetPanel = new StackedPanel();
|
|
284
|
-
this._widgetPanel.widgetRemoved.connect(this._onWidgetRemoved, this);
|
|
285
|
-
const closeButton = document.createElement('button');
|
|
286
|
-
closeIcon.element({
|
|
287
|
-
container: closeButton,
|
|
288
|
-
height: '16px',
|
|
289
|
-
width: 'auto'
|
|
290
|
-
});
|
|
291
|
-
closeButton.onclick = () => {
|
|
292
|
-
this.collapse();
|
|
293
|
-
this.hide();
|
|
294
|
-
};
|
|
295
|
-
closeButton.className = 'jp-Button jp-SidePanel-collapse';
|
|
296
|
-
const icon = new Widget({ node: closeButton });
|
|
297
|
-
this._panel.addWidget(icon);
|
|
298
|
-
this._panel.addWidget(this._widgetPanel);
|
|
299
|
-
}
|
|
300
|
-
/**
|
|
301
|
-
* Get the current widget in the sidebar panel.
|
|
302
|
-
*/
|
|
303
|
-
get currentWidget() {
|
|
304
|
-
return (this._currentWidget ||
|
|
305
|
-
this._lastCurrentWidget ||
|
|
306
|
-
(this._items.length > 0 ? this._items[0].widget : null));
|
|
307
|
-
}
|
|
308
|
-
/**
|
|
309
|
-
* Get the area of the side panel
|
|
310
|
-
*/
|
|
311
|
-
get area() {
|
|
312
|
-
return this._area;
|
|
313
|
-
}
|
|
314
|
-
/**
|
|
315
|
-
* Whether the panel is visible
|
|
316
|
-
*/
|
|
317
|
-
get isVisible() {
|
|
318
|
-
return this._panel.isVisible;
|
|
319
|
-
}
|
|
320
|
-
/**
|
|
321
|
-
* Get the stacked panel managed by the handler
|
|
322
|
-
*/
|
|
323
|
-
get panel() {
|
|
324
|
-
return this._panel;
|
|
325
|
-
}
|
|
326
|
-
/**
|
|
327
|
-
* Get the widgets list.
|
|
328
|
-
*/
|
|
329
|
-
get widgets() {
|
|
330
|
-
return this._items.map(obj => obj.widget);
|
|
331
|
-
}
|
|
332
|
-
/**
|
|
333
|
-
* Signal fired when a widget is added to the panel
|
|
334
|
-
*/
|
|
335
|
-
get widgetAdded() {
|
|
336
|
-
return this._widgetAdded;
|
|
337
|
-
}
|
|
338
|
-
/**
|
|
339
|
-
* Signal fired when a widget is removed from the panel
|
|
340
|
-
*/
|
|
341
|
-
get widgetRemoved() {
|
|
342
|
-
return this._widgetRemoved;
|
|
343
|
-
}
|
|
344
|
-
/**
|
|
345
|
-
* Expand the sidebar.
|
|
346
|
-
*
|
|
347
|
-
* #### Notes
|
|
348
|
-
* This will open the most recently used widget, or the first widget
|
|
349
|
-
* if there is no most recently used.
|
|
350
|
-
*/
|
|
351
|
-
expand(id) {
|
|
352
|
-
if (this._currentWidget) {
|
|
353
|
-
this.collapse();
|
|
354
|
-
}
|
|
355
|
-
if (id) {
|
|
356
|
-
this.activate(id);
|
|
357
|
-
}
|
|
358
|
-
else {
|
|
359
|
-
const visibleWidget = this.currentWidget;
|
|
360
|
-
if (visibleWidget) {
|
|
361
|
-
this._currentWidget = visibleWidget;
|
|
362
|
-
this.activate(visibleWidget.id);
|
|
363
|
-
}
|
|
364
|
-
}
|
|
365
|
-
}
|
|
366
|
-
/**
|
|
367
|
-
* Activate a widget residing in the stacked panel by ID.
|
|
368
|
-
*
|
|
369
|
-
* @param id - The widget's unique ID.
|
|
370
|
-
*/
|
|
371
|
-
activate(id) {
|
|
372
|
-
const widget = this._findWidgetByID(id);
|
|
373
|
-
if (widget) {
|
|
374
|
-
this._currentWidget = widget;
|
|
375
|
-
widget.show();
|
|
376
|
-
widget.activate();
|
|
377
|
-
}
|
|
378
|
-
}
|
|
379
|
-
/**
|
|
380
|
-
* Test whether the sidebar has the given widget by id.
|
|
381
|
-
*/
|
|
382
|
-
has(id) {
|
|
383
|
-
return this._findWidgetByID(id) !== null;
|
|
384
|
-
}
|
|
385
|
-
/**
|
|
386
|
-
* Collapse the sidebar so no items are expanded.
|
|
387
|
-
*/
|
|
388
|
-
collapse() {
|
|
389
|
-
var _a;
|
|
390
|
-
(_a = this._currentWidget) === null || _a === void 0 ? void 0 : _a.hide();
|
|
391
|
-
this._currentWidget = null;
|
|
392
|
-
}
|
|
393
|
-
/**
|
|
394
|
-
* Add a widget and its title to the stacked panel.
|
|
395
|
-
*
|
|
396
|
-
* If the widget is already added, it will be moved.
|
|
397
|
-
*/
|
|
398
|
-
addWidget(widget, rank) {
|
|
399
|
-
widget.parent = null;
|
|
400
|
-
widget.hide();
|
|
401
|
-
const item = { widget, rank };
|
|
402
|
-
const index = this._findInsertIndex(item);
|
|
403
|
-
ArrayExt.insert(this._items, index, item);
|
|
404
|
-
this._widgetPanel.insertWidget(index, widget);
|
|
405
|
-
this._refreshVisibility();
|
|
406
|
-
this._widgetAdded.emit(widget);
|
|
407
|
-
}
|
|
408
|
-
/**
|
|
409
|
-
* Hide the side panel
|
|
410
|
-
*/
|
|
411
|
-
hide() {
|
|
412
|
-
this._isHiddenByUser = true;
|
|
413
|
-
this._refreshVisibility();
|
|
414
|
-
}
|
|
415
|
-
/**
|
|
416
|
-
* Show the side panel
|
|
417
|
-
*/
|
|
418
|
-
show() {
|
|
419
|
-
this._isHiddenByUser = false;
|
|
420
|
-
this._refreshVisibility();
|
|
421
|
-
}
|
|
422
|
-
/**
|
|
423
|
-
* Find the insertion index for a rank item.
|
|
424
|
-
*/
|
|
425
|
-
_findInsertIndex(item) {
|
|
426
|
-
return ArrayExt.upperBound(this._items, item, Private.itemCmp);
|
|
427
|
-
}
|
|
428
|
-
/**
|
|
429
|
-
* Find the index of the item with the given widget, or `-1`.
|
|
430
|
-
*/
|
|
431
|
-
_findWidgetIndex(widget) {
|
|
432
|
-
return ArrayExt.findFirstIndex(this._items, i => i.widget === widget);
|
|
433
|
-
}
|
|
434
|
-
/**
|
|
435
|
-
* Find the widget with the given id, or `null`.
|
|
436
|
-
*/
|
|
437
|
-
_findWidgetByID(id) {
|
|
438
|
-
const item = find(this._items, value => value.widget.id === id);
|
|
439
|
-
return item ? item.widget : null;
|
|
440
|
-
}
|
|
441
|
-
/**
|
|
442
|
-
* Refresh the visibility of the stacked panel.
|
|
443
|
-
*/
|
|
444
|
-
_refreshVisibility() {
|
|
445
|
-
this._panel.setHidden(this._isHiddenByUser);
|
|
446
|
-
}
|
|
447
|
-
/*
|
|
448
|
-
* Handle the `widgetRemoved` signal from the panel.
|
|
449
|
-
*/
|
|
450
|
-
_onWidgetRemoved(sender, widget) {
|
|
451
|
-
if (widget === this._lastCurrentWidget) {
|
|
452
|
-
this._lastCurrentWidget = null;
|
|
453
|
-
}
|
|
454
|
-
ArrayExt.removeAt(this._items, this._findWidgetIndex(widget));
|
|
455
|
-
this._refreshVisibility();
|
|
456
|
-
this._widgetRemoved.emit(widget);
|
|
457
|
-
}
|
|
458
|
-
}
|
|
459
|
-
/**
|
|
460
|
-
* A namespace for private module data.
|
|
461
|
-
*/
|
|
462
|
-
var Private;
|
|
463
|
-
(function (Private) {
|
|
464
|
-
/**
|
|
465
|
-
* A less-than comparison function for side bar rank items.
|
|
466
|
-
*/
|
|
467
|
-
function itemCmp(first, second) {
|
|
468
|
-
return first.rank - second.rank;
|
|
469
|
-
}
|
|
470
|
-
Private.itemCmp = itemCmp;
|
|
471
|
-
/**
|
|
472
|
-
* A class which manages a panel and sorts its widgets by rank.
|
|
473
|
-
*/
|
|
474
|
-
class PanelHandler {
|
|
475
|
-
constructor() {
|
|
476
|
-
/**
|
|
477
|
-
* A message hook for child add/remove messages on the main area dock panel.
|
|
478
|
-
*/
|
|
479
|
-
this._panelChildHook = (handler, msg) => {
|
|
480
|
-
switch (msg.type) {
|
|
481
|
-
case 'child-added':
|
|
482
|
-
{
|
|
483
|
-
const widget = msg.child;
|
|
484
|
-
// If we already know about this widget, we're done
|
|
485
|
-
if (this._items.find(v => v.widget === widget)) {
|
|
486
|
-
break;
|
|
487
|
-
}
|
|
488
|
-
// Otherwise, add to the end by default
|
|
489
|
-
const rank = this._items[this._items.length - 1].rank;
|
|
490
|
-
this._items.push({ widget, rank });
|
|
491
|
-
}
|
|
492
|
-
break;
|
|
493
|
-
case 'child-removed':
|
|
494
|
-
{
|
|
495
|
-
const widget = msg.child;
|
|
496
|
-
ArrayExt.removeFirstWhere(this._items, v => v.widget === widget);
|
|
497
|
-
}
|
|
498
|
-
break;
|
|
499
|
-
default:
|
|
500
|
-
break;
|
|
501
|
-
}
|
|
502
|
-
return true;
|
|
503
|
-
};
|
|
504
|
-
this._items = new Array();
|
|
505
|
-
this._panel = new Panel();
|
|
506
|
-
MessageLoop.installMessageHook(this._panel, this._panelChildHook);
|
|
507
|
-
}
|
|
508
|
-
/**
|
|
509
|
-
* Get the panel managed by the handler.
|
|
510
|
-
*/
|
|
511
|
-
get panel() {
|
|
512
|
-
return this._panel;
|
|
513
|
-
}
|
|
514
|
-
/**
|
|
515
|
-
* Add a widget to the panel.
|
|
516
|
-
*
|
|
517
|
-
* If the widget is already added, it will be moved.
|
|
518
|
-
*/
|
|
519
|
-
addWidget(widget, rank) {
|
|
520
|
-
widget.parent = null;
|
|
521
|
-
const item = { widget, rank };
|
|
522
|
-
const index = ArrayExt.upperBound(this._items, item, Private.itemCmp);
|
|
523
|
-
ArrayExt.insert(this._items, index, item);
|
|
524
|
-
this._panel.insertWidget(index, widget);
|
|
525
|
-
}
|
|
526
|
-
}
|
|
527
|
-
Private.PanelHandler = PanelHandler;
|
|
528
|
-
})(Private || (Private = {}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jupyter-notebook/application",
|
|
3
|
-
"version": "7.0.0-alpha.
|
|
3
|
+
"version": "7.0.0-alpha.9",
|
|
4
4
|
"description": "Jupyter Notebook - Application",
|
|
5
5
|
"homepage": "https://github.com/jupyter/notebook",
|
|
6
6
|
"bugs": {
|
|
@@ -43,11 +43,11 @@
|
|
|
43
43
|
"watch": "tsc -b --watch"
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@jupyterlab/application": "^4.0.0-alpha.
|
|
47
|
-
"@jupyterlab/coreutils": "^6.0.0-alpha.
|
|
48
|
-
"@jupyterlab/docregistry": "^4.0.0-alpha.
|
|
49
|
-
"@jupyterlab/rendermime-interfaces": "^3.8.0-alpha.
|
|
50
|
-
"@jupyterlab/ui-components": "^4.0.0-alpha.
|
|
46
|
+
"@jupyterlab/application": "^4.0.0-alpha.16",
|
|
47
|
+
"@jupyterlab/coreutils": "^6.0.0-alpha.16",
|
|
48
|
+
"@jupyterlab/docregistry": "^4.0.0-alpha.16",
|
|
49
|
+
"@jupyterlab/rendermime-interfaces": "^3.8.0-alpha.16",
|
|
50
|
+
"@jupyterlab/ui-components": "^4.0.0-alpha.31",
|
|
51
51
|
"@lumino/algorithm": "^2.0.0-alpha.6",
|
|
52
52
|
"@lumino/coreutils": "^2.0.0-alpha.6",
|
|
53
53
|
"@lumino/messaging": "^2.0.0-alpha.6",
|
|
@@ -58,7 +58,7 @@
|
|
|
58
58
|
"devDependencies": {
|
|
59
59
|
"@babel/core": "^7.11.6",
|
|
60
60
|
"@babel/preset-env": "^7.12.1",
|
|
61
|
-
"@jupyterlab/testutils": "^4.0.0-alpha.
|
|
61
|
+
"@jupyterlab/testutils": "^4.0.0-alpha.16",
|
|
62
62
|
"@types/jest": "^26.0.10",
|
|
63
63
|
"jest": "^26.4.2",
|
|
64
64
|
"rimraf": "^3.0.2",
|