@jupyterlab/apputils 0.19.1-alpha.0 → 0.19.1
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/LICENSE +34 -0
- package/lib/clientsession.d.ts +443 -443
- package/lib/clientsession.js +883 -883
- package/lib/clipboard.d.ts +33 -33
- package/lib/clipboard.js +88 -88
- package/lib/commandlinker.d.ts +121 -121
- package/lib/commandlinker.js +175 -175
- package/lib/commandpalette.d.ts +33 -33
- package/lib/commandpalette.js +12 -12
- package/lib/dialog.d.ts +357 -357
- package/lib/dialog.js +540 -540
- package/lib/domutils.d.ts +13 -13
- package/lib/domutils.js +28 -28
- package/lib/hoverbox.d.ts +82 -82
- package/lib/hoverbox.js +101 -101
- package/lib/iframe.d.ts +14 -14
- package/lib/iframe.js +45 -45
- package/lib/index.d.ts +19 -19
- package/lib/index.js +26 -26
- package/lib/instancetracker.d.ts +278 -278
- package/lib/instancetracker.js +318 -318
- package/lib/mainareawidget.d.ts +108 -108
- package/lib/mainareawidget.js +184 -184
- package/lib/sanitizer.d.ts +44 -44
- package/lib/sanitizer.js +913 -913
- package/lib/spinner.d.ts +15 -15
- package/lib/spinner.js +30 -30
- package/lib/splash.d.ts +19 -19
- package/lib/splash.js +10 -10
- package/lib/styling.d.ts +27 -27
- package/lib/styling.js +92 -92
- package/lib/thememanager.d.ts +141 -141
- package/lib/thememanager.js +238 -238
- package/lib/toolbar.d.ts +178 -178
- package/lib/toolbar.js +515 -515
- package/lib/vdom.d.ts +90 -90
- package/lib/vdom.js +130 -130
- package/lib/windowresolver.d.ts +37 -37
- package/lib/windowresolver.js +173 -173
- package/package.json +9 -6
package/lib/toolbar.js
CHANGED
|
@@ -1,515 +1,515 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// Copyright (c) Jupyter Development Team.
|
|
3
|
-
// Distributed under the terms of the Modified BSD License.
|
|
4
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
5
|
-
if (mod && mod.__esModule) return mod;
|
|
6
|
-
var result = {};
|
|
7
|
-
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
|
|
8
|
-
result["default"] = mod;
|
|
9
|
-
return result;
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
const vdom_1 = require("./vdom");
|
|
13
|
-
const algorithm_1 = require("@phosphor/algorithm");
|
|
14
|
-
const messaging_1 = require("@phosphor/messaging");
|
|
15
|
-
const properties_1 = require("@phosphor/properties");
|
|
16
|
-
const widgets_1 = require("@phosphor/widgets");
|
|
17
|
-
const React = __importStar(require("react"));
|
|
18
|
-
/**
|
|
19
|
-
* The class name added to toolbars.
|
|
20
|
-
*/
|
|
21
|
-
const TOOLBAR_CLASS = 'jp-Toolbar';
|
|
22
|
-
/**
|
|
23
|
-
* The class name added to toolbar items.
|
|
24
|
-
*/
|
|
25
|
-
const TOOLBAR_ITEM_CLASS = 'jp-Toolbar-item';
|
|
26
|
-
/**
|
|
27
|
-
* The class name added to toolbar kernel name text.
|
|
28
|
-
*/
|
|
29
|
-
const TOOLBAR_KERNEL_NAME_CLASS = 'jp-Toolbar-kernelName';
|
|
30
|
-
/**
|
|
31
|
-
* The class name added to toolbar spacer.
|
|
32
|
-
*/
|
|
33
|
-
const TOOLBAR_SPACER_CLASS = 'jp-Toolbar-spacer';
|
|
34
|
-
/**
|
|
35
|
-
* The class name added to toolbar kernel status icon.
|
|
36
|
-
*/
|
|
37
|
-
const TOOLBAR_KERNEL_STATUS_CLASS = 'jp-Toolbar-kernelStatus';
|
|
38
|
-
/**
|
|
39
|
-
* The class name added to a busy kernel indicator.
|
|
40
|
-
*/
|
|
41
|
-
const TOOLBAR_BUSY_CLASS = 'jp-FilledCircleIcon';
|
|
42
|
-
const TOOLBAR_IDLE_CLASS = 'jp-CircleIcon';
|
|
43
|
-
/**
|
|
44
|
-
* A layout for toolbars.
|
|
45
|
-
*
|
|
46
|
-
* #### Notes
|
|
47
|
-
* This layout automatically collapses its height if there are no visible
|
|
48
|
-
* toolbar widgets, and expands to the standard toolbar height if there are
|
|
49
|
-
* visible toolbar widgets.
|
|
50
|
-
*/
|
|
51
|
-
class ToolbarLayout extends widgets_1.PanelLayout {
|
|
52
|
-
constructor() {
|
|
53
|
-
super(...arguments);
|
|
54
|
-
this._dirty = false;
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* A message handler invoked on a `'fit-request'` message.
|
|
58
|
-
*
|
|
59
|
-
* If any child widget is visible, expand the toolbar height to the normal
|
|
60
|
-
* toolbar height.
|
|
61
|
-
*/
|
|
62
|
-
onFitRequest(msg) {
|
|
63
|
-
super.onFitRequest(msg);
|
|
64
|
-
if (this.parent.isAttached) {
|
|
65
|
-
// If there are any widgets not explicitly hidden, expand the toolbar to
|
|
66
|
-
// accommodate them.
|
|
67
|
-
if (algorithm_1.some(this.widgets, w => !w.isHidden)) {
|
|
68
|
-
this.parent.node.style.minHeight = 'var(--jp-private-toolbar-height)';
|
|
69
|
-
}
|
|
70
|
-
else {
|
|
71
|
-
this.parent.node.style.minHeight = '';
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
// Set the dirty flag to ensure only a single update occurs.
|
|
75
|
-
this._dirty = true;
|
|
76
|
-
// Notify the ancestor that it should fit immediately. This may
|
|
77
|
-
// cause a resize of the parent, fulfilling the required update.
|
|
78
|
-
if (this.parent.parent) {
|
|
79
|
-
messaging_1.MessageLoop.sendMessage(this.parent.parent, widgets_1.Widget.Msg.FitRequest);
|
|
80
|
-
}
|
|
81
|
-
// If the dirty flag is still set, the parent was not resized.
|
|
82
|
-
// Trigger the required update on the parent widget immediately.
|
|
83
|
-
if (this._dirty) {
|
|
84
|
-
messaging_1.MessageLoop.sendMessage(this.parent, widgets_1.Widget.Msg.UpdateRequest);
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* A message handler invoked on an `'update-request'` message.
|
|
89
|
-
*/
|
|
90
|
-
onUpdateRequest(msg) {
|
|
91
|
-
super.onUpdateRequest(msg);
|
|
92
|
-
if (this.parent.isVisible) {
|
|
93
|
-
this._dirty = false;
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
/**
|
|
97
|
-
* A message handler invoked on a `'child-shown'` message.
|
|
98
|
-
*/
|
|
99
|
-
onChildShown(msg) {
|
|
100
|
-
super.onChildShown(msg);
|
|
101
|
-
// Post a fit request for the parent widget.
|
|
102
|
-
this.parent.fit();
|
|
103
|
-
}
|
|
104
|
-
/**
|
|
105
|
-
* A message handler invoked on a `'child-hidden'` message.
|
|
106
|
-
*/
|
|
107
|
-
onChildHidden(msg) {
|
|
108
|
-
super.onChildHidden(msg);
|
|
109
|
-
// Post a fit request for the parent widget.
|
|
110
|
-
this.parent.fit();
|
|
111
|
-
}
|
|
112
|
-
/**
|
|
113
|
-
* A message handler invoked on a `'before-attach'` message.
|
|
114
|
-
*/
|
|
115
|
-
onBeforeAttach(msg) {
|
|
116
|
-
super.onBeforeAttach(msg);
|
|
117
|
-
// Post a fit request for the parent widget.
|
|
118
|
-
this.parent.fit();
|
|
119
|
-
}
|
|
120
|
-
/**
|
|
121
|
-
* Attach a widget to the parent's DOM node.
|
|
122
|
-
*
|
|
123
|
-
* @param index - The current index of the widget in the layout.
|
|
124
|
-
*
|
|
125
|
-
* @param widget - The widget to attach to the parent.
|
|
126
|
-
*
|
|
127
|
-
* #### Notes
|
|
128
|
-
* This is a reimplementation of the superclass method.
|
|
129
|
-
*/
|
|
130
|
-
attachWidget(index, widget) {
|
|
131
|
-
super.attachWidget(index, widget);
|
|
132
|
-
// Post a fit request for the parent widget.
|
|
133
|
-
this.parent.fit();
|
|
134
|
-
}
|
|
135
|
-
/**
|
|
136
|
-
* Detach a widget from the parent's DOM node.
|
|
137
|
-
*
|
|
138
|
-
* @param index - The previous index of the widget in the layout.
|
|
139
|
-
*
|
|
140
|
-
* @param widget - The widget to detach from the parent.
|
|
141
|
-
*
|
|
142
|
-
* #### Notes
|
|
143
|
-
* This is a reimplementation of the superclass method.
|
|
144
|
-
*/
|
|
145
|
-
detachWidget(index, widget) {
|
|
146
|
-
super.detachWidget(index, widget);
|
|
147
|
-
// Post a fit request for the parent widget.
|
|
148
|
-
this.parent.fit();
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
/**
|
|
152
|
-
* A class which provides a toolbar widget.
|
|
153
|
-
*/
|
|
154
|
-
class Toolbar extends widgets_1.Widget {
|
|
155
|
-
/**
|
|
156
|
-
* Construct a new toolbar widget.
|
|
157
|
-
*/
|
|
158
|
-
constructor() {
|
|
159
|
-
super();
|
|
160
|
-
this.addClass(TOOLBAR_CLASS);
|
|
161
|
-
this.layout = new ToolbarLayout();
|
|
162
|
-
}
|
|
163
|
-
/**
|
|
164
|
-
* Get an iterator over the ordered toolbar item names.
|
|
165
|
-
*
|
|
166
|
-
* @returns An iterator over the toolbar item names.
|
|
167
|
-
*/
|
|
168
|
-
names() {
|
|
169
|
-
let layout = this.layout;
|
|
170
|
-
return algorithm_1.map(layout.widgets, widget => {
|
|
171
|
-
return Private.nameProperty.get(widget);
|
|
172
|
-
});
|
|
173
|
-
}
|
|
174
|
-
/**
|
|
175
|
-
* Add an item to the end of the toolbar.
|
|
176
|
-
*
|
|
177
|
-
* @param name - The name of the widget to add to the toolbar.
|
|
178
|
-
*
|
|
179
|
-
* @param widget - The widget to add to the toolbar.
|
|
180
|
-
*
|
|
181
|
-
* @param index - The optional name of the item to insert after.
|
|
182
|
-
*
|
|
183
|
-
* @returns Whether the item was added to toolbar. Returns false if
|
|
184
|
-
* an item of the same name is already in the toolbar.
|
|
185
|
-
*
|
|
186
|
-
* #### Notes
|
|
187
|
-
* The item can be removed from the toolbar by setting its parent to `null`.
|
|
188
|
-
*/
|
|
189
|
-
addItem(name, widget) {
|
|
190
|
-
let layout = this.layout;
|
|
191
|
-
return this.insertItem(layout.widgets.length, name, widget);
|
|
192
|
-
}
|
|
193
|
-
/**
|
|
194
|
-
* Insert an item into the toolbar at the specified index.
|
|
195
|
-
*
|
|
196
|
-
* @param index - The index at which to insert the item.
|
|
197
|
-
*
|
|
198
|
-
* @param name - The name of the item.
|
|
199
|
-
*
|
|
200
|
-
* @param widget - The widget to add.
|
|
201
|
-
*
|
|
202
|
-
* @returns Whether the item was added to the toolbar. Returns false if
|
|
203
|
-
* an item of the same name is already in the toolbar.
|
|
204
|
-
*
|
|
205
|
-
* #### Notes
|
|
206
|
-
* The index will be clamped to the bounds of the items.
|
|
207
|
-
* The item can be removed from the toolbar by setting its parent to `null`.
|
|
208
|
-
*/
|
|
209
|
-
insertItem(index, name, widget) {
|
|
210
|
-
let existing = algorithm_1.find(this.names(), value => value === name);
|
|
211
|
-
if (existing) {
|
|
212
|
-
return false;
|
|
213
|
-
}
|
|
214
|
-
widget.addClass(TOOLBAR_ITEM_CLASS);
|
|
215
|
-
let layout = this.layout;
|
|
216
|
-
layout.insertWidget(index, widget);
|
|
217
|
-
Private.nameProperty.set(widget, name);
|
|
218
|
-
return true;
|
|
219
|
-
}
|
|
220
|
-
/**
|
|
221
|
-
* Handle the DOM events for the widget.
|
|
222
|
-
*
|
|
223
|
-
* @param event - The DOM event sent to the widget.
|
|
224
|
-
*
|
|
225
|
-
* #### Notes
|
|
226
|
-
* This method implements the DOM `EventListener` interface and is
|
|
227
|
-
* called in response to events on the dock panel's node. It should
|
|
228
|
-
* not be called directly by user code.
|
|
229
|
-
*/
|
|
230
|
-
handleEvent(event) {
|
|
231
|
-
switch (event.type) {
|
|
232
|
-
case 'click':
|
|
233
|
-
if (!this.node.contains(document.activeElement) && this.parent) {
|
|
234
|
-
this.parent.activate();
|
|
235
|
-
}
|
|
236
|
-
break;
|
|
237
|
-
default:
|
|
238
|
-
break;
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
/**
|
|
242
|
-
* Handle `after-attach` messages for the widget.
|
|
243
|
-
*/
|
|
244
|
-
onAfterAttach(msg) {
|
|
245
|
-
this.node.addEventListener('click', this);
|
|
246
|
-
}
|
|
247
|
-
/**
|
|
248
|
-
* Handle `before-detach` messages for the widget.
|
|
249
|
-
*/
|
|
250
|
-
onBeforeDetach(msg) {
|
|
251
|
-
this.node.removeEventListener('click', this);
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
exports.Toolbar = Toolbar;
|
|
255
|
-
/**
|
|
256
|
-
* The namespace for Toolbar class statics.
|
|
257
|
-
*/
|
|
258
|
-
(function (Toolbar) {
|
|
259
|
-
/**
|
|
260
|
-
* Create an interrupt toolbar item.
|
|
261
|
-
*/
|
|
262
|
-
function createInterruptButton(session) {
|
|
263
|
-
return new ToolbarButton({
|
|
264
|
-
iconClassName: 'jp-StopIcon jp-Icon jp-Icon-16',
|
|
265
|
-
onClick: () => {
|
|
266
|
-
if (session.kernel) {
|
|
267
|
-
session.kernel.interrupt();
|
|
268
|
-
}
|
|
269
|
-
},
|
|
270
|
-
tooltip: 'Interrupt the kernel'
|
|
271
|
-
});
|
|
272
|
-
}
|
|
273
|
-
Toolbar.createInterruptButton = createInterruptButton;
|
|
274
|
-
/**
|
|
275
|
-
* Create a restart toolbar item.
|
|
276
|
-
*/
|
|
277
|
-
function createRestartButton(session) {
|
|
278
|
-
return new ToolbarButton({
|
|
279
|
-
iconClassName: 'jp-RefreshIcon jp-Icon jp-Icon-16',
|
|
280
|
-
onClick: () => {
|
|
281
|
-
session.restart();
|
|
282
|
-
},
|
|
283
|
-
tooltip: 'Restart the kernel'
|
|
284
|
-
});
|
|
285
|
-
}
|
|
286
|
-
Toolbar.createRestartButton = createRestartButton;
|
|
287
|
-
/**
|
|
288
|
-
* Create a toolbar spacer item.
|
|
289
|
-
*
|
|
290
|
-
* #### Notes
|
|
291
|
-
* It is a flex spacer that separates the left toolbar items
|
|
292
|
-
* from the right toolbar items.
|
|
293
|
-
*/
|
|
294
|
-
function createSpacerItem() {
|
|
295
|
-
return new Private.Spacer();
|
|
296
|
-
}
|
|
297
|
-
Toolbar.createSpacerItem = createSpacerItem;
|
|
298
|
-
/**
|
|
299
|
-
* Create a kernel name indicator item.
|
|
300
|
-
*
|
|
301
|
-
* #### Notes
|
|
302
|
-
* It will display the `'display_name`' of the current kernel,
|
|
303
|
-
* or `'No Kernel!'` if there is no kernel.
|
|
304
|
-
* It can handle a change in context or kernel.
|
|
305
|
-
*/
|
|
306
|
-
function createKernelNameItem(session) {
|
|
307
|
-
return new Private.KernelName({ session });
|
|
308
|
-
}
|
|
309
|
-
Toolbar.createKernelNameItem = createKernelNameItem;
|
|
310
|
-
/**
|
|
311
|
-
* Create a kernel status indicator item.
|
|
312
|
-
*
|
|
313
|
-
* #### Notes
|
|
314
|
-
* It show display a busy status if the kernel status is
|
|
315
|
-
* not idle.
|
|
316
|
-
* It will show the current status in the node title.
|
|
317
|
-
* It can handle a change to the context or the kernel.
|
|
318
|
-
*/
|
|
319
|
-
function createKernelStatusItem(session) {
|
|
320
|
-
return new Private.KernelStatus(session);
|
|
321
|
-
}
|
|
322
|
-
Toolbar.createKernelStatusItem = createKernelStatusItem;
|
|
323
|
-
})(Toolbar = exports.Toolbar || (exports.Toolbar = {}));
|
|
324
|
-
/**
|
|
325
|
-
* React component for a toolbar button.
|
|
326
|
-
*
|
|
327
|
-
* @param props - The props for ToolbarButtonComponent.
|
|
328
|
-
*/
|
|
329
|
-
function ToolbarButtonComponent(props) {
|
|
330
|
-
const handleMouseDown = (event) => {
|
|
331
|
-
event.preventDefault();
|
|
332
|
-
props.onClick();
|
|
333
|
-
};
|
|
334
|
-
return (React.createElement("button", { className: props.className
|
|
335
|
-
? props.className + ' jp-ToolbarButtonComponent'
|
|
336
|
-
: 'jp-ToolbarButtonComponent', disabled: props.enabled === false, onMouseDown: handleMouseDown, title: props.tooltip || props.iconLabel },
|
|
337
|
-
props.iconClassName && (React.createElement("span", { className: props.iconClassName + ' jp-ToolbarButtonComponent-icon' })),
|
|
338
|
-
props.label && (React.createElement("span", { className: "jp-ToolbarButtonComponent-label" }, props.label))));
|
|
339
|
-
}
|
|
340
|
-
exports.ToolbarButtonComponent = ToolbarButtonComponent;
|
|
341
|
-
/**
|
|
342
|
-
* Phosphor Widget version of ToolbarButtonComponent.
|
|
343
|
-
*/
|
|
344
|
-
class ToolbarButton extends vdom_1.ReactElementWidget {
|
|
345
|
-
/**
|
|
346
|
-
* Create a ToolbarButton.
|
|
347
|
-
*
|
|
348
|
-
* @param props - Props for ToolbarButtonComponent.
|
|
349
|
-
*/
|
|
350
|
-
constructor(props = {}) {
|
|
351
|
-
super(React.createElement(ToolbarButtonComponent, Object.assign({}, props)));
|
|
352
|
-
this.addClass('jp-ToolbarButton');
|
|
353
|
-
}
|
|
354
|
-
}
|
|
355
|
-
exports.ToolbarButton = ToolbarButton;
|
|
356
|
-
/**
|
|
357
|
-
* React component for a toolbar button that wraps a command.
|
|
358
|
-
*
|
|
359
|
-
* This wraps the ToolbarButtonComponent and watches the command registry
|
|
360
|
-
* for changes to the command.
|
|
361
|
-
*/
|
|
362
|
-
class CommandToolbarButtonComponent extends React.Component {
|
|
363
|
-
constructor(props) {
|
|
364
|
-
super(props);
|
|
365
|
-
props.commands.commandChanged.connect(this._onChange, this);
|
|
366
|
-
this._childProps = Private.propsFromCommand(this.props);
|
|
367
|
-
}
|
|
368
|
-
render() {
|
|
369
|
-
return React.createElement(ToolbarButtonComponent, Object.assign({}, this._childProps));
|
|
370
|
-
}
|
|
371
|
-
_onChange(sender, args) {
|
|
372
|
-
if (args.id !== this.props.id) {
|
|
373
|
-
return; // Not our command
|
|
374
|
-
}
|
|
375
|
-
if (args.type !== 'changed') {
|
|
376
|
-
return; // Not a change
|
|
377
|
-
}
|
|
378
|
-
this._childProps = Private.propsFromCommand(this.props);
|
|
379
|
-
this.forceUpdate();
|
|
380
|
-
}
|
|
381
|
-
}
|
|
382
|
-
exports.CommandToolbarButtonComponent = CommandToolbarButtonComponent;
|
|
383
|
-
/**
|
|
384
|
-
* Phosphor Widget version of ToolbarButtonComponent.
|
|
385
|
-
*/
|
|
386
|
-
class CommandToolbarButton extends vdom_1.ReactElementWidget {
|
|
387
|
-
constructor(props) {
|
|
388
|
-
super(React.createElement(CommandToolbarButtonComponent, Object.assign({}, props)));
|
|
389
|
-
this.addClass('jp-CommandToolbarButton');
|
|
390
|
-
}
|
|
391
|
-
}
|
|
392
|
-
exports.CommandToolbarButton = CommandToolbarButton;
|
|
393
|
-
/**
|
|
394
|
-
* A namespace for private data.
|
|
395
|
-
*/
|
|
396
|
-
var Private;
|
|
397
|
-
(function (Private) {
|
|
398
|
-
function propsFromCommand(options) {
|
|
399
|
-
let { commands, id } = options;
|
|
400
|
-
const iconClassName = commands.iconClass(id);
|
|
401
|
-
const iconLabel = commands.iconLabel(id);
|
|
402
|
-
const label = commands.label(id);
|
|
403
|
-
let className = commands.className(id);
|
|
404
|
-
// Add the boolean state classes.
|
|
405
|
-
if (commands.isToggled(id)) {
|
|
406
|
-
className += ' p-mod-toggled';
|
|
407
|
-
}
|
|
408
|
-
if (!commands.isVisible(id)) {
|
|
409
|
-
className += ' p-mod-hidden';
|
|
410
|
-
}
|
|
411
|
-
const tooltip = commands.caption(id) || label || iconLabel;
|
|
412
|
-
const onClick = () => {
|
|
413
|
-
commands.execute(id);
|
|
414
|
-
};
|
|
415
|
-
const enabled = commands.isEnabled(id);
|
|
416
|
-
return { className, iconClassName, tooltip, onClick, enabled };
|
|
417
|
-
}
|
|
418
|
-
Private.propsFromCommand = propsFromCommand;
|
|
419
|
-
/**
|
|
420
|
-
* An attached property for the name of a toolbar item.
|
|
421
|
-
*/
|
|
422
|
-
Private.nameProperty = new properties_1.AttachedProperty({
|
|
423
|
-
name: 'name',
|
|
424
|
-
create: () => ''
|
|
425
|
-
});
|
|
426
|
-
/**
|
|
427
|
-
* A no-op function.
|
|
428
|
-
*/
|
|
429
|
-
function noOp() {
|
|
430
|
-
/* no-op */
|
|
431
|
-
}
|
|
432
|
-
Private.noOp = noOp;
|
|
433
|
-
/**
|
|
434
|
-
* A spacer widget.
|
|
435
|
-
*/
|
|
436
|
-
class Spacer extends widgets_1.Widget {
|
|
437
|
-
/**
|
|
438
|
-
* Construct a new spacer widget.
|
|
439
|
-
*/
|
|
440
|
-
constructor() {
|
|
441
|
-
super();
|
|
442
|
-
this.addClass(TOOLBAR_SPACER_CLASS);
|
|
443
|
-
}
|
|
444
|
-
}
|
|
445
|
-
Private.Spacer = Spacer;
|
|
446
|
-
/**
|
|
447
|
-
* React component for a kernel name button.
|
|
448
|
-
*
|
|
449
|
-
* This wraps the ToolbarButtonComponent and watches the kernel
|
|
450
|
-
* session for changes.
|
|
451
|
-
*/
|
|
452
|
-
class KernelNameComponent extends React.Component {
|
|
453
|
-
constructor(props) {
|
|
454
|
-
super(props);
|
|
455
|
-
props.session.kernelChanged.connect(this._onKernelChanged, this);
|
|
456
|
-
this._childProps = {
|
|
457
|
-
className: TOOLBAR_KERNEL_NAME_CLASS,
|
|
458
|
-
onClick: () => {
|
|
459
|
-
this.props.session.selectKernel();
|
|
460
|
-
},
|
|
461
|
-
tooltip: 'Switch kernel',
|
|
462
|
-
label: props.session.kernelDisplayName
|
|
463
|
-
};
|
|
464
|
-
}
|
|
465
|
-
render() {
|
|
466
|
-
return React.createElement(ToolbarButtonComponent, Object.assign({}, this._childProps));
|
|
467
|
-
}
|
|
468
|
-
/**
|
|
469
|
-
* Update the text of the kernel name item.
|
|
470
|
-
*/
|
|
471
|
-
_onKernelChanged(session) {
|
|
472
|
-
this._childProps.label = session.kernelDisplayName;
|
|
473
|
-
this.forceUpdate();
|
|
474
|
-
}
|
|
475
|
-
}
|
|
476
|
-
Private.KernelNameComponent = KernelNameComponent;
|
|
477
|
-
/**
|
|
478
|
-
* Phosphor Widget version of ToolbarButtonComponent.
|
|
479
|
-
*/
|
|
480
|
-
class KernelName extends vdom_1.ReactElementWidget {
|
|
481
|
-
constructor(props) {
|
|
482
|
-
super(React.createElement(KernelNameComponent, Object.assign({}, props)));
|
|
483
|
-
this.addClass('jp-KernelName');
|
|
484
|
-
}
|
|
485
|
-
}
|
|
486
|
-
Private.KernelName = KernelName;
|
|
487
|
-
/**
|
|
488
|
-
* A toolbar item that displays kernel status.
|
|
489
|
-
*/
|
|
490
|
-
class KernelStatus extends widgets_1.Widget {
|
|
491
|
-
/**
|
|
492
|
-
* Construct a new kernel status widget.
|
|
493
|
-
*/
|
|
494
|
-
constructor(session) {
|
|
495
|
-
super();
|
|
496
|
-
this.addClass(TOOLBAR_KERNEL_STATUS_CLASS);
|
|
497
|
-
this._onStatusChanged(session);
|
|
498
|
-
session.statusChanged.connect(this._onStatusChanged, this);
|
|
499
|
-
}
|
|
500
|
-
/**
|
|
501
|
-
* Handle a status on a kernel.
|
|
502
|
-
*/
|
|
503
|
-
_onStatusChanged(session) {
|
|
504
|
-
if (this.isDisposed) {
|
|
505
|
-
return;
|
|
506
|
-
}
|
|
507
|
-
let status = session.status;
|
|
508
|
-
this.toggleClass(TOOLBAR_IDLE_CLASS, status === 'idle');
|
|
509
|
-
this.toggleClass(TOOLBAR_BUSY_CLASS, status !== 'idle');
|
|
510
|
-
let title = 'Kernel ' + status[0].toUpperCase() + status.slice(1);
|
|
511
|
-
this.node.title = title;
|
|
512
|
-
}
|
|
513
|
-
}
|
|
514
|
-
Private.KernelStatus = KernelStatus;
|
|
515
|
-
})(Private || (Private = {}));
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright (c) Jupyter Development Team.
|
|
3
|
+
// Distributed under the terms of the Modified BSD License.
|
|
4
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
5
|
+
if (mod && mod.__esModule) return mod;
|
|
6
|
+
var result = {};
|
|
7
|
+
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
|
|
8
|
+
result["default"] = mod;
|
|
9
|
+
return result;
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const vdom_1 = require("./vdom");
|
|
13
|
+
const algorithm_1 = require("@phosphor/algorithm");
|
|
14
|
+
const messaging_1 = require("@phosphor/messaging");
|
|
15
|
+
const properties_1 = require("@phosphor/properties");
|
|
16
|
+
const widgets_1 = require("@phosphor/widgets");
|
|
17
|
+
const React = __importStar(require("react"));
|
|
18
|
+
/**
|
|
19
|
+
* The class name added to toolbars.
|
|
20
|
+
*/
|
|
21
|
+
const TOOLBAR_CLASS = 'jp-Toolbar';
|
|
22
|
+
/**
|
|
23
|
+
* The class name added to toolbar items.
|
|
24
|
+
*/
|
|
25
|
+
const TOOLBAR_ITEM_CLASS = 'jp-Toolbar-item';
|
|
26
|
+
/**
|
|
27
|
+
* The class name added to toolbar kernel name text.
|
|
28
|
+
*/
|
|
29
|
+
const TOOLBAR_KERNEL_NAME_CLASS = 'jp-Toolbar-kernelName';
|
|
30
|
+
/**
|
|
31
|
+
* The class name added to toolbar spacer.
|
|
32
|
+
*/
|
|
33
|
+
const TOOLBAR_SPACER_CLASS = 'jp-Toolbar-spacer';
|
|
34
|
+
/**
|
|
35
|
+
* The class name added to toolbar kernel status icon.
|
|
36
|
+
*/
|
|
37
|
+
const TOOLBAR_KERNEL_STATUS_CLASS = 'jp-Toolbar-kernelStatus';
|
|
38
|
+
/**
|
|
39
|
+
* The class name added to a busy kernel indicator.
|
|
40
|
+
*/
|
|
41
|
+
const TOOLBAR_BUSY_CLASS = 'jp-FilledCircleIcon';
|
|
42
|
+
const TOOLBAR_IDLE_CLASS = 'jp-CircleIcon';
|
|
43
|
+
/**
|
|
44
|
+
* A layout for toolbars.
|
|
45
|
+
*
|
|
46
|
+
* #### Notes
|
|
47
|
+
* This layout automatically collapses its height if there are no visible
|
|
48
|
+
* toolbar widgets, and expands to the standard toolbar height if there are
|
|
49
|
+
* visible toolbar widgets.
|
|
50
|
+
*/
|
|
51
|
+
class ToolbarLayout extends widgets_1.PanelLayout {
|
|
52
|
+
constructor() {
|
|
53
|
+
super(...arguments);
|
|
54
|
+
this._dirty = false;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* A message handler invoked on a `'fit-request'` message.
|
|
58
|
+
*
|
|
59
|
+
* If any child widget is visible, expand the toolbar height to the normal
|
|
60
|
+
* toolbar height.
|
|
61
|
+
*/
|
|
62
|
+
onFitRequest(msg) {
|
|
63
|
+
super.onFitRequest(msg);
|
|
64
|
+
if (this.parent.isAttached) {
|
|
65
|
+
// If there are any widgets not explicitly hidden, expand the toolbar to
|
|
66
|
+
// accommodate them.
|
|
67
|
+
if (algorithm_1.some(this.widgets, w => !w.isHidden)) {
|
|
68
|
+
this.parent.node.style.minHeight = 'var(--jp-private-toolbar-height)';
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
this.parent.node.style.minHeight = '';
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
// Set the dirty flag to ensure only a single update occurs.
|
|
75
|
+
this._dirty = true;
|
|
76
|
+
// Notify the ancestor that it should fit immediately. This may
|
|
77
|
+
// cause a resize of the parent, fulfilling the required update.
|
|
78
|
+
if (this.parent.parent) {
|
|
79
|
+
messaging_1.MessageLoop.sendMessage(this.parent.parent, widgets_1.Widget.Msg.FitRequest);
|
|
80
|
+
}
|
|
81
|
+
// If the dirty flag is still set, the parent was not resized.
|
|
82
|
+
// Trigger the required update on the parent widget immediately.
|
|
83
|
+
if (this._dirty) {
|
|
84
|
+
messaging_1.MessageLoop.sendMessage(this.parent, widgets_1.Widget.Msg.UpdateRequest);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* A message handler invoked on an `'update-request'` message.
|
|
89
|
+
*/
|
|
90
|
+
onUpdateRequest(msg) {
|
|
91
|
+
super.onUpdateRequest(msg);
|
|
92
|
+
if (this.parent.isVisible) {
|
|
93
|
+
this._dirty = false;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* A message handler invoked on a `'child-shown'` message.
|
|
98
|
+
*/
|
|
99
|
+
onChildShown(msg) {
|
|
100
|
+
super.onChildShown(msg);
|
|
101
|
+
// Post a fit request for the parent widget.
|
|
102
|
+
this.parent.fit();
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* A message handler invoked on a `'child-hidden'` message.
|
|
106
|
+
*/
|
|
107
|
+
onChildHidden(msg) {
|
|
108
|
+
super.onChildHidden(msg);
|
|
109
|
+
// Post a fit request for the parent widget.
|
|
110
|
+
this.parent.fit();
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* A message handler invoked on a `'before-attach'` message.
|
|
114
|
+
*/
|
|
115
|
+
onBeforeAttach(msg) {
|
|
116
|
+
super.onBeforeAttach(msg);
|
|
117
|
+
// Post a fit request for the parent widget.
|
|
118
|
+
this.parent.fit();
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Attach a widget to the parent's DOM node.
|
|
122
|
+
*
|
|
123
|
+
* @param index - The current index of the widget in the layout.
|
|
124
|
+
*
|
|
125
|
+
* @param widget - The widget to attach to the parent.
|
|
126
|
+
*
|
|
127
|
+
* #### Notes
|
|
128
|
+
* This is a reimplementation of the superclass method.
|
|
129
|
+
*/
|
|
130
|
+
attachWidget(index, widget) {
|
|
131
|
+
super.attachWidget(index, widget);
|
|
132
|
+
// Post a fit request for the parent widget.
|
|
133
|
+
this.parent.fit();
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Detach a widget from the parent's DOM node.
|
|
137
|
+
*
|
|
138
|
+
* @param index - The previous index of the widget in the layout.
|
|
139
|
+
*
|
|
140
|
+
* @param widget - The widget to detach from the parent.
|
|
141
|
+
*
|
|
142
|
+
* #### Notes
|
|
143
|
+
* This is a reimplementation of the superclass method.
|
|
144
|
+
*/
|
|
145
|
+
detachWidget(index, widget) {
|
|
146
|
+
super.detachWidget(index, widget);
|
|
147
|
+
// Post a fit request for the parent widget.
|
|
148
|
+
this.parent.fit();
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* A class which provides a toolbar widget.
|
|
153
|
+
*/
|
|
154
|
+
class Toolbar extends widgets_1.Widget {
|
|
155
|
+
/**
|
|
156
|
+
* Construct a new toolbar widget.
|
|
157
|
+
*/
|
|
158
|
+
constructor() {
|
|
159
|
+
super();
|
|
160
|
+
this.addClass(TOOLBAR_CLASS);
|
|
161
|
+
this.layout = new ToolbarLayout();
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Get an iterator over the ordered toolbar item names.
|
|
165
|
+
*
|
|
166
|
+
* @returns An iterator over the toolbar item names.
|
|
167
|
+
*/
|
|
168
|
+
names() {
|
|
169
|
+
let layout = this.layout;
|
|
170
|
+
return algorithm_1.map(layout.widgets, widget => {
|
|
171
|
+
return Private.nameProperty.get(widget);
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Add an item to the end of the toolbar.
|
|
176
|
+
*
|
|
177
|
+
* @param name - The name of the widget to add to the toolbar.
|
|
178
|
+
*
|
|
179
|
+
* @param widget - The widget to add to the toolbar.
|
|
180
|
+
*
|
|
181
|
+
* @param index - The optional name of the item to insert after.
|
|
182
|
+
*
|
|
183
|
+
* @returns Whether the item was added to toolbar. Returns false if
|
|
184
|
+
* an item of the same name is already in the toolbar.
|
|
185
|
+
*
|
|
186
|
+
* #### Notes
|
|
187
|
+
* The item can be removed from the toolbar by setting its parent to `null`.
|
|
188
|
+
*/
|
|
189
|
+
addItem(name, widget) {
|
|
190
|
+
let layout = this.layout;
|
|
191
|
+
return this.insertItem(layout.widgets.length, name, widget);
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Insert an item into the toolbar at the specified index.
|
|
195
|
+
*
|
|
196
|
+
* @param index - The index at which to insert the item.
|
|
197
|
+
*
|
|
198
|
+
* @param name - The name of the item.
|
|
199
|
+
*
|
|
200
|
+
* @param widget - The widget to add.
|
|
201
|
+
*
|
|
202
|
+
* @returns Whether the item was added to the toolbar. Returns false if
|
|
203
|
+
* an item of the same name is already in the toolbar.
|
|
204
|
+
*
|
|
205
|
+
* #### Notes
|
|
206
|
+
* The index will be clamped to the bounds of the items.
|
|
207
|
+
* The item can be removed from the toolbar by setting its parent to `null`.
|
|
208
|
+
*/
|
|
209
|
+
insertItem(index, name, widget) {
|
|
210
|
+
let existing = algorithm_1.find(this.names(), value => value === name);
|
|
211
|
+
if (existing) {
|
|
212
|
+
return false;
|
|
213
|
+
}
|
|
214
|
+
widget.addClass(TOOLBAR_ITEM_CLASS);
|
|
215
|
+
let layout = this.layout;
|
|
216
|
+
layout.insertWidget(index, widget);
|
|
217
|
+
Private.nameProperty.set(widget, name);
|
|
218
|
+
return true;
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Handle the DOM events for the widget.
|
|
222
|
+
*
|
|
223
|
+
* @param event - The DOM event sent to the widget.
|
|
224
|
+
*
|
|
225
|
+
* #### Notes
|
|
226
|
+
* This method implements the DOM `EventListener` interface and is
|
|
227
|
+
* called in response to events on the dock panel's node. It should
|
|
228
|
+
* not be called directly by user code.
|
|
229
|
+
*/
|
|
230
|
+
handleEvent(event) {
|
|
231
|
+
switch (event.type) {
|
|
232
|
+
case 'click':
|
|
233
|
+
if (!this.node.contains(document.activeElement) && this.parent) {
|
|
234
|
+
this.parent.activate();
|
|
235
|
+
}
|
|
236
|
+
break;
|
|
237
|
+
default:
|
|
238
|
+
break;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* Handle `after-attach` messages for the widget.
|
|
243
|
+
*/
|
|
244
|
+
onAfterAttach(msg) {
|
|
245
|
+
this.node.addEventListener('click', this);
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Handle `before-detach` messages for the widget.
|
|
249
|
+
*/
|
|
250
|
+
onBeforeDetach(msg) {
|
|
251
|
+
this.node.removeEventListener('click', this);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
exports.Toolbar = Toolbar;
|
|
255
|
+
/**
|
|
256
|
+
* The namespace for Toolbar class statics.
|
|
257
|
+
*/
|
|
258
|
+
(function (Toolbar) {
|
|
259
|
+
/**
|
|
260
|
+
* Create an interrupt toolbar item.
|
|
261
|
+
*/
|
|
262
|
+
function createInterruptButton(session) {
|
|
263
|
+
return new ToolbarButton({
|
|
264
|
+
iconClassName: 'jp-StopIcon jp-Icon jp-Icon-16',
|
|
265
|
+
onClick: () => {
|
|
266
|
+
if (session.kernel) {
|
|
267
|
+
session.kernel.interrupt();
|
|
268
|
+
}
|
|
269
|
+
},
|
|
270
|
+
tooltip: 'Interrupt the kernel'
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
Toolbar.createInterruptButton = createInterruptButton;
|
|
274
|
+
/**
|
|
275
|
+
* Create a restart toolbar item.
|
|
276
|
+
*/
|
|
277
|
+
function createRestartButton(session) {
|
|
278
|
+
return new ToolbarButton({
|
|
279
|
+
iconClassName: 'jp-RefreshIcon jp-Icon jp-Icon-16',
|
|
280
|
+
onClick: () => {
|
|
281
|
+
session.restart();
|
|
282
|
+
},
|
|
283
|
+
tooltip: 'Restart the kernel'
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
Toolbar.createRestartButton = createRestartButton;
|
|
287
|
+
/**
|
|
288
|
+
* Create a toolbar spacer item.
|
|
289
|
+
*
|
|
290
|
+
* #### Notes
|
|
291
|
+
* It is a flex spacer that separates the left toolbar items
|
|
292
|
+
* from the right toolbar items.
|
|
293
|
+
*/
|
|
294
|
+
function createSpacerItem() {
|
|
295
|
+
return new Private.Spacer();
|
|
296
|
+
}
|
|
297
|
+
Toolbar.createSpacerItem = createSpacerItem;
|
|
298
|
+
/**
|
|
299
|
+
* Create a kernel name indicator item.
|
|
300
|
+
*
|
|
301
|
+
* #### Notes
|
|
302
|
+
* It will display the `'display_name`' of the current kernel,
|
|
303
|
+
* or `'No Kernel!'` if there is no kernel.
|
|
304
|
+
* It can handle a change in context or kernel.
|
|
305
|
+
*/
|
|
306
|
+
function createKernelNameItem(session) {
|
|
307
|
+
return new Private.KernelName({ session });
|
|
308
|
+
}
|
|
309
|
+
Toolbar.createKernelNameItem = createKernelNameItem;
|
|
310
|
+
/**
|
|
311
|
+
* Create a kernel status indicator item.
|
|
312
|
+
*
|
|
313
|
+
* #### Notes
|
|
314
|
+
* It show display a busy status if the kernel status is
|
|
315
|
+
* not idle.
|
|
316
|
+
* It will show the current status in the node title.
|
|
317
|
+
* It can handle a change to the context or the kernel.
|
|
318
|
+
*/
|
|
319
|
+
function createKernelStatusItem(session) {
|
|
320
|
+
return new Private.KernelStatus(session);
|
|
321
|
+
}
|
|
322
|
+
Toolbar.createKernelStatusItem = createKernelStatusItem;
|
|
323
|
+
})(Toolbar = exports.Toolbar || (exports.Toolbar = {}));
|
|
324
|
+
/**
|
|
325
|
+
* React component for a toolbar button.
|
|
326
|
+
*
|
|
327
|
+
* @param props - The props for ToolbarButtonComponent.
|
|
328
|
+
*/
|
|
329
|
+
function ToolbarButtonComponent(props) {
|
|
330
|
+
const handleMouseDown = (event) => {
|
|
331
|
+
event.preventDefault();
|
|
332
|
+
props.onClick();
|
|
333
|
+
};
|
|
334
|
+
return (React.createElement("button", { className: props.className
|
|
335
|
+
? props.className + ' jp-ToolbarButtonComponent'
|
|
336
|
+
: 'jp-ToolbarButtonComponent', disabled: props.enabled === false, onMouseDown: handleMouseDown, title: props.tooltip || props.iconLabel },
|
|
337
|
+
props.iconClassName && (React.createElement("span", { className: props.iconClassName + ' jp-ToolbarButtonComponent-icon' })),
|
|
338
|
+
props.label && (React.createElement("span", { className: "jp-ToolbarButtonComponent-label" }, props.label))));
|
|
339
|
+
}
|
|
340
|
+
exports.ToolbarButtonComponent = ToolbarButtonComponent;
|
|
341
|
+
/**
|
|
342
|
+
* Phosphor Widget version of ToolbarButtonComponent.
|
|
343
|
+
*/
|
|
344
|
+
class ToolbarButton extends vdom_1.ReactElementWidget {
|
|
345
|
+
/**
|
|
346
|
+
* Create a ToolbarButton.
|
|
347
|
+
*
|
|
348
|
+
* @param props - Props for ToolbarButtonComponent.
|
|
349
|
+
*/
|
|
350
|
+
constructor(props = {}) {
|
|
351
|
+
super(React.createElement(ToolbarButtonComponent, Object.assign({}, props)));
|
|
352
|
+
this.addClass('jp-ToolbarButton');
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
exports.ToolbarButton = ToolbarButton;
|
|
356
|
+
/**
|
|
357
|
+
* React component for a toolbar button that wraps a command.
|
|
358
|
+
*
|
|
359
|
+
* This wraps the ToolbarButtonComponent and watches the command registry
|
|
360
|
+
* for changes to the command.
|
|
361
|
+
*/
|
|
362
|
+
class CommandToolbarButtonComponent extends React.Component {
|
|
363
|
+
constructor(props) {
|
|
364
|
+
super(props);
|
|
365
|
+
props.commands.commandChanged.connect(this._onChange, this);
|
|
366
|
+
this._childProps = Private.propsFromCommand(this.props);
|
|
367
|
+
}
|
|
368
|
+
render() {
|
|
369
|
+
return React.createElement(ToolbarButtonComponent, Object.assign({}, this._childProps));
|
|
370
|
+
}
|
|
371
|
+
_onChange(sender, args) {
|
|
372
|
+
if (args.id !== this.props.id) {
|
|
373
|
+
return; // Not our command
|
|
374
|
+
}
|
|
375
|
+
if (args.type !== 'changed') {
|
|
376
|
+
return; // Not a change
|
|
377
|
+
}
|
|
378
|
+
this._childProps = Private.propsFromCommand(this.props);
|
|
379
|
+
this.forceUpdate();
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
exports.CommandToolbarButtonComponent = CommandToolbarButtonComponent;
|
|
383
|
+
/**
|
|
384
|
+
* Phosphor Widget version of ToolbarButtonComponent.
|
|
385
|
+
*/
|
|
386
|
+
class CommandToolbarButton extends vdom_1.ReactElementWidget {
|
|
387
|
+
constructor(props) {
|
|
388
|
+
super(React.createElement(CommandToolbarButtonComponent, Object.assign({}, props)));
|
|
389
|
+
this.addClass('jp-CommandToolbarButton');
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
exports.CommandToolbarButton = CommandToolbarButton;
|
|
393
|
+
/**
|
|
394
|
+
* A namespace for private data.
|
|
395
|
+
*/
|
|
396
|
+
var Private;
|
|
397
|
+
(function (Private) {
|
|
398
|
+
function propsFromCommand(options) {
|
|
399
|
+
let { commands, id } = options;
|
|
400
|
+
const iconClassName = commands.iconClass(id);
|
|
401
|
+
const iconLabel = commands.iconLabel(id);
|
|
402
|
+
const label = commands.label(id);
|
|
403
|
+
let className = commands.className(id);
|
|
404
|
+
// Add the boolean state classes.
|
|
405
|
+
if (commands.isToggled(id)) {
|
|
406
|
+
className += ' p-mod-toggled';
|
|
407
|
+
}
|
|
408
|
+
if (!commands.isVisible(id)) {
|
|
409
|
+
className += ' p-mod-hidden';
|
|
410
|
+
}
|
|
411
|
+
const tooltip = commands.caption(id) || label || iconLabel;
|
|
412
|
+
const onClick = () => {
|
|
413
|
+
commands.execute(id);
|
|
414
|
+
};
|
|
415
|
+
const enabled = commands.isEnabled(id);
|
|
416
|
+
return { className, iconClassName, tooltip, onClick, enabled };
|
|
417
|
+
}
|
|
418
|
+
Private.propsFromCommand = propsFromCommand;
|
|
419
|
+
/**
|
|
420
|
+
* An attached property for the name of a toolbar item.
|
|
421
|
+
*/
|
|
422
|
+
Private.nameProperty = new properties_1.AttachedProperty({
|
|
423
|
+
name: 'name',
|
|
424
|
+
create: () => ''
|
|
425
|
+
});
|
|
426
|
+
/**
|
|
427
|
+
* A no-op function.
|
|
428
|
+
*/
|
|
429
|
+
function noOp() {
|
|
430
|
+
/* no-op */
|
|
431
|
+
}
|
|
432
|
+
Private.noOp = noOp;
|
|
433
|
+
/**
|
|
434
|
+
* A spacer widget.
|
|
435
|
+
*/
|
|
436
|
+
class Spacer extends widgets_1.Widget {
|
|
437
|
+
/**
|
|
438
|
+
* Construct a new spacer widget.
|
|
439
|
+
*/
|
|
440
|
+
constructor() {
|
|
441
|
+
super();
|
|
442
|
+
this.addClass(TOOLBAR_SPACER_CLASS);
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
Private.Spacer = Spacer;
|
|
446
|
+
/**
|
|
447
|
+
* React component for a kernel name button.
|
|
448
|
+
*
|
|
449
|
+
* This wraps the ToolbarButtonComponent and watches the kernel
|
|
450
|
+
* session for changes.
|
|
451
|
+
*/
|
|
452
|
+
class KernelNameComponent extends React.Component {
|
|
453
|
+
constructor(props) {
|
|
454
|
+
super(props);
|
|
455
|
+
props.session.kernelChanged.connect(this._onKernelChanged, this);
|
|
456
|
+
this._childProps = {
|
|
457
|
+
className: TOOLBAR_KERNEL_NAME_CLASS,
|
|
458
|
+
onClick: () => {
|
|
459
|
+
this.props.session.selectKernel();
|
|
460
|
+
},
|
|
461
|
+
tooltip: 'Switch kernel',
|
|
462
|
+
label: props.session.kernelDisplayName
|
|
463
|
+
};
|
|
464
|
+
}
|
|
465
|
+
render() {
|
|
466
|
+
return React.createElement(ToolbarButtonComponent, Object.assign({}, this._childProps));
|
|
467
|
+
}
|
|
468
|
+
/**
|
|
469
|
+
* Update the text of the kernel name item.
|
|
470
|
+
*/
|
|
471
|
+
_onKernelChanged(session) {
|
|
472
|
+
this._childProps.label = session.kernelDisplayName;
|
|
473
|
+
this.forceUpdate();
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
Private.KernelNameComponent = KernelNameComponent;
|
|
477
|
+
/**
|
|
478
|
+
* Phosphor Widget version of ToolbarButtonComponent.
|
|
479
|
+
*/
|
|
480
|
+
class KernelName extends vdom_1.ReactElementWidget {
|
|
481
|
+
constructor(props) {
|
|
482
|
+
super(React.createElement(KernelNameComponent, Object.assign({}, props)));
|
|
483
|
+
this.addClass('jp-KernelName');
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
Private.KernelName = KernelName;
|
|
487
|
+
/**
|
|
488
|
+
* A toolbar item that displays kernel status.
|
|
489
|
+
*/
|
|
490
|
+
class KernelStatus extends widgets_1.Widget {
|
|
491
|
+
/**
|
|
492
|
+
* Construct a new kernel status widget.
|
|
493
|
+
*/
|
|
494
|
+
constructor(session) {
|
|
495
|
+
super();
|
|
496
|
+
this.addClass(TOOLBAR_KERNEL_STATUS_CLASS);
|
|
497
|
+
this._onStatusChanged(session);
|
|
498
|
+
session.statusChanged.connect(this._onStatusChanged, this);
|
|
499
|
+
}
|
|
500
|
+
/**
|
|
501
|
+
* Handle a status on a kernel.
|
|
502
|
+
*/
|
|
503
|
+
_onStatusChanged(session) {
|
|
504
|
+
if (this.isDisposed) {
|
|
505
|
+
return;
|
|
506
|
+
}
|
|
507
|
+
let status = session.status;
|
|
508
|
+
this.toggleClass(TOOLBAR_IDLE_CLASS, status === 'idle');
|
|
509
|
+
this.toggleClass(TOOLBAR_BUSY_CLASS, status !== 'idle');
|
|
510
|
+
let title = 'Kernel ' + status[0].toUpperCase() + status.slice(1);
|
|
511
|
+
this.node.title = title;
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
Private.KernelStatus = KernelStatus;
|
|
515
|
+
})(Private || (Private = {}));
|