@jupyterlite/application-extension 0.1.0-beta.11 → 0.1.0-beta.13
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.js +24 -14
- package/package.json +13 -13
package/lib/index.js
CHANGED
|
@@ -128,21 +128,33 @@ const downloadPlugin = {
|
|
|
128
128
|
const { currentWidget } = shell;
|
|
129
129
|
return !!(currentWidget && docManager.contextForWidget(currentWidget));
|
|
130
130
|
};
|
|
131
|
-
const downloadContent = (
|
|
131
|
+
const downloadContent = async (contentPath, fileName) => {
|
|
132
|
+
var _a, _b, _c;
|
|
133
|
+
const model = await contents.get(contentPath, { content: true });
|
|
132
134
|
const element = document.createElement('a');
|
|
133
|
-
|
|
134
|
-
|
|
135
|
+
if (model.type === 'notebook' || model.format === 'json') {
|
|
136
|
+
const mime = (_a = model.mimetype) !== null && _a !== void 0 ? _a : 'text/json';
|
|
137
|
+
const content = JSON.stringify(model.content, null, 2);
|
|
138
|
+
element.href = `data:${mime};charset=utf-8,${encodeURIComponent(content)}`;
|
|
139
|
+
}
|
|
140
|
+
else if (model.type === 'file') {
|
|
141
|
+
if (model.format === 'base64') {
|
|
142
|
+
const mime = (_b = model.mimetype) !== null && _b !== void 0 ? _b : 'application/octet-stream';
|
|
143
|
+
element.href = `data:${mime};base64,${model.content}`;
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
const mime = (_c = model.mimetype) !== null && _c !== void 0 ? _c : 'text/plain';
|
|
147
|
+
element.href = `data:${mime};charset=utf-8,${encodeURIComponent(model.content)}`;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
throw new Error(`Content whose type is "${model.type}" cannot be downloaded`);
|
|
152
|
+
}
|
|
153
|
+
element.download = fileName;
|
|
135
154
|
document.body.appendChild(element);
|
|
136
155
|
element.click();
|
|
137
156
|
document.body.removeChild(element);
|
|
138
157
|
};
|
|
139
|
-
const formatContent = async (path) => {
|
|
140
|
-
const model = await contents.get(path, { content: true });
|
|
141
|
-
if (model.type === 'notebook' || model.mimetype.indexOf('json') !== -1) {
|
|
142
|
-
return JSON.stringify(model.content, null, 2);
|
|
143
|
-
}
|
|
144
|
-
return model.content;
|
|
145
|
-
};
|
|
146
158
|
commands.addCommand(CommandIDs.docmanagerDownload, {
|
|
147
159
|
label: trans.__('Download'),
|
|
148
160
|
caption: trans.__('Download the file to your computer'),
|
|
@@ -162,8 +174,7 @@ const downloadPlugin = {
|
|
|
162
174
|
});
|
|
163
175
|
}
|
|
164
176
|
await context.save();
|
|
165
|
-
|
|
166
|
-
downloadContent(content, context.path);
|
|
177
|
+
await downloadContent(context.path, context.path);
|
|
167
178
|
},
|
|
168
179
|
});
|
|
169
180
|
const category = trans.__('File Operations');
|
|
@@ -183,8 +194,7 @@ const downloadPlugin = {
|
|
|
183
194
|
if (item.type === 'directory') {
|
|
184
195
|
return;
|
|
185
196
|
}
|
|
186
|
-
|
|
187
|
-
downloadContent(content, item.name);
|
|
197
|
+
await downloadContent(item.path, item.name);
|
|
188
198
|
});
|
|
189
199
|
},
|
|
190
200
|
icon: downloadIcon.bindprops({ stylesheet: 'menuItem' }),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jupyterlite/application-extension",
|
|
3
|
-
"version": "0.1.0-beta.
|
|
3
|
+
"version": "0.1.0-beta.13",
|
|
4
4
|
"description": "JupyterLite - Application Extension",
|
|
5
5
|
"homepage": "https://github.com/jupyterlite/jupyterlite",
|
|
6
6
|
"bugs": {
|
|
@@ -37,20 +37,20 @@
|
|
|
37
37
|
"watch": "tsc -b --watch"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@jupyterlab/application": "~3.4.
|
|
41
|
-
"@jupyterlab/apputils": "~3.4.
|
|
42
|
-
"@jupyterlab/docmanager": "~3.4.
|
|
43
|
-
"@jupyterlab/docprovider": "~3.4.
|
|
44
|
-
"@jupyterlab/filebrowser": "~3.4.
|
|
45
|
-
"@jupyterlab/help-extension": "~3.4.
|
|
46
|
-
"@jupyterlab/mainmenu": "~3.4.
|
|
47
|
-
"@jupyterlab/services": "~6.4.
|
|
48
|
-
"@jupyterlab/translation": "~3.4.
|
|
49
|
-
"@jupyterlab/ui-components": "~3.4.
|
|
50
|
-
"@jupyterlite/ui-components": "^0.1.0-beta.
|
|
40
|
+
"@jupyterlab/application": "~3.4.7",
|
|
41
|
+
"@jupyterlab/apputils": "~3.4.7",
|
|
42
|
+
"@jupyterlab/docmanager": "~3.4.7",
|
|
43
|
+
"@jupyterlab/docprovider": "~3.4.7",
|
|
44
|
+
"@jupyterlab/filebrowser": "~3.4.7",
|
|
45
|
+
"@jupyterlab/help-extension": "~3.4.7",
|
|
46
|
+
"@jupyterlab/mainmenu": "~3.4.7",
|
|
47
|
+
"@jupyterlab/services": "~6.4.6",
|
|
48
|
+
"@jupyterlab/translation": "~3.4.7",
|
|
49
|
+
"@jupyterlab/ui-components": "~3.4.7",
|
|
50
|
+
"@jupyterlite/ui-components": "^0.1.0-beta.13",
|
|
51
51
|
"@lumino/algorithm": "^1.9.1",
|
|
52
52
|
"@lumino/coreutils": "^1.12.0",
|
|
53
|
-
"@lumino/widgets": "^1.
|
|
53
|
+
"@lumino/widgets": "^1.33.0"
|
|
54
54
|
},
|
|
55
55
|
"devDependencies": {
|
|
56
56
|
"@babel/core": "^7.11.6",
|