@jupyterlab/launcher 4.0.0-alpha.9 → 4.0.0-beta.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/lib/tokens.d.ts +1 -2
- package/lib/tokens.js +4 -0
- package/lib/tokens.js.map +1 -1
- package/lib/widget.d.ts +1 -2
- package/lib/widget.js +26 -23
- package/lib/widget.js.map +1 -1
- package/package.json +16 -15
- package/src/index.ts +9 -0
- package/src/tokens.ts +142 -0
- package/src/widget.tsx +376 -0
- package/style/base.css +18 -12
package/lib/tokens.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { ITranslator } from '@jupyterlab/translation';
|
|
2
2
|
import { VDomRenderer } from '@jupyterlab/ui-components';
|
|
3
|
-
import { IIterator } from '@lumino/algorithm';
|
|
4
3
|
import { CommandRegistry } from '@lumino/commands';
|
|
5
4
|
import { ReadonlyJSONObject, Token } from '@lumino/coreutils';
|
|
6
5
|
import { IDisposable } from '@lumino/disposable';
|
|
@@ -36,7 +35,7 @@ export declare namespace ILauncher {
|
|
|
36
35
|
/**
|
|
37
36
|
* Return an iterator of launcher items.
|
|
38
37
|
*/
|
|
39
|
-
items():
|
|
38
|
+
items(): IterableIterator<ILauncher.IItemOptions>;
|
|
40
39
|
}
|
|
41
40
|
/**
|
|
42
41
|
* The options used to create a Launcher.
|
package/lib/tokens.js
CHANGED
package/lib/tokens.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tokens.js","sourceRoot":"","sources":["../src/tokens.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"tokens.js","sourceRoot":"","sources":["../src/tokens.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,OAAO,EAAsB,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAI9D;;GAEG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,IAAI,KAAK,CAAY,gCAAgC,CAAC,CAAC"}
|
package/lib/widget.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { ITranslator } from '@jupyterlab/translation';
|
|
2
2
|
import { VDomModel, VDomRenderer } from '@jupyterlab/ui-components';
|
|
3
|
-
import { IIterator } from '@lumino/algorithm';
|
|
4
3
|
import { IDisposable } from '@lumino/disposable';
|
|
5
4
|
import * as React from 'react';
|
|
6
5
|
import { ILauncher } from './tokens';
|
|
@@ -23,7 +22,7 @@ export declare class LauncherModel extends VDomModel implements ILauncher.IModel
|
|
|
23
22
|
/**
|
|
24
23
|
* Return an iterator of launcher items.
|
|
25
24
|
*/
|
|
26
|
-
items():
|
|
25
|
+
items(): IterableIterator<ILauncher.IItemOptions>;
|
|
27
26
|
protected itemsList: ILauncher.IItemOptions[];
|
|
28
27
|
}
|
|
29
28
|
/**
|
package/lib/widget.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import { showErrorMessage } from '@jupyterlab/apputils';
|
|
4
4
|
import { nullTranslator } from '@jupyterlab/translation';
|
|
5
5
|
import { classes, LabIcon, VDomModel, VDomRenderer } from '@jupyterlab/ui-components';
|
|
6
|
-
import { ArrayExt,
|
|
6
|
+
import { ArrayExt, map } from '@lumino/algorithm';
|
|
7
7
|
import { DisposableDelegate } from '@lumino/disposable';
|
|
8
8
|
import { AttachedProperty } from '@lumino/properties';
|
|
9
9
|
import { Widget } from '@lumino/widgets';
|
|
@@ -45,7 +45,7 @@ export class LauncherModel extends VDomModel {
|
|
|
45
45
|
* Return an iterator of launcher items.
|
|
46
46
|
*/
|
|
47
47
|
items() {
|
|
48
|
-
return
|
|
48
|
+
return this.itemsList[Symbol.iterator]();
|
|
49
49
|
}
|
|
50
50
|
}
|
|
51
51
|
/**
|
|
@@ -104,13 +104,13 @@ export class Launcher extends VDomRenderer {
|
|
|
104
104
|
];
|
|
105
105
|
// First group-by categories
|
|
106
106
|
const categories = Object.create(null);
|
|
107
|
-
|
|
107
|
+
for (const item of this.model.items()) {
|
|
108
108
|
const cat = item.category || this._trans.__('Other');
|
|
109
109
|
if (!(cat in categories)) {
|
|
110
110
|
categories[cat] = [];
|
|
111
111
|
}
|
|
112
112
|
categories[cat].push(item);
|
|
113
|
-
}
|
|
113
|
+
}
|
|
114
114
|
// Within each category sort by rank
|
|
115
115
|
for (const cat in categories) {
|
|
116
116
|
categories[cat] = categories[cat].sort((a, b) => {
|
|
@@ -123,9 +123,9 @@ export class Launcher extends VDomRenderer {
|
|
|
123
123
|
// Assemble the final ordered list of categories, beginning with
|
|
124
124
|
// KNOWN_CATEGORIES.
|
|
125
125
|
const orderedCategories = [];
|
|
126
|
-
|
|
126
|
+
for (const cat of knownCategories) {
|
|
127
127
|
orderedCategories.push(cat);
|
|
128
|
-
}
|
|
128
|
+
}
|
|
129
129
|
for (const cat in categories) {
|
|
130
130
|
if (knownCategories.indexOf(cat) === -1) {
|
|
131
131
|
orderedCategories.push(cat);
|
|
@@ -137,19 +137,16 @@ export class Launcher extends VDomRenderer {
|
|
|
137
137
|
return;
|
|
138
138
|
}
|
|
139
139
|
const item = categories[cat][0];
|
|
140
|
-
const args =
|
|
140
|
+
const args = { ...item.args, cwd: this.cwd };
|
|
141
141
|
const kernel = kernelCategories.indexOf(cat) > -1;
|
|
142
|
-
// DEPRECATED: remove _icon when lumino 2.0 is adopted
|
|
143
|
-
// if icon is aliasing iconClass, don't use it
|
|
144
142
|
const iconClass = this._commands.iconClass(item.command, args);
|
|
145
|
-
const
|
|
146
|
-
const icon = _icon === iconClass ? undefined : _icon;
|
|
143
|
+
const icon = this._commands.icon(item.command, args);
|
|
147
144
|
if (cat in categories) {
|
|
148
145
|
section = (React.createElement("div", { className: "jp-Launcher-section", key: cat },
|
|
149
146
|
React.createElement("div", { className: "jp-Launcher-sectionHeader" },
|
|
150
147
|
React.createElement(LabIcon.resolveReact, { icon: icon, iconClass: classes(iconClass, 'jp-Icon-cover'), stylesheet: "launcherSection" }),
|
|
151
148
|
React.createElement("h2", { className: "jp-Launcher-sectionTitle" }, cat)),
|
|
152
|
-
React.createElement("div", { className: "jp-Launcher-cardContainer" },
|
|
149
|
+
React.createElement("div", { className: "jp-Launcher-cardContainer" }, Array.from(map(categories[cat], (item) => {
|
|
153
150
|
return Card(kernel, item, this, this._commands, this._trans, this._callback);
|
|
154
151
|
})))));
|
|
155
152
|
sections.push(section);
|
|
@@ -172,14 +169,16 @@ export class Launcher extends VDomRenderer {
|
|
|
172
169
|
*
|
|
173
170
|
* @param launcher - the Launcher instance to which this is added.
|
|
174
171
|
*
|
|
175
|
-
* @param
|
|
172
|
+
* @param commands - the command registry holding the command of item.
|
|
173
|
+
*
|
|
174
|
+
* @param trans - the translation bundle.
|
|
176
175
|
*
|
|
177
176
|
* @returns a vdom `VirtualElement` for the launcher card.
|
|
178
177
|
*/
|
|
179
178
|
function Card(kernel, item, launcher, commands, trans, launcherCallback) {
|
|
180
179
|
// Get some properties of the command
|
|
181
180
|
const command = item.command;
|
|
182
|
-
const args =
|
|
181
|
+
const args = { ...item.args, cwd: launcher.cwd };
|
|
183
182
|
const caption = commands.caption(command, args);
|
|
184
183
|
const label = commands.label(command, args);
|
|
185
184
|
const title = kernel ? label : caption || label;
|
|
@@ -192,15 +191,18 @@ function Card(kernel, item, launcher, commands, trans, launcherCallback) {
|
|
|
192
191
|
}
|
|
193
192
|
launcher.pending = true;
|
|
194
193
|
void commands
|
|
195
|
-
.execute(command,
|
|
194
|
+
.execute(command, {
|
|
195
|
+
...item.args,
|
|
196
|
+
cwd: launcher.cwd
|
|
197
|
+
})
|
|
196
198
|
.then(value => {
|
|
197
199
|
launcher.pending = false;
|
|
198
200
|
if (value instanceof Widget) {
|
|
199
201
|
launcherCallback(value);
|
|
200
|
-
launcher.dispose();
|
|
201
202
|
}
|
|
202
203
|
})
|
|
203
204
|
.catch(err => {
|
|
205
|
+
console.error(err);
|
|
204
206
|
launcher.pending = false;
|
|
205
207
|
void showErrorMessage(trans._p('Error', 'Launcher Error'), err);
|
|
206
208
|
});
|
|
@@ -212,11 +214,8 @@ function Card(kernel, item, launcher, commands, trans, launcherCallback) {
|
|
|
212
214
|
onclick();
|
|
213
215
|
}
|
|
214
216
|
};
|
|
215
|
-
// DEPRECATED: remove _icon when lumino 2.0 is adopted
|
|
216
|
-
// if icon is aliasing iconClass, don't use it
|
|
217
217
|
const iconClass = commands.iconClass(command, args);
|
|
218
|
-
const
|
|
219
|
-
const icon = _icon === iconClass ? undefined : _icon;
|
|
218
|
+
const icon = commands.icon(command, args);
|
|
220
219
|
// Return the VDOM element.
|
|
221
220
|
return (React.createElement("div", { className: "jp-LauncherCard", title: title, onClick: onclick, onKeyPress: onkeypress, tabIndex: 0, "data-category": item.category || trans.__('Other'), key: Private.keyProperty.get(item) },
|
|
222
221
|
React.createElement("div", { className: "jp-LauncherCard-icon" }, kernel ? (item.kernelIconUrl ? (React.createElement("img", { src: item.kernelIconUrl, className: "jp-Launcher-kernelIcon" })) : (React.createElement("div", { className: "jp-LauncherCard-noKernelIcon" }, label[0].toUpperCase()))) : (React.createElement(LabIcon.resolveReact, { icon: icon, iconClass: classes(iconClass, 'jp-Icon-cover'), stylesheet: "launcherCard" }))),
|
|
@@ -243,7 +242,11 @@ var Private;
|
|
|
243
242
|
* Create a fully specified item given item options.
|
|
244
243
|
*/
|
|
245
244
|
function createItem(options) {
|
|
246
|
-
return
|
|
245
|
+
return {
|
|
246
|
+
...options,
|
|
247
|
+
category: options.category || '',
|
|
248
|
+
rank: options.rank !== undefined ? options.rank : Infinity
|
|
249
|
+
};
|
|
247
250
|
}
|
|
248
251
|
Private.createItem = createItem;
|
|
249
252
|
/**
|
|
@@ -257,8 +260,8 @@ var Private;
|
|
|
257
260
|
return r1 < r2 ? -1 : 1; // Infinity safe
|
|
258
261
|
}
|
|
259
262
|
// Finally, compare by display name.
|
|
260
|
-
const aLabel = commands.label(a.command,
|
|
261
|
-
const bLabel = commands.label(b.command,
|
|
263
|
+
const aLabel = commands.label(a.command, { ...a.args, cwd });
|
|
264
|
+
const bLabel = commands.label(b.command, { ...b.args, cwd });
|
|
262
265
|
return aLabel.localeCompare(bLabel);
|
|
263
266
|
}
|
|
264
267
|
Private.sortCmp = sortCmp;
|
package/lib/widget.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"widget.js","sourceRoot":"","sources":["../src/widget.tsx"],"names":[],"mappings":"AAAA,0CAA0C;AAC1C,2DAA2D;AAE3D,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAEL,cAAc,EAEf,MAAM,yBAAyB,CAAC;AACjC,OAAO,EACL,OAAO,EACP,OAAO,EACP,SAAS,EACT,YAAY,EACb,MAAM,2BAA2B,CAAC;AACnC,OAAO,
|
|
1
|
+
{"version":3,"file":"widget.js","sourceRoot":"","sources":["../src/widget.tsx"],"names":[],"mappings":"AAAA,0CAA0C;AAC1C,2DAA2D;AAE3D,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAEL,cAAc,EAEf,MAAM,yBAAyB,CAAC;AACjC,OAAO,EACL,OAAO,EACP,OAAO,EACP,SAAS,EACT,YAAY,EACb,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAElD,OAAO,EAAE,kBAAkB,EAAe,MAAM,oBAAoB,CAAC;AACrE,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AACzC,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAG/B;;GAEG;AACH,MAAM,cAAc,GAAG,aAAa,CAAC;AAErC;;;GAGG;AACH,MAAM,OAAO,aAAc,SAAQ,SAAS;IAA5C;;QA+BY,cAAS,GAA6B,EAAE,CAAC;IACrD,CAAC;IA/BC;;;;;;;;;OASG;IACH,GAAG,CAAC,OAA+B;QACjC,wEAAwE;QACxE,MAAM,IAAI,GAAG,OAA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beta.1",
|
|
4
4
|
"description": "JupyterLab - Launcher Panel",
|
|
5
5
|
"homepage": "https://github.com/jupyterlab/jupyterlab",
|
|
6
6
|
"bugs": {
|
|
@@ -27,7 +27,8 @@
|
|
|
27
27
|
"lib/*.js.map",
|
|
28
28
|
"lib/*.js",
|
|
29
29
|
"style/*.css",
|
|
30
|
-
"style/index.js"
|
|
30
|
+
"style/index.js",
|
|
31
|
+
"src/**/*.{ts,tsx}"
|
|
31
32
|
],
|
|
32
33
|
"scripts": {
|
|
33
34
|
"build": "tsc -b",
|
|
@@ -36,22 +37,22 @@
|
|
|
36
37
|
"watch": "tsc -b --watch"
|
|
37
38
|
},
|
|
38
39
|
"dependencies": {
|
|
39
|
-
"@jupyterlab/apputils": "^4.0.0-
|
|
40
|
-
"@jupyterlab/translation": "^4.0.0-
|
|
41
|
-
"@jupyterlab/ui-components": "^4.0.0-
|
|
42
|
-
"@lumino/algorithm": "^
|
|
43
|
-
"@lumino/commands": "^
|
|
44
|
-
"@lumino/coreutils": "^
|
|
45
|
-
"@lumino/disposable": "^
|
|
46
|
-
"@lumino/properties": "^
|
|
47
|
-
"@lumino/widgets": "^
|
|
48
|
-
"react": "^
|
|
40
|
+
"@jupyterlab/apputils": "^4.0.0-beta.1",
|
|
41
|
+
"@jupyterlab/translation": "^4.0.0-beta.1",
|
|
42
|
+
"@jupyterlab/ui-components": "^4.0.0-beta.1",
|
|
43
|
+
"@lumino/algorithm": "^2.0.0",
|
|
44
|
+
"@lumino/commands": "^2.0.1",
|
|
45
|
+
"@lumino/coreutils": "^2.0.0",
|
|
46
|
+
"@lumino/disposable": "^2.0.0",
|
|
47
|
+
"@lumino/properties": "^2.0.0",
|
|
48
|
+
"@lumino/widgets": "^2.0.1",
|
|
49
|
+
"react": "^18.2.0"
|
|
49
50
|
},
|
|
50
51
|
"devDependencies": {
|
|
51
|
-
"@types/react": "^
|
|
52
|
+
"@types/react": "^18.0.26",
|
|
52
53
|
"rimraf": "~3.0.0",
|
|
53
|
-
"typedoc": "~0.
|
|
54
|
-
"typescript": "~
|
|
54
|
+
"typedoc": "~0.23.25",
|
|
55
|
+
"typescript": "~5.0.2"
|
|
55
56
|
},
|
|
56
57
|
"publishConfig": {
|
|
57
58
|
"access": "public"
|
package/src/index.ts
ADDED
package/src/tokens.ts
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) Jupyter Development Team.
|
|
3
|
+
* Distributed under the terms of the Modified BSD License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { ITranslator } from '@jupyterlab/translation';
|
|
7
|
+
import { VDomRenderer } from '@jupyterlab/ui-components';
|
|
8
|
+
import { CommandRegistry } from '@lumino/commands';
|
|
9
|
+
import { ReadonlyJSONObject, Token } from '@lumino/coreutils';
|
|
10
|
+
import { IDisposable } from '@lumino/disposable';
|
|
11
|
+
import { Widget } from '@lumino/widgets';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* The launcher token.
|
|
15
|
+
*/
|
|
16
|
+
export const ILauncher = new Token<ILauncher>('@jupyterlab/launcher:ILauncher');
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* The launcher interface.
|
|
20
|
+
*/
|
|
21
|
+
export interface ILauncher {
|
|
22
|
+
/**
|
|
23
|
+
* Add a command item to the launcher, and trigger re-render event for parent
|
|
24
|
+
* widget.
|
|
25
|
+
*
|
|
26
|
+
* @param options - The specification options for a launcher item.
|
|
27
|
+
*
|
|
28
|
+
* @returns A disposable that will remove the item from Launcher, and trigger
|
|
29
|
+
* re-render event for parent widget.
|
|
30
|
+
*
|
|
31
|
+
*/
|
|
32
|
+
add(options: ILauncher.IItemOptions): IDisposable;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* The namespace for `ILauncher` class statics.
|
|
37
|
+
*/
|
|
38
|
+
export namespace ILauncher {
|
|
39
|
+
/**
|
|
40
|
+
* An interface for the launcher model
|
|
41
|
+
*/
|
|
42
|
+
export interface IModel extends ILauncher, VDomRenderer.IModel {
|
|
43
|
+
/**
|
|
44
|
+
* Return an iterator of launcher items.
|
|
45
|
+
*/
|
|
46
|
+
items(): IterableIterator<ILauncher.IItemOptions>;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* The options used to create a Launcher.
|
|
51
|
+
*/
|
|
52
|
+
export interface IOptions {
|
|
53
|
+
/**
|
|
54
|
+
* The model of the launcher.
|
|
55
|
+
*/
|
|
56
|
+
model: IModel;
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* The cwd of the launcher.
|
|
60
|
+
*/
|
|
61
|
+
cwd: string;
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* The command registry used by the launcher.
|
|
65
|
+
*/
|
|
66
|
+
commands: CommandRegistry;
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* The application language translation.
|
|
70
|
+
*/
|
|
71
|
+
translator?: ITranslator;
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* The callback used when an item is launched.
|
|
75
|
+
*/
|
|
76
|
+
callback: (widget: Widget) => void;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* The options used to create a launcher item.
|
|
81
|
+
*/
|
|
82
|
+
export interface IItemOptions {
|
|
83
|
+
/**
|
|
84
|
+
* The command ID for the launcher item.
|
|
85
|
+
*
|
|
86
|
+
* #### Notes
|
|
87
|
+
* If the command's `execute` method returns a `Widget` or
|
|
88
|
+
* a promise that resolves with a `Widget`, then that widget will
|
|
89
|
+
* replace the launcher in the same location of the application
|
|
90
|
+
* shell. If the `execute` method does something else
|
|
91
|
+
* (i.e., create a modal dialog), then the launcher will not be
|
|
92
|
+
* disposed.
|
|
93
|
+
*/
|
|
94
|
+
command: string;
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* The arguments given to the command for
|
|
98
|
+
* creating the launcher item.
|
|
99
|
+
*
|
|
100
|
+
* ### Notes
|
|
101
|
+
* The launcher will also add the current working
|
|
102
|
+
* directory of the filebrowser in the `cwd` field
|
|
103
|
+
* of the args, which a command may use to create
|
|
104
|
+
* the activity with respect to the right directory.
|
|
105
|
+
*/
|
|
106
|
+
args?: ReadonlyJSONObject;
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* The category for the launcher item.
|
|
110
|
+
*
|
|
111
|
+
* The default value is an empty string.
|
|
112
|
+
*/
|
|
113
|
+
category?: string;
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* The rank for the launcher item.
|
|
117
|
+
*
|
|
118
|
+
* The rank is used when ordering launcher items for display. After grouping
|
|
119
|
+
* into categories, items are sorted in the following order:
|
|
120
|
+
* 1. Rank (lower is better)
|
|
121
|
+
* 3. Display Name (locale order)
|
|
122
|
+
*
|
|
123
|
+
* The default rank is `Infinity`.
|
|
124
|
+
*/
|
|
125
|
+
rank?: number;
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* For items that have a kernel associated with them, the URL of the kernel
|
|
129
|
+
* icon.
|
|
130
|
+
*
|
|
131
|
+
* This is not a CSS class, but the URL that points to the icon in the kernel
|
|
132
|
+
* spec.
|
|
133
|
+
*/
|
|
134
|
+
kernelIconUrl?: string;
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Metadata about the item. This can be used by the launcher to
|
|
138
|
+
* affect how the item is displayed.
|
|
139
|
+
*/
|
|
140
|
+
metadata?: ReadonlyJSONObject;
|
|
141
|
+
}
|
|
142
|
+
}
|
package/src/widget.tsx
ADDED
|
@@ -0,0 +1,376 @@
|
|
|
1
|
+
// Copyright (c) Jupyter Development Team.
|
|
2
|
+
// Distributed under the terms of the Modified BSD License.
|
|
3
|
+
|
|
4
|
+
import { showErrorMessage } from '@jupyterlab/apputils';
|
|
5
|
+
import {
|
|
6
|
+
ITranslator,
|
|
7
|
+
nullTranslator,
|
|
8
|
+
TranslationBundle
|
|
9
|
+
} from '@jupyterlab/translation';
|
|
10
|
+
import {
|
|
11
|
+
classes,
|
|
12
|
+
LabIcon,
|
|
13
|
+
VDomModel,
|
|
14
|
+
VDomRenderer
|
|
15
|
+
} from '@jupyterlab/ui-components';
|
|
16
|
+
import { ArrayExt, map } from '@lumino/algorithm';
|
|
17
|
+
import { CommandRegistry } from '@lumino/commands';
|
|
18
|
+
import { DisposableDelegate, IDisposable } from '@lumino/disposable';
|
|
19
|
+
import { AttachedProperty } from '@lumino/properties';
|
|
20
|
+
import { Widget } from '@lumino/widgets';
|
|
21
|
+
import * as React from 'react';
|
|
22
|
+
import { ILauncher } from './tokens';
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* The class name added to Launcher instances.
|
|
26
|
+
*/
|
|
27
|
+
const LAUNCHER_CLASS = 'jp-Launcher';
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* LauncherModel keeps track of the path to working directory and has a list of
|
|
31
|
+
* LauncherItems, which the Launcher will render.
|
|
32
|
+
*/
|
|
33
|
+
export class LauncherModel extends VDomModel implements ILauncher.IModel {
|
|
34
|
+
/**
|
|
35
|
+
* Add a command item to the launcher, and trigger re-render event for parent
|
|
36
|
+
* widget.
|
|
37
|
+
*
|
|
38
|
+
* @param options - The specification options for a launcher item.
|
|
39
|
+
*
|
|
40
|
+
* @returns A disposable that will remove the item from Launcher, and trigger
|
|
41
|
+
* re-render event for parent widget.
|
|
42
|
+
*
|
|
43
|
+
*/
|
|
44
|
+
add(options: ILauncher.IItemOptions): IDisposable {
|
|
45
|
+
// Create a copy of the options to circumvent mutations to the original.
|
|
46
|
+
const item = Private.createItem(options);
|
|
47
|
+
|
|
48
|
+
this.itemsList.push(item);
|
|
49
|
+
this.stateChanged.emit(void 0);
|
|
50
|
+
|
|
51
|
+
return new DisposableDelegate(() => {
|
|
52
|
+
ArrayExt.removeFirstOf(this.itemsList, item);
|
|
53
|
+
this.stateChanged.emit(void 0);
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Return an iterator of launcher items.
|
|
59
|
+
*/
|
|
60
|
+
items(): IterableIterator<ILauncher.IItemOptions> {
|
|
61
|
+
return this.itemsList[Symbol.iterator]();
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
protected itemsList: ILauncher.IItemOptions[] = [];
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* A virtual-DOM-based widget for the Launcher.
|
|
69
|
+
*/
|
|
70
|
+
export class Launcher extends VDomRenderer<ILauncher.IModel> {
|
|
71
|
+
/**
|
|
72
|
+
* Construct a new launcher widget.
|
|
73
|
+
*/
|
|
74
|
+
constructor(options: ILauncher.IOptions) {
|
|
75
|
+
super(options.model);
|
|
76
|
+
this._cwd = options.cwd;
|
|
77
|
+
this.translator = options.translator || nullTranslator;
|
|
78
|
+
this._trans = this.translator.load('jupyterlab');
|
|
79
|
+
this._callback = options.callback;
|
|
80
|
+
this._commands = options.commands;
|
|
81
|
+
this.addClass(LAUNCHER_CLASS);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* The cwd of the launcher.
|
|
86
|
+
*/
|
|
87
|
+
get cwd(): string {
|
|
88
|
+
return this._cwd;
|
|
89
|
+
}
|
|
90
|
+
set cwd(value: string) {
|
|
91
|
+
this._cwd = value;
|
|
92
|
+
this.update();
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Whether there is a pending item being launched.
|
|
97
|
+
*/
|
|
98
|
+
get pending(): boolean {
|
|
99
|
+
return this._pending;
|
|
100
|
+
}
|
|
101
|
+
set pending(value: boolean) {
|
|
102
|
+
this._pending = value;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Render the launcher to virtual DOM nodes.
|
|
107
|
+
*/
|
|
108
|
+
protected render(): React.ReactElement<any> | null {
|
|
109
|
+
// Bail if there is no model.
|
|
110
|
+
if (!this.model) {
|
|
111
|
+
return null;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
const knownCategories = [
|
|
115
|
+
this._trans.__('Notebook'),
|
|
116
|
+
this._trans.__('Console'),
|
|
117
|
+
this._trans.__('Other')
|
|
118
|
+
];
|
|
119
|
+
const kernelCategories = [
|
|
120
|
+
this._trans.__('Notebook'),
|
|
121
|
+
this._trans.__('Console')
|
|
122
|
+
];
|
|
123
|
+
|
|
124
|
+
// First group-by categories
|
|
125
|
+
const categories = Object.create(null);
|
|
126
|
+
for (const item of this.model.items()) {
|
|
127
|
+
const cat = item.category || this._trans.__('Other');
|
|
128
|
+
if (!(cat in categories)) {
|
|
129
|
+
categories[cat] = [];
|
|
130
|
+
}
|
|
131
|
+
categories[cat].push(item);
|
|
132
|
+
}
|
|
133
|
+
// Within each category sort by rank
|
|
134
|
+
for (const cat in categories) {
|
|
135
|
+
categories[cat] = categories[cat].sort(
|
|
136
|
+
(a: ILauncher.IItemOptions, b: ILauncher.IItemOptions) => {
|
|
137
|
+
return Private.sortCmp(a, b, this._cwd, this._commands);
|
|
138
|
+
}
|
|
139
|
+
);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// Variable to help create sections
|
|
143
|
+
const sections: React.ReactElement<any>[] = [];
|
|
144
|
+
let section: React.ReactElement<any>;
|
|
145
|
+
|
|
146
|
+
// Assemble the final ordered list of categories, beginning with
|
|
147
|
+
// KNOWN_CATEGORIES.
|
|
148
|
+
const orderedCategories: string[] = [];
|
|
149
|
+
for (const cat of knownCategories) {
|
|
150
|
+
orderedCategories.push(cat);
|
|
151
|
+
}
|
|
152
|
+
for (const cat in categories) {
|
|
153
|
+
if (knownCategories.indexOf(cat) === -1) {
|
|
154
|
+
orderedCategories.push(cat);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// Now create the sections for each category
|
|
159
|
+
orderedCategories.forEach(cat => {
|
|
160
|
+
if (!categories[cat]) {
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
const item = categories[cat][0] as ILauncher.IItemOptions;
|
|
164
|
+
const args = { ...item.args, cwd: this.cwd };
|
|
165
|
+
const kernel = kernelCategories.indexOf(cat) > -1;
|
|
166
|
+
const iconClass = this._commands.iconClass(item.command, args);
|
|
167
|
+
const icon = this._commands.icon(item.command, args);
|
|
168
|
+
|
|
169
|
+
if (cat in categories) {
|
|
170
|
+
section = (
|
|
171
|
+
<div className="jp-Launcher-section" key={cat}>
|
|
172
|
+
<div className="jp-Launcher-sectionHeader">
|
|
173
|
+
<LabIcon.resolveReact
|
|
174
|
+
icon={icon}
|
|
175
|
+
iconClass={classes(iconClass, 'jp-Icon-cover')}
|
|
176
|
+
stylesheet="launcherSection"
|
|
177
|
+
/>
|
|
178
|
+
<h2 className="jp-Launcher-sectionTitle">{cat}</h2>
|
|
179
|
+
</div>
|
|
180
|
+
<div className="jp-Launcher-cardContainer">
|
|
181
|
+
{Array.from(
|
|
182
|
+
map(categories[cat], (item: ILauncher.IItemOptions) => {
|
|
183
|
+
return Card(
|
|
184
|
+
kernel,
|
|
185
|
+
item,
|
|
186
|
+
this,
|
|
187
|
+
this._commands,
|
|
188
|
+
this._trans,
|
|
189
|
+
this._callback
|
|
190
|
+
);
|
|
191
|
+
})
|
|
192
|
+
)}
|
|
193
|
+
</div>
|
|
194
|
+
</div>
|
|
195
|
+
);
|
|
196
|
+
sections.push(section);
|
|
197
|
+
}
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
// Wrap the sections in body and content divs.
|
|
201
|
+
return (
|
|
202
|
+
<div className="jp-Launcher-body">
|
|
203
|
+
<div className="jp-Launcher-content">
|
|
204
|
+
<div className="jp-Launcher-cwd">
|
|
205
|
+
<h3>{this.cwd}</h3>
|
|
206
|
+
</div>
|
|
207
|
+
{sections}
|
|
208
|
+
</div>
|
|
209
|
+
</div>
|
|
210
|
+
);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
protected translator: ITranslator;
|
|
214
|
+
private _trans: TranslationBundle;
|
|
215
|
+
private _commands: CommandRegistry;
|
|
216
|
+
private _callback: (widget: Widget) => void;
|
|
217
|
+
private _pending = false;
|
|
218
|
+
private _cwd = '';
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* A pure tsx component for a launcher card.
|
|
222
|
+
*
|
|
223
|
+
* @param kernel - whether the item takes uses a kernel.
|
|
224
|
+
*
|
|
225
|
+
* @param item - the launcher item to render.
|
|
226
|
+
*
|
|
227
|
+
* @param launcher - the Launcher instance to which this is added.
|
|
228
|
+
*
|
|
229
|
+
* @param commands - the command registry holding the command of item.
|
|
230
|
+
*
|
|
231
|
+
* @param trans - the translation bundle.
|
|
232
|
+
*
|
|
233
|
+
* @returns a vdom `VirtualElement` for the launcher card.
|
|
234
|
+
*/
|
|
235
|
+
function Card(
|
|
236
|
+
kernel: boolean,
|
|
237
|
+
item: ILauncher.IItemOptions,
|
|
238
|
+
launcher: Launcher,
|
|
239
|
+
commands: CommandRegistry,
|
|
240
|
+
trans: TranslationBundle,
|
|
241
|
+
launcherCallback: (widget: Widget) => void
|
|
242
|
+
): React.ReactElement<any> {
|
|
243
|
+
// Get some properties of the command
|
|
244
|
+
const command = item.command;
|
|
245
|
+
const args = { ...item.args, cwd: launcher.cwd };
|
|
246
|
+
const caption = commands.caption(command, args);
|
|
247
|
+
const label = commands.label(command, args);
|
|
248
|
+
const title = kernel ? label : caption || label;
|
|
249
|
+
|
|
250
|
+
// Build the onclick handler.
|
|
251
|
+
const onclick = () => {
|
|
252
|
+
// If an item has already been launched,
|
|
253
|
+
// don't try to launch another.
|
|
254
|
+
if (launcher.pending === true) {
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
257
|
+
launcher.pending = true;
|
|
258
|
+
void commands
|
|
259
|
+
.execute(command, {
|
|
260
|
+
...item.args,
|
|
261
|
+
cwd: launcher.cwd
|
|
262
|
+
})
|
|
263
|
+
.then(value => {
|
|
264
|
+
launcher.pending = false;
|
|
265
|
+
if (value instanceof Widget) {
|
|
266
|
+
launcherCallback(value);
|
|
267
|
+
}
|
|
268
|
+
})
|
|
269
|
+
.catch(err => {
|
|
270
|
+
console.error(err);
|
|
271
|
+
launcher.pending = false;
|
|
272
|
+
void showErrorMessage(trans._p('Error', 'Launcher Error'), err);
|
|
273
|
+
});
|
|
274
|
+
};
|
|
275
|
+
|
|
276
|
+
// With tabindex working, you can now pick a kernel by tabbing around and
|
|
277
|
+
// pressing Enter.
|
|
278
|
+
const onkeypress = (event: React.KeyboardEvent) => {
|
|
279
|
+
if (event.key === 'Enter') {
|
|
280
|
+
onclick();
|
|
281
|
+
}
|
|
282
|
+
};
|
|
283
|
+
|
|
284
|
+
const iconClass = commands.iconClass(command, args);
|
|
285
|
+
const icon = commands.icon(command, args);
|
|
286
|
+
|
|
287
|
+
// Return the VDOM element.
|
|
288
|
+
return (
|
|
289
|
+
<div
|
|
290
|
+
className="jp-LauncherCard"
|
|
291
|
+
title={title}
|
|
292
|
+
onClick={onclick}
|
|
293
|
+
onKeyPress={onkeypress}
|
|
294
|
+
tabIndex={0}
|
|
295
|
+
data-category={item.category || trans.__('Other')}
|
|
296
|
+
key={Private.keyProperty.get(item)}
|
|
297
|
+
>
|
|
298
|
+
<div className="jp-LauncherCard-icon">
|
|
299
|
+
{kernel ? (
|
|
300
|
+
item.kernelIconUrl ? (
|
|
301
|
+
<img src={item.kernelIconUrl} className="jp-Launcher-kernelIcon" />
|
|
302
|
+
) : (
|
|
303
|
+
<div className="jp-LauncherCard-noKernelIcon">
|
|
304
|
+
{label[0].toUpperCase()}
|
|
305
|
+
</div>
|
|
306
|
+
)
|
|
307
|
+
) : (
|
|
308
|
+
<LabIcon.resolveReact
|
|
309
|
+
icon={icon}
|
|
310
|
+
iconClass={classes(iconClass, 'jp-Icon-cover')}
|
|
311
|
+
stylesheet="launcherCard"
|
|
312
|
+
/>
|
|
313
|
+
)}
|
|
314
|
+
</div>
|
|
315
|
+
<div className="jp-LauncherCard-label" title={title}>
|
|
316
|
+
<p>{label}</p>
|
|
317
|
+
</div>
|
|
318
|
+
</div>
|
|
319
|
+
);
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
/**
|
|
323
|
+
* The namespace for module private data.
|
|
324
|
+
*/
|
|
325
|
+
namespace Private {
|
|
326
|
+
/**
|
|
327
|
+
* An incrementing counter for keys.
|
|
328
|
+
*/
|
|
329
|
+
let id = 0;
|
|
330
|
+
|
|
331
|
+
/**
|
|
332
|
+
* An attached property for an item's key.
|
|
333
|
+
*/
|
|
334
|
+
export const keyProperty = new AttachedProperty<
|
|
335
|
+
ILauncher.IItemOptions,
|
|
336
|
+
number
|
|
337
|
+
>({
|
|
338
|
+
name: 'key',
|
|
339
|
+
create: () => id++
|
|
340
|
+
});
|
|
341
|
+
|
|
342
|
+
/**
|
|
343
|
+
* Create a fully specified item given item options.
|
|
344
|
+
*/
|
|
345
|
+
export function createItem(
|
|
346
|
+
options: ILauncher.IItemOptions
|
|
347
|
+
): ILauncher.IItemOptions {
|
|
348
|
+
return {
|
|
349
|
+
...options,
|
|
350
|
+
category: options.category || '',
|
|
351
|
+
rank: options.rank !== undefined ? options.rank : Infinity
|
|
352
|
+
};
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
/**
|
|
356
|
+
* A sort comparison function for a launcher item.
|
|
357
|
+
*/
|
|
358
|
+
export function sortCmp(
|
|
359
|
+
a: ILauncher.IItemOptions,
|
|
360
|
+
b: ILauncher.IItemOptions,
|
|
361
|
+
cwd: string,
|
|
362
|
+
commands: CommandRegistry
|
|
363
|
+
): number {
|
|
364
|
+
// First, compare by rank.
|
|
365
|
+
const r1 = a.rank;
|
|
366
|
+
const r2 = b.rank;
|
|
367
|
+
if (r1 !== r2 && r1 !== undefined && r2 !== undefined) {
|
|
368
|
+
return r1 < r2 ? -1 : 1; // Infinity safe
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
// Finally, compare by display name.
|
|
372
|
+
const aLabel = commands.label(a.command, { ...a.args, cwd });
|
|
373
|
+
const bLabel = commands.label(b.command, { ...b.args, cwd });
|
|
374
|
+
return aLabel.localeCompare(bLabel);
|
|
375
|
+
}
|
|
376
|
+
}
|
package/style/base.css
CHANGED
|
@@ -6,13 +6,13 @@
|
|
|
6
6
|
/* Private CSS variables */
|
|
7
7
|
|
|
8
8
|
:root {
|
|
9
|
-
--jp-private-launcher-top-padding:
|
|
10
|
-
--jp-private-launcher-side-padding:
|
|
11
|
-
--jp-private-launcher-card-size:
|
|
12
|
-
--jp-private-launcher-card-label-height:
|
|
13
|
-
--jp-private-launcher-card-icon-height:
|
|
14
|
-
--jp-private-launcher-large-icon-size:
|
|
15
|
-
--jp-private-launcher-small-icon-size:
|
|
9
|
+
--jp-private-launcher-top-padding: 1.231em;
|
|
10
|
+
--jp-private-launcher-side-padding: 2.462em;
|
|
11
|
+
--jp-private-launcher-card-size: 7.692em;
|
|
12
|
+
--jp-private-launcher-card-label-height: 2.462em;
|
|
13
|
+
--jp-private-launcher-card-icon-height: 5.231em;
|
|
14
|
+
--jp-private-launcher-large-icon-size: 4em;
|
|
15
|
+
--jp-private-launcher-small-icon-size: 2.462em;
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
/* Launcher */
|
|
@@ -80,7 +80,7 @@
|
|
|
80
80
|
.jp-Launcher-sectionTitle {
|
|
81
81
|
font-size: var(--jp-ui-font-size2);
|
|
82
82
|
font-weight: normal;
|
|
83
|
-
color: var(--jp-ui-font-
|
|
83
|
+
color: var(--jp-ui-font-color0);
|
|
84
84
|
box-sizing: border-box;
|
|
85
85
|
}
|
|
86
86
|
|
|
@@ -113,6 +113,8 @@
|
|
|
113
113
|
.jp-LauncherCard:focus:not(:active) {
|
|
114
114
|
border: 1px solid var(--jp-brand-color1);
|
|
115
115
|
box-shadow: var(--jp-elevation-z6);
|
|
116
|
+
outline: unset; /* if outline is not unset, then depending on which browser you use, the
|
|
117
|
+
border change is either hidden behind the outline or visually combined with it */
|
|
116
118
|
}
|
|
117
119
|
|
|
118
120
|
.jp-LauncherCard:hover {
|
|
@@ -142,7 +144,7 @@
|
|
|
142
144
|
|
|
143
145
|
.jp-LauncherCard[data-category='Notebook'] .jp-LauncherCard-noKernelIcon {
|
|
144
146
|
/* This color is copied from the notebook icon. */
|
|
145
|
-
color:
|
|
147
|
+
color: var(--jp-jupyter-icon-color);
|
|
146
148
|
}
|
|
147
149
|
|
|
148
150
|
.jp-LauncherCard[data-category='Console'] .jp-LauncherCard-noKernelIcon {
|
|
@@ -159,13 +161,14 @@
|
|
|
159
161
|
}
|
|
160
162
|
|
|
161
163
|
.jp-LauncherCard-label p {
|
|
162
|
-
height:
|
|
164
|
+
height: 2.154em;
|
|
163
165
|
word-break: break-word;
|
|
164
166
|
text-align: center;
|
|
165
167
|
color: var(--jp-ui-font-color1);
|
|
166
|
-
line-height:
|
|
167
|
-
font-size:
|
|
168
|
+
line-height: 1.077em;
|
|
169
|
+
font-size: calc(var(--jp-ui-font-size1) * 0.923);
|
|
168
170
|
overflow: hidden;
|
|
171
|
+
margin: auto;
|
|
169
172
|
}
|
|
170
173
|
|
|
171
174
|
/* kernel icons */
|
|
@@ -175,4 +178,7 @@
|
|
|
175
178
|
height: var(--jp-private-launcher-large-icon-size);
|
|
176
179
|
margin: 0;
|
|
177
180
|
padding: 0;
|
|
181
|
+
|
|
182
|
+
/* Preserve image aspect ratio */
|
|
183
|
+
object-fit: contain;
|
|
178
184
|
}
|