Skip to content

Commit ba371e6

Browse files
authored
Switch to LabIcon (#44)
1 parent 3ea2154 commit ba371e6

File tree

11 files changed

+247
-348
lines changed

11 files changed

+247
-348
lines changed

.binder/environment.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ channels:
33
dependencies:
44
- python>=3.6
55
- pytest
6-
- jupyterlab>=2.0.0,<3.0.0
6+
- jupyterlab>=2.2.0,<3.0.0
77
- cookiecutter
88
- nodejs
99
- git

.github/workflows/publish.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
- name: Install dependencies
2323
run: |
2424
python -m pip install --upgrade pip
25-
pip install jupyterlab setuptools twine wheel
25+
pip install "jupyterlab>=2.2.0,<3.0.0" setuptools twine wheel
2626
- name: Publish the Python package
2727
env:
2828
TWINE_USERNAME: __token__

environment.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ channels:
44
dependencies:
55
- python>=3.6
66
- pytest
7-
- jupyterlab>=2.0.0,<3.0.0
7+
- jupyterlab>=2.2.0,<3.0.0
88
- cookiecutter
99
- nodejs
1010
- git

package.json

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@hadim/jupyter-archive",
3-
"version": "2.0.0",
3+
"version": "2.2.0",
44
"description": "A Jupyterlab extension to make, download and extract archive files.",
55
"keywords": [
66
"jupyter",
@@ -26,26 +26,30 @@
2626
"url": "https://github.com/hadim/jupyter-archive.git"
2727
},
2828
"scripts": {
29-
"build": "yarn run build:lib",
29+
"build": "jlpm run build:lib",
3030
"build:labextension": "cd jupyter_archive && rimraf labextension && mkdirp labextension && cd labextension && npm pack ../..",
3131
"build:lib": "tsc",
32-
"build:all": "yarn run build:labextension",
33-
"clean": "yarn run clean:lib",
32+
"build:all": "jlpm run build:labextension",
33+
"clean": "jlpm run clean:lib",
3434
"clean:lib": "rimraf lib && rimraf tsconfig.tsbuildinfo",
3535
"clean:labextension": "rimraf jupyter_archive/labextension",
36-
"clean:all": "yarn run clean:lib && yarn run clean:labextension",
37-
"prepare": "yarn run clean && yarn run build",
36+
"clean:all": "jlpm run clean:lib && jlpm run clean:labextension",
37+
"prepare": "jlpm run clean && jlpm run build",
3838
"watch": "tsc -w"
3939
},
4040
"dependencies": {
41-
"@jupyterlab/application": "^2.0.2",
42-
"@jupyterlab/filebrowser": "^2.0.2"
41+
"@jupyterlab/application": "^2.2.0",
42+
"@jupyterlab/apputils": "^2.2.0",
43+
"@jupyterlab/coreutils": "^4.2.0",
44+
"@jupyterlab/filebrowser": "^2.2.0",
45+
"@jupyterlab/services": "^5.2.0",
46+
"@jupyterlab/settingregistry": "^2.2.0",
47+
"@jupyterlab/ui-components": "^2.2.0"
4348
},
4449
"devDependencies": {
4550
"mkdirp": "^1.0.3",
4651
"rimraf": "~3.0.0",
47-
"typescript": "~3.7.3",
48-
"yarn": "~1.22"
52+
"typescript": "~3.7.3"
4953
},
5054
"sideEffects": [
5155
"style/*.css"

schema/archive.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"jupyter.lab.setting-icon": "jupyter-archive:archive",
23
"title": "Archive",
34
"description": "Archive handler options.",
45
"properties": {

src/icon.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { LabIcon } from "@jupyterlab/ui-components";
2+
3+
// icon svg import statements
4+
import archiveSvg from "../style/icons/archive.svg";
5+
import unarchiveSvg from "../style/icons/unarchive.svg";
6+
7+
export const archiveIcon = new LabIcon({
8+
name: "jupyter-archive:archive",
9+
svgstr: archiveSvg,
10+
});
11+
export const unarchiveIcon = new LabIcon({
12+
name: "jupyter-archive:unarchive",
13+
svgstr: unarchiveSvg,
14+
});

src/index.ts

Lines changed: 45 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
import {
22
JupyterFrontEnd,
3-
JupyterFrontEndPlugin
3+
JupyterFrontEndPlugin,
44
} from "@jupyterlab/application";
55
import { showErrorMessage } from "@jupyterlab/apputils";
66
import { URLExt, PathExt } from "@jupyterlab/coreutils";
7-
import { ISettingRegistry } from '@jupyterlab/settingregistry';
7+
import { ISettingRegistry } from "@jupyterlab/settingregistry";
88
import { IFileBrowserFactory } from "@jupyterlab/filebrowser";
99
import { ServerConnection } from "@jupyterlab/services";
1010
import { each } from "@lumino/algorithm";
1111
import { IDisposable } from "@lumino/disposable";
1212
import { Menu } from "@lumino/widgets";
13+
import { archiveIcon, unarchiveIcon } from "./icon";
1314

1415
const DIRECTORIES_URL = "directories";
1516
const EXTRACT_ARCHVE_URL = "extract-archive";
@@ -46,10 +47,7 @@ function downloadArchiveRequest(
4647
const fullurl = new URL(url);
4748

4849
// Generate a random token.
49-
const rand = () =>
50-
Math.random()
51-
.toString(36)
52-
.substr(2);
50+
const rand = () => Math.random().toString(36).substr(2);
5351
const token = (length: number) =>
5452
(rand() + rand() + rand() + rand()).substr(0, length);
5553

@@ -99,11 +97,13 @@ function extractArchiveRequest(path: string): Promise<void> {
9997
url = fullurl.toString();
10098
const request = { method: "GET" };
10199

102-
return ServerConnection.makeRequest(url, request, settings).then(response => {
103-
if (response.status !== 200) {
104-
throw new ServerConnection.ResponseError(response);
100+
return ServerConnection.makeRequest(url, request, settings).then(
101+
(response) => {
102+
if (response.status !== 200) {
103+
throw new ServerConnection.ResponseError(response);
104+
}
105105
}
106-
});
106+
);
107107
}
108108

109109
/**
@@ -134,7 +134,7 @@ const extension: JupyterFrontEndPlugin<void> = {
134134
".tar.bz",
135135
".tar.bz2",
136136
".txz",
137-
".tar.xz"
137+
".tar.xz",
138138
];
139139
let archiveFormat: ArchiveFormat; // Default value read from settings
140140
let followSymlinks: string; // Default value read from settings
@@ -151,24 +151,24 @@ const extension: JupyterFrontEndPlugin<void> = {
151151

152152
// Create submenus
153153
const archiveFolder = new Menu({
154-
commands
154+
commands,
155155
});
156156
archiveFolder.title.label = "Download As";
157-
archiveFolder.title.iconClass = "jp-MaterialIcon jp-DownloadIcon";
157+
archiveFolder.title.icon = archiveIcon;
158158
const archiveCurrentFolder = new Menu({
159-
commands
159+
commands,
160160
});
161161
archiveCurrentFolder.title.label = "Download Current Folder As";
162-
archiveCurrentFolder.title.iconClass = "jp-MaterialIcon jp-DownloadIcon";
162+
archiveCurrentFolder.title.icon = archiveIcon;
163163

164-
["zip", "tar.bz2", "tar.gz", "tar.xz"].forEach(format => {
164+
["zip", "tar.bz2", "tar.gz", "tar.xz"].forEach((format) => {
165165
archiveFolder.addItem({
166166
command: CommandIDs.downloadArchive,
167-
args: { format }
167+
args: { format },
168168
});
169169
archiveCurrentFolder.addItem({
170170
command: CommandIDs.downloadArchiveCurrentFolder,
171-
args: { format }
171+
args: { format },
172172
});
173173
});
174174

@@ -193,26 +193,26 @@ const extension: JupyterFrontEndPlugin<void> = {
193193
selector: selectorOnlyDir,
194194
rank: 10,
195195
type: "submenu",
196-
submenu: archiveFolder
196+
submenu: archiveFolder,
197197
});
198198

199199
archiveCurrentFolderItem = app.contextMenu.addItem({
200200
selector: selectorContent,
201201
rank: 3,
202202
type: "submenu",
203-
submenu: archiveCurrentFolder
203+
submenu: archiveCurrentFolder,
204204
});
205205
} else {
206206
archiveFolderItem = app.contextMenu.addItem({
207207
command: CommandIDs.downloadArchive,
208208
selector: selectorOnlyDir,
209-
rank: 10
209+
rank: 10,
210210
});
211211

212212
archiveCurrentFolderItem = app.contextMenu.addItem({
213213
command: CommandIDs.downloadArchiveCurrentFolder,
214214
selector: selectorContent,
215-
rank: 3
215+
rank: 3,
216216
});
217217
}
218218
}
@@ -224,8 +224,8 @@ const extension: JupyterFrontEndPlugin<void> = {
224224
// Load the settings
225225
settingRegistry
226226
.load("@hadim/jupyter-archive:archive")
227-
.then(settings => {
228-
settings.changed.connect(settings => {
227+
.then((settings) => {
228+
settings.changed.connect((settings) => {
229229
const newFormat = settings.get("format").composite as ArchiveFormat;
230230
updateFormat(newFormat, archiveFormat);
231231
followSymlinks = settings.get("followSymlinks").composite as string;
@@ -237,7 +237,7 @@ const extension: JupyterFrontEndPlugin<void> = {
237237
followSymlinks = settings.get("followSymlinks").composite as string;
238238
downloadHidden = settings.get("downloadHidden").composite as string;
239239
})
240-
.catch(reason => {
240+
.catch((reason) => {
241241
console.error(reason);
242242
showErrorMessage(
243243
"Fail to read settings for '@hadim/jupyter-archive:archive'",
@@ -247,44 +247,43 @@ const extension: JupyterFrontEndPlugin<void> = {
247247

248248
// Add the 'downloadArchive' command to the file's menu.
249249
commands.addCommand(CommandIDs.downloadArchive, {
250-
execute: args => {
250+
execute: (args) => {
251251
const widget = tracker.currentWidget;
252252
if (widget) {
253-
each(widget.selectedItems(), item => {
253+
each(widget.selectedItems(), (item) => {
254254
if (item.type == "directory") {
255255
const format = args["format"] as ArchiveFormat;
256256
downloadArchiveRequest(
257257
item.path,
258258
allowedArchiveExtensions.indexOf("." + format) >= 0
259259
? format
260260
: archiveFormat,
261-
followSymlinks,
262-
downloadHidden
261+
followSymlinks,
262+
downloadHidden
263263
);
264264
}
265265
});
266266
}
267267
},
268-
iconClass: args =>
269-
"format" in args ? "" : "jp-MaterialIcon jp-DownloadIcon",
270-
label: args => {
268+
icon: (args) => ("format" in args ? "" : archiveIcon),
269+
label: (args) => {
271270
const format = (args["format"] as ArchiveFormat) || "";
272271
const label = format.replace(".", " ").toLocaleUpperCase();
273272
return label ? `${label} Archive` : "Download as an Archive";
274-
}
273+
},
275274
});
276275

277276
// Add the 'extractArchive' command to the file's menu.
278277
commands.addCommand(CommandIDs.extractArchive, {
279278
execute: () => {
280279
const widget = tracker.currentWidget;
281280
if (widget) {
282-
each(widget.selectedItems(), item => {
281+
each(widget.selectedItems(), (item) => {
283282
extractArchiveRequest(item.path);
284283
});
285284
}
286285
},
287-
iconClass: "jp-MaterialIcon jp-DownCaretIcon",
286+
icon: unarchiveIcon,
288287
isVisible: () => {
289288
const widget = tracker.currentWidget;
290289
let visible = false;
@@ -294,26 +293,27 @@ const extension: JupyterFrontEndPlugin<void> = {
294293
const splitName = basename.split(".");
295294
let lastTwoParts = "";
296295
if (splitName.length >= 2) {
297-
lastTwoParts = "." + splitName.splice(splitName.length - 2, 2).join(".");
296+
lastTwoParts =
297+
"." + splitName.splice(splitName.length - 2, 2).join(".");
298298
}
299299
visible =
300-
allowedArchiveExtensions.indexOf(PathExt.extname(basename)) >=
301-
0 || allowedArchiveExtensions.indexOf(lastTwoParts) >= 0;
300+
allowedArchiveExtensions.indexOf(PathExt.extname(basename)) >= 0 ||
301+
allowedArchiveExtensions.indexOf(lastTwoParts) >= 0;
302302
}
303303
return visible;
304304
},
305-
label: "Extract Archive"
305+
label: "Extract Archive",
306306
});
307307

308308
app.contextMenu.addItem({
309309
command: CommandIDs.extractArchive,
310310
selector: selectorNotDir,
311-
rank: 10
311+
rank: 10,
312312
});
313313

314314
// Add the 'downloadArchiveCurrentFolder' command to file browser content.
315315
commands.addCommand(CommandIDs.downloadArchiveCurrentFolder, {
316-
execute: args => {
316+
execute: (args) => {
317317
const widget = tracker.currentWidget;
318318
if (widget) {
319319
const format = args["format"] as ArchiveFormat;
@@ -327,17 +327,16 @@ const extension: JupyterFrontEndPlugin<void> = {
327327
);
328328
}
329329
},
330-
iconClass: args =>
331-
"format" in args ? "" : "jp-MaterialIcon jp-DownloadIcon",
332-
label: args => {
330+
icon: (args) => ("format" in args ? "" : archiveIcon),
331+
label: (args) => {
333332
const format = (args["format"] as ArchiveFormat) || "";
334333
const label = format.replace(".", " ").toLocaleUpperCase();
335334
return label
336335
? `${label} Archive`
337336
: "Download Current Folder as an Archive";
338-
}
337+
},
339338
});
340-
}
339+
},
341340
};
342341

343342
export default extension;

src/svg.d.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright (c) Jupyter Development Team.
2+
// Distributed under the terms of the Modified BSD License.
3+
4+
// including this file in a package allows for the use of import statements
5+
// with svg files. Example: `import xSvg from 'path/xSvg.svg'`
6+
7+
// for use with raw-loader in Webpack.
8+
// The svg will be imported as a raw string
9+
10+
declare module "*.svg" {
11+
const value: string;
12+
export default value;
13+
}

style/icons/archive.svg

Lines changed: 1 addition & 0 deletions
Loading

style/icons/unarchive.svg

Lines changed: 1 addition & 0 deletions
Loading

0 commit comments

Comments
 (0)