@difizen/libro-jupyter 0.1.17 → 0.1.18
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/es/file/file-command.d.ts +6 -0
- package/es/file/file-command.d.ts.map +1 -1
- package/es/file/file-command.js +45 -2
- package/es/file/file-view/index.d.ts +12 -0
- package/es/file/file-view/index.d.ts.map +1 -1
- package/es/file/file-view/index.js +137 -4
- package/es/libro-jupyter-model.d.ts.map +1 -1
- package/es/libro-jupyter-model.js +18 -2
- package/es/libro-jupyter-protocol.d.ts +1 -0
- package/es/libro-jupyter-protocol.d.ts.map +1 -1
- package/es/libro-jupyter-protocol.js +2 -1
- package/package.json +16 -16
- package/src/file/file-command.tsx +46 -6
- package/src/file/file-view/index.tsx +90 -0
- package/src/libro-jupyter-model.ts +17 -0
- package/src/libro-jupyter-protocol.ts +2 -0
|
@@ -54,6 +54,10 @@ export declare const FileCommands: {
|
|
|
54
54
|
id: string;
|
|
55
55
|
label: string;
|
|
56
56
|
};
|
|
57
|
+
UPLOAD: {
|
|
58
|
+
id: string;
|
|
59
|
+
label: string;
|
|
60
|
+
};
|
|
57
61
|
};
|
|
58
62
|
export declare const FileTreeContextMenuPath: MenuPath;
|
|
59
63
|
export declare const FileTreeContextMenuGroups: Record<string, MenuPath>;
|
|
@@ -67,6 +71,8 @@ export declare class FileCommandContribution implements CommandContribution, Men
|
|
|
67
71
|
fileView: FileView;
|
|
68
72
|
lastAction: 'COPY' | 'CUT';
|
|
69
73
|
lastActionNode: FileStatNode;
|
|
74
|
+
allowDownload: boolean;
|
|
75
|
+
allowUpload: boolean;
|
|
70
76
|
constructor(viewManager: ViewManager);
|
|
71
77
|
registerMenus(menu: MenuRegistry): void;
|
|
72
78
|
registerCommands(command: CommandRegistry): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"file-command.d.ts","sourceRoot":"","sources":["../../src/file/file-command.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,KAAK,EACV,eAAe,EACf,QAAQ,EACR,YAAY,EACZ,eAAe,EAChB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,WAAW,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AACtE,OAAO,EACL,mBAAmB,EACnB,YAAY,EAEZ,gBAAgB,EAChB,YAAY,EACZ,aAAa,EAEb,mBAAmB,EAEpB,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"file-command.d.ts","sourceRoot":"","sources":["../../src/file/file-command.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,KAAK,EACV,eAAe,EACf,QAAQ,EACR,YAAY,EACZ,eAAe,EAChB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,WAAW,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AACtE,OAAO,EACL,mBAAmB,EACnB,YAAY,EAEZ,gBAAgB,EAChB,YAAY,EACZ,aAAa,EAEb,mBAAmB,EAEpB,MAAM,mBAAmB,CAAC;AAM3B,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AACvD,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAEhD,OAAO,cAAc,CAAC;AAEtB,eAAO,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAqDxB,CAAC;AACF,eAAO,MAAM,uBAAuB,EAAE,QAAqC,CAAC;AAC5E,eAAO,MAAM,yBAAyB,EAAE,MAAM,CAAC,MAAM,EAAE,QAAQ,CAK9D,CAAC;AAEF,qBAGa,uBACX,YAAW,mBAAmB,EAAE,gBAAgB,EAAE,mBAAmB;IAErE,SAAS,CAAC,WAAW,EAAE,WAAW,CAAC;IACP,WAAW,EAAE,kBAAkB,CAAC;IACtC,YAAY,EAAE,YAAY,CAAC;IAC1B,SAAS,CAAC,WAAW,EAAE,aAAa,CAAC;IAC9B,oBAAoB,EAAE,oBAAoB,CAAC;IAChD,eAAe,EAAE,eAAe,CAAC;IAE1D,QAAQ,EAAE,QAAQ,CAAC;IACnB,UAAU,EAAE,MAAM,GAAG,KAAK,CAAC;IAC3B,cAAc,EAAE,YAAY,CAAC;IAC7B,aAAa,UAAS;IACtB,WAAW,UAAS;gBAEa,WAAW,EAAE,WAAW;IAazD,aAAa,CAAC,IAAI,EAAE,YAAY;IAmEhC,gBAAgB,CAAC,OAAO,EAAE,eAAe,GAAG,IAAI;IAkOhD,oBAAoB,CAAC,eAAe,EAAE,eAAe,GAAG,IAAI;CAQ7D"}
|
package/es/file/file-command.js
CHANGED
|
@@ -20,7 +20,6 @@ import { ContentsManager } from '@difizen/libro-kernel';
|
|
|
20
20
|
import { ViewManager, ConfigurationService } from '@difizen/mana-app';
|
|
21
21
|
import { CommandContribution, FileStatNode, inject, MenuContribution, ModalService, OpenerService, singleton, ToolbarContribution, URI } from '@difizen/mana-app';
|
|
22
22
|
import { message, Modal } from 'antd';
|
|
23
|
-
import { LibroConfigAllowDownload } from "../config/index.js";
|
|
24
23
|
import { FileCreateModal } from "./file-create-modal.js";
|
|
25
24
|
import { FileDirCreateModal } from "./file-createdir-modal.js";
|
|
26
25
|
import { FileRenameModal } from "./file-rename-modal.js";
|
|
@@ -77,6 +76,10 @@ export var FileCommands = {
|
|
|
77
76
|
DOWNLOAD: {
|
|
78
77
|
id: 'fileTree.command.download',
|
|
79
78
|
label: '下载'
|
|
79
|
+
},
|
|
80
|
+
UPLOAD: {
|
|
81
|
+
id: 'fileTree.command.upload',
|
|
82
|
+
label: '上传'
|
|
80
83
|
}
|
|
81
84
|
};
|
|
82
85
|
export var FileTreeContextMenuPath = ['file-tree-context-menu'];
|
|
@@ -101,6 +104,8 @@ export var FileCommandContribution = (_dec = singleton({
|
|
|
101
104
|
this.fileView = void 0;
|
|
102
105
|
this.lastAction = void 0;
|
|
103
106
|
this.lastActionNode = void 0;
|
|
107
|
+
this.allowDownload = false;
|
|
108
|
+
this.allowUpload = false;
|
|
104
109
|
this.viewManager = viewManager;
|
|
105
110
|
this.viewManager.getOrCreateView(FileView).then(function (view) {
|
|
106
111
|
_this.fileView = view;
|
|
@@ -171,6 +176,11 @@ export var FileCommandContribution = (_dec = singleton({
|
|
|
171
176
|
command: FileCommands.DOWNLOAD.id,
|
|
172
177
|
order: 'h'
|
|
173
178
|
});
|
|
179
|
+
menu.registerMenuAction(FileTreeContextMenuGroups['extra'], {
|
|
180
|
+
id: FileCommands.UPLOAD.id,
|
|
181
|
+
command: FileCommands.UPLOAD.id,
|
|
182
|
+
order: 'i'
|
|
183
|
+
});
|
|
174
184
|
}
|
|
175
185
|
}, {
|
|
176
186
|
key: "registerCommands",
|
|
@@ -480,6 +490,11 @@ export var FileCommandContribution = (_dec = singleton({
|
|
|
480
490
|
}
|
|
481
491
|
var path = data.uri.path.toString();
|
|
482
492
|
_this2.contentsManager.getDownloadUrl(path).then(function (url) {
|
|
493
|
+
var urlObj = new URL(url);
|
|
494
|
+
if (urlObj.origin !== location.origin) {
|
|
495
|
+
// not same origin
|
|
496
|
+
return;
|
|
497
|
+
}
|
|
483
498
|
var element = document.createElement('a');
|
|
484
499
|
element.href = url;
|
|
485
500
|
element.download = '';
|
|
@@ -491,7 +506,35 @@ export var FileCommandContribution = (_dec = singleton({
|
|
|
491
506
|
}).catch(console.error);
|
|
492
507
|
},
|
|
493
508
|
isVisible: function isVisible(data) {
|
|
494
|
-
return
|
|
509
|
+
return _this2.allowDownload && FileStatNode.is(data) && data.fileStat.isFile;
|
|
510
|
+
}
|
|
511
|
+
});
|
|
512
|
+
command.registerCommand(FileCommands.UPLOAD, {
|
|
513
|
+
execute: function execute(data, view) {
|
|
514
|
+
if (!_this2.allowUpload) {
|
|
515
|
+
return;
|
|
516
|
+
}
|
|
517
|
+
if (!view || !(view instanceof FileView)) {
|
|
518
|
+
return;
|
|
519
|
+
}
|
|
520
|
+
if (!data || data instanceof FileView) {
|
|
521
|
+
return view.uploadSubmit();
|
|
522
|
+
}
|
|
523
|
+
if (FileStatNode.is(data) && data.fileStat.isDirectory) {
|
|
524
|
+
return view.uploadSubmit(data.uri.path.toString());
|
|
525
|
+
}
|
|
526
|
+
},
|
|
527
|
+
isVisible: function isVisible(data, view) {
|
|
528
|
+
if (!_this2.allowUpload) {
|
|
529
|
+
return false;
|
|
530
|
+
}
|
|
531
|
+
if (!view || !(view instanceof FileView)) {
|
|
532
|
+
return false;
|
|
533
|
+
}
|
|
534
|
+
if (!data || data instanceof FileView) {
|
|
535
|
+
return true;
|
|
536
|
+
}
|
|
537
|
+
return FileStatNode.is(data) && data.fileStat.isDirectory;
|
|
495
538
|
}
|
|
496
539
|
});
|
|
497
540
|
}
|
|
@@ -1,13 +1,25 @@
|
|
|
1
|
+
import { ContentsManager } from '@difizen/libro-kernel';
|
|
2
|
+
import type { IContentsModel } from '@difizen/libro-kernel';
|
|
1
3
|
import type { TreeNode } from '@difizen/mana-app';
|
|
2
4
|
import { FileTreeModel, FileTreeView, LabelProvider, TreeDecoratorService, TreeProps, TreeViewDecorator, CommandRegistry, OpenerService, SelectionService } from '@difizen/mana-app';
|
|
3
5
|
import React from 'react';
|
|
4
6
|
import './index.less';
|
|
5
7
|
export declare class FileView extends FileTreeView {
|
|
6
8
|
protected openService: OpenerService;
|
|
9
|
+
protected contentsManager: ContentsManager;
|
|
7
10
|
protected command: CommandRegistry;
|
|
11
|
+
uploadInput?: HTMLInputElement;
|
|
8
12
|
id: string;
|
|
9
13
|
className: string;
|
|
10
14
|
constructor(props: TreeProps, model: FileTreeModel, treeViewDecorator: TreeViewDecorator, selectionService: SelectionService, labelProvider: LabelProvider, decoratorService: TreeDecoratorService);
|
|
15
|
+
onViewMount(): void;
|
|
16
|
+
uploadSubmit: (basePath?: string) => void;
|
|
17
|
+
/**
|
|
18
|
+
* Perform the actual upload.
|
|
19
|
+
*/
|
|
20
|
+
protected doUpload(file: File, basePath: string): Promise<IContentsModel>;
|
|
21
|
+
onInputChanged: () => void;
|
|
22
|
+
onInputClicked: () => void;
|
|
11
23
|
openNode: (treeNode: TreeNode) => Promise<void>;
|
|
12
24
|
handleClickEvent(node: TreeNode | undefined, event: React.MouseEvent<HTMLElement>): void;
|
|
13
25
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/file/file-view/index.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAmB,MAAM,mBAAmB,CAAC;AAEnE,OAAO,EAGL,aAAa,EACb,YAAY,EAEZ,aAAa,EACb,oBAAoB,EACpB,SAAS,EACT,iBAAiB,EAEjB,eAAe,EAEf,aAAa,EACb,gBAAgB,EAIjB,MAAM,mBAAmB,CAAC;AAE3B,OAAO,KAAK,MAAM,OAAO,CAAC;AAI1B,OAAO,cAAc,CAAC;AAUtB,qBAEa,QAAS,SAAQ,YAAY;IACjB,SAAS,CAAC,WAAW,EAAE,aAAa,CAAC;IACnC,SAAS,CAAC,OAAO,EAAE,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/file/file-view/index.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,KAAK,EAAE,QAAQ,EAAmB,MAAM,mBAAmB,CAAC;AAEnE,OAAO,EAGL,aAAa,EACb,YAAY,EAEZ,aAAa,EACb,oBAAoB,EACpB,SAAS,EACT,iBAAiB,EAEjB,eAAe,EAEf,aAAa,EACb,gBAAgB,EAIjB,MAAM,mBAAmB,CAAC;AAE3B,OAAO,KAAK,MAAM,OAAO,CAAC;AAI1B,OAAO,cAAc,CAAC;AAUtB,qBAEa,QAAS,SAAQ,YAAY;IACjB,SAAS,CAAC,WAAW,EAAE,aAAa,CAAC;IACnC,SAAS,CAAC,eAAe,EAAE,eAAe,CAAC;IAC3C,SAAS,CAAC,OAAO,EAAE,eAAe,CAAC;IAC5D,WAAW,CAAC,EAAE,gBAAgB,CAAC;IACtB,EAAE,SAAuB;IACzB,SAAS,SAA6B;gBAG1B,KAAK,EAAE,SAAS,EACZ,KAAK,EAAE,aAAa,EAChB,iBAAiB,EAAE,iBAAiB,EACrC,gBAAgB,EAAE,gBAAgB,EACrC,aAAa,EAAE,aAAa,EACrB,gBAAgB,EAAE,oBAAoB;IAe7D,WAAW,IAAI,IAAI;IAgB5B,YAAY,cAAe,MAAM,UAK/B;IACF;;OAEG;cACa,QAAQ,CAAC,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC;IAgC/E,cAAc,aAqBZ;IAEF,cAAc,aAIZ;IAEF,QAAQ,aAAoB,QAAQ,mBAmClC;IAEO,gBAAgB,CACvB,IAAI,EAAE,QAAQ,GAAG,SAAS,EAC1B,KAAK,EAAE,KAAK,CAAC,UAAU,CAAC,WAAW,CAAC,GACnC,IAAI;CAeR"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
-
var _dec, _dec2, _dec3, _dec4, _class, _class2, _descriptor, _descriptor2;
|
|
2
|
+
var _dec, _dec2, _dec3, _dec4, _dec5, _class, _class2, _descriptor, _descriptor2, _descriptor3;
|
|
3
3
|
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
|
|
4
4
|
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
5
5
|
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
@@ -21,6 +21,7 @@ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.g
|
|
|
21
21
|
function _applyDecoratedDescriptor(target, property, decorators, descriptor, context) { var desc = {}; Object.keys(descriptor).forEach(function (key) { desc[key] = descriptor[key]; }); desc.enumerable = !!desc.enumerable; desc.configurable = !!desc.configurable; if ('value' in desc || desc.initializer) { desc.writable = true; } desc = decorators.slice().reverse().reduce(function (desc, decorator) { return decorator(target, property, desc) || desc; }, desc); if (context && desc.initializer !== void 0) { desc.value = desc.initializer ? desc.initializer.call(context) : void 0; desc.initializer = undefined; } if (desc.initializer === void 0) { Object.defineProperty(target, property, desc); desc = null; } return desc; }
|
|
22
22
|
function _initializerWarningHelper(descriptor, context) { throw new Error('Decorating class property failed. Please ensure that ' + 'transform-class-properties is enabled and runs after the decorators transform.'); }
|
|
23
23
|
import { ExclamationCircleFilled, FolderFilled } from '@ant-design/icons';
|
|
24
|
+
import { ContentsManager } from '@difizen/libro-kernel';
|
|
24
25
|
import { FileTreeViewFactory } from '@difizen/mana-app';
|
|
25
26
|
import { FileStatNode, FileTree, FileTreeModel, FileTreeView, isOSX, LabelProvider, TreeDecoratorService, TreeProps, TreeViewDecorator, TreeViewModule, CommandRegistry, ManaModule, OpenerService, SelectionService, view, inject, singleton } from '@difizen/mana-app';
|
|
26
27
|
import { Modal } from 'antd';
|
|
@@ -30,7 +31,7 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
30
31
|
var FileTreeModule = ManaModule.create().register(FileTree, FileTreeModel).dependOn(TreeViewModule);
|
|
31
32
|
var confirm = Modal.confirm;
|
|
32
33
|
var noVerifyFileType = ['.ipynb', '.py'];
|
|
33
|
-
export var FileView = (_dec = singleton(), _dec2 = view(FileTreeViewFactory, FileTreeModule), _dec3 = inject(OpenerService), _dec4 = inject(CommandRegistry), _dec(_class = _dec2(_class = (_class2 = /*#__PURE__*/function (_FileTreeView) {
|
|
34
|
+
export var FileView = (_dec = singleton(), _dec2 = view(FileTreeViewFactory, FileTreeModule), _dec3 = inject(OpenerService), _dec4 = inject(ContentsManager), _dec5 = inject(CommandRegistry), _dec(_class = _dec2(_class = (_class2 = /*#__PURE__*/function (_FileTreeView) {
|
|
34
35
|
_inherits(FileView, _FileTreeView);
|
|
35
36
|
var _super = _createSuper(FileView);
|
|
36
37
|
function FileView(props, model, treeViewDecorator, selectionService, labelProvider, decoratorService) {
|
|
@@ -38,9 +39,45 @@ export var FileView = (_dec = singleton(), _dec2 = view(FileTreeViewFactory, Fil
|
|
|
38
39
|
_classCallCheck(this, FileView);
|
|
39
40
|
_this = _super.call(this, props, model, treeViewDecorator, selectionService, labelProvider, decoratorService);
|
|
40
41
|
_initializerDefineProperty(_this, "openService", _descriptor, _assertThisInitialized(_this));
|
|
41
|
-
_initializerDefineProperty(_this, "
|
|
42
|
+
_initializerDefineProperty(_this, "contentsManager", _descriptor2, _assertThisInitialized(_this));
|
|
43
|
+
_initializerDefineProperty(_this, "command", _descriptor3, _assertThisInitialized(_this));
|
|
44
|
+
_this.uploadInput = void 0;
|
|
42
45
|
_this.id = FileTreeViewFactory;
|
|
43
46
|
_this.className = 'libro-jupyter-file-tree';
|
|
47
|
+
_this.uploadSubmit = function (basePath) {
|
|
48
|
+
if (_this.uploadInput) {
|
|
49
|
+
_this.uploadInput.setAttribute('data-path', basePath || '');
|
|
50
|
+
_this.uploadInput.click();
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
_this.onInputChanged = function () {
|
|
54
|
+
if (!_this.uploadInput) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
var path = _this.uploadInput.getAttribute('data-path') || '';
|
|
58
|
+
if (!path) {
|
|
59
|
+
var _this$model$location;
|
|
60
|
+
path = ((_this$model$location = _this.model.location) === null || _this$model$location === void 0 ? void 0 : _this$model$location.path.toString()) || '';
|
|
61
|
+
}
|
|
62
|
+
if (!path) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
var files = Array.prototype.slice.call(_this.uploadInput.files);
|
|
66
|
+
var pending = files.map(function (file) {
|
|
67
|
+
return _this.doUpload(file, path);
|
|
68
|
+
});
|
|
69
|
+
Promise.all(pending).then(function () {
|
|
70
|
+
_this.model.refresh();
|
|
71
|
+
return;
|
|
72
|
+
}).catch(function (error) {
|
|
73
|
+
console.error('Upload Error:', error);
|
|
74
|
+
});
|
|
75
|
+
};
|
|
76
|
+
_this.onInputClicked = function () {
|
|
77
|
+
if (_this.uploadInput) {
|
|
78
|
+
_this.uploadInput.value = '';
|
|
79
|
+
}
|
|
80
|
+
};
|
|
44
81
|
_this.openNode = /*#__PURE__*/function () {
|
|
45
82
|
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(treeNode) {
|
|
46
83
|
var opener;
|
|
@@ -125,6 +162,97 @@ export var FileView = (_dec = singleton(), _dec2 = view(FileTreeViewFactory, Fil
|
|
|
125
162
|
FileView = inject(FileTreeModel)(FileView, undefined, 1) || FileView;
|
|
126
163
|
FileView = inject(TreeProps)(FileView, undefined, 0) || FileView;
|
|
127
164
|
_createClass(FileView, [{
|
|
165
|
+
key: "onViewMount",
|
|
166
|
+
value: function onViewMount() {
|
|
167
|
+
var _get2, _this$container;
|
|
168
|
+
(_get2 = _get(_getPrototypeOf(FileView.prototype), "onViewMount", this)) === null || _get2 === void 0 || _get2.call(this);
|
|
169
|
+
if (!((_this$container = this.container) !== null && _this$container !== void 0 && _this$container.current)) {
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
var container = this.container.current;
|
|
173
|
+
var input = document.createElement('input');
|
|
174
|
+
input.type = 'file';
|
|
175
|
+
input.multiple = true;
|
|
176
|
+
input.onclick = this.onInputClicked;
|
|
177
|
+
input.onchange = this.onInputChanged;
|
|
178
|
+
input.style.display = 'none';
|
|
179
|
+
container.appendChild(input);
|
|
180
|
+
this.uploadInput = input;
|
|
181
|
+
}
|
|
182
|
+
}, {
|
|
183
|
+
key: "doUpload",
|
|
184
|
+
value: (
|
|
185
|
+
/**
|
|
186
|
+
* Perform the actual upload.
|
|
187
|
+
*/
|
|
188
|
+
function () {
|
|
189
|
+
var _doUpload = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(file, basePath) {
|
|
190
|
+
var _this2 = this;
|
|
191
|
+
var path, name, type, format, uploadInner;
|
|
192
|
+
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
193
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
194
|
+
case 0:
|
|
195
|
+
// Gather the file model parameters.
|
|
196
|
+
path = basePath;
|
|
197
|
+
path = path ? path + '/' + file.name : file.name;
|
|
198
|
+
name = file.name;
|
|
199
|
+
type = 'file';
|
|
200
|
+
format = 'base64';
|
|
201
|
+
uploadInner = /*#__PURE__*/function () {
|
|
202
|
+
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(blob, chunk) {
|
|
203
|
+
var reader, content, model;
|
|
204
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
205
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
206
|
+
case 0:
|
|
207
|
+
reader = new FileReader();
|
|
208
|
+
reader.readAsDataURL(blob);
|
|
209
|
+
_context3.next = 4;
|
|
210
|
+
return new Promise(function (resolve, reject) {
|
|
211
|
+
reader.onload = resolve;
|
|
212
|
+
reader.onerror = function (event) {
|
|
213
|
+
return reject("Failed to upload \"".concat(file.name, "\":") + event);
|
|
214
|
+
};
|
|
215
|
+
});
|
|
216
|
+
case 4:
|
|
217
|
+
// remove header https://stackoverflow.com/a/24289420/907060
|
|
218
|
+
content = reader.result.split(',')[1];
|
|
219
|
+
model = {
|
|
220
|
+
type: type,
|
|
221
|
+
format: format,
|
|
222
|
+
name: name,
|
|
223
|
+
chunk: chunk,
|
|
224
|
+
content: content
|
|
225
|
+
};
|
|
226
|
+
_context3.next = 8;
|
|
227
|
+
return _this2.contentsManager.save(path, model);
|
|
228
|
+
case 8:
|
|
229
|
+
return _context3.abrupt("return", _context3.sent);
|
|
230
|
+
case 9:
|
|
231
|
+
case "end":
|
|
232
|
+
return _context3.stop();
|
|
233
|
+
}
|
|
234
|
+
}, _callee3);
|
|
235
|
+
}));
|
|
236
|
+
return function uploadInner(_x4, _x5) {
|
|
237
|
+
return _ref2.apply(this, arguments);
|
|
238
|
+
};
|
|
239
|
+
}();
|
|
240
|
+
_context4.next = 8;
|
|
241
|
+
return uploadInner(file);
|
|
242
|
+
case 8:
|
|
243
|
+
return _context4.abrupt("return", _context4.sent);
|
|
244
|
+
case 9:
|
|
245
|
+
case "end":
|
|
246
|
+
return _context4.stop();
|
|
247
|
+
}
|
|
248
|
+
}, _callee4);
|
|
249
|
+
}));
|
|
250
|
+
function doUpload(_x2, _x3) {
|
|
251
|
+
return _doUpload.apply(this, arguments);
|
|
252
|
+
}
|
|
253
|
+
return doUpload;
|
|
254
|
+
}())
|
|
255
|
+
}, {
|
|
128
256
|
key: "handleClickEvent",
|
|
129
257
|
value: function handleClickEvent(node, event) {
|
|
130
258
|
var modifierKeyCombined = isOSX ? event.shiftKey || event.metaKey : event.shiftKey || event.ctrlKey;
|
|
@@ -142,7 +270,12 @@ export var FileView = (_dec = singleton(), _dec2 = view(FileTreeViewFactory, Fil
|
|
|
142
270
|
enumerable: true,
|
|
143
271
|
writable: true,
|
|
144
272
|
initializer: null
|
|
145
|
-
}), _descriptor2 = _applyDecoratedDescriptor(_class2.prototype, "
|
|
273
|
+
}), _descriptor2 = _applyDecoratedDescriptor(_class2.prototype, "contentsManager", [_dec4], {
|
|
274
|
+
configurable: true,
|
|
275
|
+
enumerable: true,
|
|
276
|
+
writable: true,
|
|
277
|
+
initializer: null
|
|
278
|
+
}), _descriptor3 = _applyDecoratedDescriptor(_class2.prototype, "command", [_dec5], {
|
|
146
279
|
configurable: true,
|
|
147
280
|
enumerable: true,
|
|
148
281
|
writable: true,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"libro-jupyter-model.d.ts","sourceRoot":"","sources":["../src/libro-jupyter-model.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,wBAAwB,EAAE,MAAM,qBAAqB,CAAC;AAC3E,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAC9D,OAAO,EACL,eAAe,EACf,uBAAuB,
|
|
1
|
+
{"version":3,"file":"libro-jupyter-model.d.ts","sourceRoot":"","sources":["../src/libro-jupyter-model.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,wBAAwB,EAAE,MAAM,qBAAqB,CAAC;AAC3E,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAC9D,OAAO,EACL,eAAe,EACf,uBAAuB,EAEvB,4BAA4B,EAC5B,gBAAgB,EAChB,aAAa,EACd,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC/D,OAAO,KAAK,EAAE,wBAAwB,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACtF,OAAO,EAAa,YAAY,EAAQ,MAAM,mBAAmB,CAAC;AAClE,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAI7C,OAAO,EAGL,gBAAgB,EACjB,MAAM,6BAA6B,CAAC;AAIrC,KAAK,MAAM,GAAG,cAAc,CAAC;AAC7B,qBACa,iBAAkB,SAAQ,UAAW,YAAW,uBAAuB;IAClF,MAAM,CAAC,EAAE,QAAS,OAAO,GAAG,EAAE,GAAG,CAAC,GAAG,SAAS,8BAS5C;IAEF,SAAS,CAAC,gBAAgB,EAAE,gBAAgB,CAAC;IAE7C,IAAI,WAAW,qBAEd;IAGD,mBAAmB,EAAE,MAAM,CAAC;IAE5B,SAAS,CAAC,YAAY,EAAE,MAAM,CAAC;IAE/B,SAAS,CAAC,YAAY,EAAE,MAAM,CAAC;IAE/B,gBAAgB,CAAC,EAAE,iBAAiB,CAAC;IAGrC,UAAU,UAAQ;IAElB,SAAS,CAAC,uBAAuB,EAAE,4BAA4B,CAAC;IAChE,SAAS,CAAC,aAAa,EAAE,aAAa,CAAC;IACvC,SAAS,CAAC,gBAAgB,EAAE,gBAAgB,CAAC;IAC7C,SAAS,CAAC,QAAQ,CAAC,eAAe,EAAE,eAAe,CAAC;IACpD,SAAS,CAAC,QAAQ,CAAC,YAAY,EAAE,YAAY,CAAC;IAC9C,SAAS,CAAC,kBAAkB,EAAE,kBAAkB,CAAC;gBAGrB,gBAAgB,EAAE,gBAAgB,EAE5D,uBAAuB,EAAE,4BAA4B,EAC9B,aAAa,EAAE,aAAa,EACzB,gBAAgB,EAAE,gBAAgB,EACnC,eAAe,EAAE,eAAe,EACnC,YAAY,EAAE,YAAY,EAEhD,wBAAwB,EAAE,wBAAwB;IA6BpD,IAAI,YAAY,wBAEf;IAED,IAAI,eAAe,IAIQ,MAAM,CAFhC;IAED,IAAI,eAAe,CAAC,KAAK,EAAE,MAAM,EAEhC;IAED,IAAI,mBAAmB,IAIQ,MAAM,CAFpC;IAED,IAAI,mBAAmB,CAAC,KAAK,EAAE,MAAM,EAEpC;IACD,SAAS,CAAC,UAAU,8BAAqC;IACzD,IAAI,OAAO,+BAEV;IAGD,gBAAgB,EAAE,OAAO,GAAG,SAAS,CAAC;IAGtC,QAAQ,SAAM;IAEd,SAAS,CAAC,aAAa,SAAM;IAE7B,IAAI,YAAY,IAIQ,MAAM,CAF7B;IAED,IAAI,YAAY,CAAC,KAAK,EAAE,MAAM,EAE7B;IAED,qBAAqB,EAAE,wBAAwB,CAAC;IAE1C,gBAAgB;IAMhB,eAAe;IAIf,iBAAiB,CAAC,YAAY,EAAE,MAAM;IAItC,gBAAgB,CAAC,YAAY,EAAE,MAAM;IAI3C,qBAAqB;IA2BN,mBAAmB,IAAI,OAAO,CAAC,IAAI,CAAC;IAuD1C,MAAM;IAcT,SAAS;IAQT,QAAQ;IAUR,OAAO;IAkBP,SAAS;IAQf,eAAe;CAiBhB"}
|
|
@@ -3,6 +3,9 @@ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" ==
|
|
|
3
3
|
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
|
|
4
4
|
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
5
5
|
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
6
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
7
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
8
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
6
9
|
function _initializerDefineProperty(target, property, descriptor, context) { if (!descriptor) return; Object.defineProperty(target, property, { enumerable: descriptor.enumerable, configurable: descriptor.configurable, writable: descriptor.writable, value: descriptor.initializer ? descriptor.initializer.call(context) : void 0 }); }
|
|
7
10
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
8
11
|
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
@@ -19,12 +22,12 @@ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.g
|
|
|
19
22
|
function _applyDecoratedDescriptor(target, property, decorators, descriptor, context) { var desc = {}; Object.keys(descriptor).forEach(function (key) { desc[key] = descriptor[key]; }); desc.enumerable = !!desc.enumerable; desc.configurable = !!desc.configurable; if ('value' in desc || desc.initializer) { desc.writable = true; } desc = decorators.slice().reverse().reduce(function (desc, decorator) { return decorator(target, property, desc) || desc; }, desc); if (context && desc.initializer !== void 0) { desc.value = desc.initializer ? desc.initializer.call(context) : void 0; desc.initializer = undefined; } if (desc.initializer === void 0) { Object.defineProperty(target, property, desc); desc = null; } return desc; }
|
|
20
23
|
function _initializerWarningHelper(descriptor, context) { throw new Error('Decorating class property failed. Please ensure that ' + 'transform-class-properties is enabled and runs after the decorators transform.'); }
|
|
21
24
|
import { LibroModel, VirtualizedManagerHelper } from '@difizen/libro-core';
|
|
22
|
-
import { ContentsManager, ExecutableNotebookModel, LibroKernelConnectionManager, ServerConnection, ServerManager } from '@difizen/libro-kernel';
|
|
25
|
+
import { ContentsManager, ExecutableNotebookModel, isDisplayDataMsg, LibroKernelConnectionManager, ServerConnection, ServerManager } from '@difizen/libro-kernel';
|
|
23
26
|
import { getOrigin, ModalService, prop } from '@difizen/mana-app';
|
|
24
27
|
import { Deferred } from '@difizen/mana-app';
|
|
25
28
|
import { inject, transient } from '@difizen/mana-app';
|
|
26
29
|
import { l10n } from '@difizen/mana-l10n';
|
|
27
|
-
import { ExecutedWithKernelCellModel, LibroFileService } from "./libro-jupyter-protocol.js";
|
|
30
|
+
import { ExecutedWithKernelCellModel, libroArgsMimetype, LibroFileService } from "./libro-jupyter-protocol.js";
|
|
28
31
|
import { SaveFileErrorModal } from "./toolbar/save-file-error.js";
|
|
29
32
|
import { getDefaultKernel } from "./utils/index.js";
|
|
30
33
|
export var LibroJupyterModel = (_dec = transient(), _dec2 = prop(), _dec3 = prop(), _dec4 = prop(), _dec5 = prop(), _dec6 = prop(), _dec7 = prop(), _dec8 = prop(), _dec(_class = (_class2 = (_LibroJupyterModel = /*#__PURE__*/function (_LibroModel) {
|
|
@@ -60,6 +63,19 @@ export var LibroJupyterModel = (_dec = transient(), _dec2 = prop(), _dec3 = prop
|
|
|
60
63
|
_this.modalService = modalService;
|
|
61
64
|
_this.dndAreaNullEnable = true;
|
|
62
65
|
_this.virtualizedManager = virtualizedManagerHelper.getOrCreate(_assertThisInitialized(_this));
|
|
66
|
+
_this.kcReady.then(function () {
|
|
67
|
+
var _this$kernelConnectio;
|
|
68
|
+
(_this$kernelConnectio = _this.kernelConnection) === null || _this$kernelConnectio === void 0 || _this$kernelConnectio.futureMessage(function (msg) {
|
|
69
|
+
if (isDisplayDataMsg(msg) && libroArgsMimetype in msg.content.data) {
|
|
70
|
+
_this.metadata = _objectSpread(_objectSpread({}, _this.metadata), {}, {
|
|
71
|
+
args: msg.content.data[libroArgsMimetype]
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
return;
|
|
76
|
+
}).catch(function () {
|
|
77
|
+
return;
|
|
78
|
+
});
|
|
63
79
|
return _this;
|
|
64
80
|
}
|
|
65
81
|
LibroJupyterModel = inject(VirtualizedManagerHelper)(LibroJupyterModel, undefined, 6) || LibroJupyterModel;
|
|
@@ -35,4 +35,5 @@ export declare const ServerLaunchManager: unique symbol;
|
|
|
35
35
|
export interface ServerLaunchManager {
|
|
36
36
|
launch: () => Promise<any>;
|
|
37
37
|
}
|
|
38
|
+
export declare const libroArgsMimetype = "application/vnd.libro.args+json";
|
|
38
39
|
//# sourceMappingURL=libro-jupyter-protocol.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"libro-jupyter-protocol.d.ts","sourceRoot":"","sources":["../src/libro-jupyter-protocol.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,EACV,aAAa,EACb,iBAAiB,EACjB,iBAAiB,EACjB,gBAAgB,EACjB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,KAAK,EAAE,KAAK,IAAI,SAAS,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAErE,MAAM,WAAW,aAAc,SAAQ,iBAAiB;IACtD,6BAA6B,EAAE,MAAM,CAAC;IACtC,yBAAyB,EAAE,MAAM,CAAC;IAClC,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,gBAAiB,SAAQ,iBAAiB;IACzD,SAAS,EAAE,aAAa,CAAC;CAC1B;AAED,MAAM,MAAM,0BAA0B,GAAG,OAAO,CAAC,gBAAgB,GAAG,aAAa,CAAC,CAAC;AAEnF,MAAM,WAAW,2BAA4B,SAAQ,mBAAmB;IACtE,QAAQ,EAAE,0BAA0B,CAAC;IACrC,eAAe,EAAE,OAAO,CAAC;CAC1B;AAED,eAAO,MAAM,2BAA2B;cAC5B,OAAO,GAAG,EAAE,GAAG,CAAC,GAAG,SAAS;CAOvC,CAAC;AAEF,MAAM,MAAM,+BAA+B,GAAG,KAAK,CAAC,EAAE,CAAC;AACvD,eAAO,MAAM,+BAA+B,eAE3C,CAAC;AAEF,eAAO,MAAM,gBAAgB,eAA6B,CAAC;AAC3D,MAAM,WAAW,gBAAgB;IAC/B,aAAa,EAAE,SAAS,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC,CAAC;IAClD,oBAAoB,EAAE,OAAO,CAC3B,OAAO,CAAC,cAAc,CAAC,GAAG;QAAE,GAAG,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,CAC3D,CAAC;IACF,IAAI,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,cAAc,GAAG,SAAS,CAAC,CAAC;IAC5D,KAAK,EAAE,CACL,eAAe,EAAE,gBAAgB,EACjC,mBAAmB,EAAE,cAAc,KAChC,OAAO,CAAC,cAAc,GAAG,SAAS,CAAC,CAAC;CAC1C;AAED,eAAO,MAAM,mBAAmB,eAAgC,CAAC;AACjE,MAAM,WAAW,mBAAmB;IAClC,MAAM,EAAE,MAAM,OAAO,CAAC,GAAG,CAAC,CAAC;CAC5B"}
|
|
1
|
+
{"version":3,"file":"libro-jupyter-protocol.d.ts","sourceRoot":"","sources":["../src/libro-jupyter-protocol.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,EACV,aAAa,EACb,iBAAiB,EACjB,iBAAiB,EACjB,gBAAgB,EACjB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,KAAK,EAAE,KAAK,IAAI,SAAS,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAErE,MAAM,WAAW,aAAc,SAAQ,iBAAiB;IACtD,6BAA6B,EAAE,MAAM,CAAC;IACtC,yBAAyB,EAAE,MAAM,CAAC;IAClC,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,gBAAiB,SAAQ,iBAAiB;IACzD,SAAS,EAAE,aAAa,CAAC;CAC1B;AAED,MAAM,MAAM,0BAA0B,GAAG,OAAO,CAAC,gBAAgB,GAAG,aAAa,CAAC,CAAC;AAEnF,MAAM,WAAW,2BAA4B,SAAQ,mBAAmB;IACtE,QAAQ,EAAE,0BAA0B,CAAC;IACrC,eAAe,EAAE,OAAO,CAAC;CAC1B;AAED,eAAO,MAAM,2BAA2B;cAC5B,OAAO,GAAG,EAAE,GAAG,CAAC,GAAG,SAAS;CAOvC,CAAC;AAEF,MAAM,MAAM,+BAA+B,GAAG,KAAK,CAAC,EAAE,CAAC;AACvD,eAAO,MAAM,+BAA+B,eAE3C,CAAC;AAEF,eAAO,MAAM,gBAAgB,eAA6B,CAAC;AAC3D,MAAM,WAAW,gBAAgB;IAC/B,aAAa,EAAE,SAAS,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC,CAAC;IAClD,oBAAoB,EAAE,OAAO,CAC3B,OAAO,CAAC,cAAc,CAAC,GAAG;QAAE,GAAG,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,CAC3D,CAAC;IACF,IAAI,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,cAAc,GAAG,SAAS,CAAC,CAAC;IAC5D,KAAK,EAAE,CACL,eAAe,EAAE,gBAAgB,EACjC,mBAAmB,EAAE,cAAc,KAChC,OAAO,CAAC,cAAc,GAAG,SAAS,CAAC,CAAC;CAC1C;AAED,eAAO,MAAM,mBAAmB,eAAgC,CAAC;AACjE,MAAM,WAAW,mBAAmB;IAClC,MAAM,EAAE,MAAM,OAAO,CAAC,GAAG,CAAC,CAAC;CAC5B;AAED,eAAO,MAAM,iBAAiB,oCAAoC,CAAC"}
|
|
@@ -6,4 +6,5 @@ export var ExecutedWithKernelCellModel = {
|
|
|
6
6
|
};
|
|
7
7
|
export var KernelStatusAndSelectorProvider = Symbol('KernelStatusAndSelectorProvider');
|
|
8
8
|
export var LibroFileService = Symbol('LibroFileService');
|
|
9
|
-
export var ServerLaunchManager = Symbol('ServerLaunchManager');
|
|
9
|
+
export var ServerLaunchManager = Symbol('ServerLaunchManager');
|
|
10
|
+
export var libroArgsMimetype = 'application/vnd.libro.args+json';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@difizen/libro-jupyter",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.18",
|
|
4
4
|
"description": "",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"libro"
|
|
@@ -31,21 +31,21 @@
|
|
|
31
31
|
"src"
|
|
32
32
|
],
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@difizen/libro-cofine-editor": "^0.1.
|
|
35
|
-
"@difizen/libro-code-editor": "^0.1.
|
|
36
|
-
"@difizen/libro-code-cell": "^0.1.
|
|
37
|
-
"@difizen/libro-codemirror": "^0.1.
|
|
38
|
-
"@difizen/libro-rendermime": "^0.1.
|
|
39
|
-
"@difizen/libro-common": "^0.1.
|
|
40
|
-
"@difizen/libro-core": "^0.1.
|
|
41
|
-
"@difizen/libro-kernel": "^0.1.
|
|
42
|
-
"@difizen/libro-l10n": "^0.1.
|
|
43
|
-
"@difizen/libro-output": "^0.1.
|
|
44
|
-
"@difizen/libro-search": "^0.1.
|
|
45
|
-
"@difizen/libro-search-code-cell": "^0.1.
|
|
46
|
-
"@difizen/libro-lsp": "^0.1.
|
|
47
|
-
"@difizen/libro-markdown-cell": "^0.1.
|
|
48
|
-
"@difizen/libro-raw-cell": "^0.1.
|
|
34
|
+
"@difizen/libro-cofine-editor": "^0.1.18",
|
|
35
|
+
"@difizen/libro-code-editor": "^0.1.18",
|
|
36
|
+
"@difizen/libro-code-cell": "^0.1.18",
|
|
37
|
+
"@difizen/libro-codemirror": "^0.1.18",
|
|
38
|
+
"@difizen/libro-rendermime": "^0.1.18",
|
|
39
|
+
"@difizen/libro-common": "^0.1.18",
|
|
40
|
+
"@difizen/libro-core": "^0.1.18",
|
|
41
|
+
"@difizen/libro-kernel": "^0.1.18",
|
|
42
|
+
"@difizen/libro-l10n": "^0.1.18",
|
|
43
|
+
"@difizen/libro-output": "^0.1.18",
|
|
44
|
+
"@difizen/libro-search": "^0.1.18",
|
|
45
|
+
"@difizen/libro-search-code-cell": "^0.1.18",
|
|
46
|
+
"@difizen/libro-lsp": "^0.1.18",
|
|
47
|
+
"@difizen/libro-markdown-cell": "^0.1.18",
|
|
48
|
+
"@difizen/libro-raw-cell": "^0.1.18",
|
|
49
49
|
"@difizen/mana-app": "latest",
|
|
50
50
|
"@difizen/mana-l10n": "latest",
|
|
51
51
|
"@ant-design/colors": "^7.0.0",
|
|
@@ -22,8 +22,6 @@ import {
|
|
|
22
22
|
} from '@difizen/mana-app';
|
|
23
23
|
import { message, Modal } from 'antd';
|
|
24
24
|
|
|
25
|
-
import { LibroConfigAllowDownload } from '../config/index.js';
|
|
26
|
-
|
|
27
25
|
import { FileCreateModal } from './file-create-modal.js';
|
|
28
26
|
import { FileDirCreateModal } from './file-createdir-modal.js';
|
|
29
27
|
import { FileRenameModal } from './file-rename-modal.js';
|
|
@@ -81,6 +79,10 @@ export const FileCommands = {
|
|
|
81
79
|
id: 'fileTree.command.download',
|
|
82
80
|
label: '下载',
|
|
83
81
|
},
|
|
82
|
+
UPLOAD: {
|
|
83
|
+
id: 'fileTree.command.upload',
|
|
84
|
+
label: '上传',
|
|
85
|
+
},
|
|
84
86
|
};
|
|
85
87
|
export const FileTreeContextMenuPath: MenuPath = ['file-tree-context-menu'];
|
|
86
88
|
export const FileTreeContextMenuGroups: Record<string, MenuPath> = {
|
|
@@ -106,6 +108,8 @@ export class FileCommandContribution
|
|
|
106
108
|
fileView: FileView;
|
|
107
109
|
lastAction: 'COPY' | 'CUT';
|
|
108
110
|
lastActionNode: FileStatNode;
|
|
111
|
+
allowDownload = false;
|
|
112
|
+
allowUpload = false;
|
|
109
113
|
|
|
110
114
|
constructor(@inject(ViewManager) viewManager: ViewManager) {
|
|
111
115
|
this.viewManager = viewManager;
|
|
@@ -181,6 +185,11 @@ export class FileCommandContribution
|
|
|
181
185
|
command: FileCommands.DOWNLOAD.id,
|
|
182
186
|
order: 'h',
|
|
183
187
|
});
|
|
188
|
+
menu.registerMenuAction(FileTreeContextMenuGroups['extra'], {
|
|
189
|
+
id: FileCommands.UPLOAD.id,
|
|
190
|
+
command: FileCommands.UPLOAD.id,
|
|
191
|
+
order: 'i',
|
|
192
|
+
});
|
|
184
193
|
}
|
|
185
194
|
registerCommands(command: CommandRegistry): void {
|
|
186
195
|
command.registerCommand(FileCommands.OPEN_FILE, {
|
|
@@ -357,6 +366,11 @@ export class FileCommandContribution
|
|
|
357
366
|
this.contentsManager
|
|
358
367
|
.getDownloadUrl(path)
|
|
359
368
|
.then((url) => {
|
|
369
|
+
const urlObj = new URL(url);
|
|
370
|
+
if (urlObj.origin !== location.origin) {
|
|
371
|
+
// not same origin
|
|
372
|
+
return;
|
|
373
|
+
}
|
|
360
374
|
const element = document.createElement('a');
|
|
361
375
|
element.href = url;
|
|
362
376
|
element.download = '';
|
|
@@ -369,10 +383,36 @@ export class FileCommandContribution
|
|
|
369
383
|
.catch(console.error);
|
|
370
384
|
},
|
|
371
385
|
isVisible: (data) => {
|
|
372
|
-
return (
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
386
|
+
return this.allowDownload && FileStatNode.is(data) && data.fileStat.isFile;
|
|
387
|
+
},
|
|
388
|
+
});
|
|
389
|
+
|
|
390
|
+
command.registerCommand(FileCommands.UPLOAD, {
|
|
391
|
+
execute: (data, view) => {
|
|
392
|
+
if (!this.allowUpload) {
|
|
393
|
+
return;
|
|
394
|
+
}
|
|
395
|
+
if (!view || !(view instanceof FileView)) {
|
|
396
|
+
return;
|
|
397
|
+
}
|
|
398
|
+
if (!data || data instanceof FileView) {
|
|
399
|
+
return view.uploadSubmit();
|
|
400
|
+
}
|
|
401
|
+
if (FileStatNode.is(data) && data.fileStat.isDirectory) {
|
|
402
|
+
return view.uploadSubmit(data.uri.path.toString());
|
|
403
|
+
}
|
|
404
|
+
},
|
|
405
|
+
isVisible: (data, view) => {
|
|
406
|
+
if (!this.allowUpload) {
|
|
407
|
+
return false;
|
|
408
|
+
}
|
|
409
|
+
if (!view || !(view instanceof FileView)) {
|
|
410
|
+
return false;
|
|
411
|
+
}
|
|
412
|
+
if (!data || data instanceof FileView) {
|
|
413
|
+
return true;
|
|
414
|
+
}
|
|
415
|
+
return FileStatNode.is(data) && data.fileStat.isDirectory;
|
|
376
416
|
},
|
|
377
417
|
});
|
|
378
418
|
}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { ExclamationCircleFilled, FolderFilled } from '@ant-design/icons';
|
|
2
|
+
import { ContentsManager } from '@difizen/libro-kernel';
|
|
3
|
+
import type { IContentsModel } from '@difizen/libro-kernel';
|
|
2
4
|
import type { TreeNode, ViewOpenHandler } from '@difizen/mana-app';
|
|
3
5
|
import { FileTreeViewFactory } from '@difizen/mana-app';
|
|
4
6
|
import {
|
|
@@ -39,7 +41,9 @@ const noVerifyFileType = ['.ipynb', '.py'];
|
|
|
39
41
|
@view(FileTreeViewFactory, FileTreeModule)
|
|
40
42
|
export class FileView extends FileTreeView {
|
|
41
43
|
@inject(OpenerService) protected openService: OpenerService;
|
|
44
|
+
@inject(ContentsManager) protected contentsManager: ContentsManager;
|
|
42
45
|
@inject(CommandRegistry) protected command: CommandRegistry;
|
|
46
|
+
uploadInput?: HTMLInputElement;
|
|
43
47
|
override id = FileTreeViewFactory;
|
|
44
48
|
override className = 'libro-jupyter-file-tree';
|
|
45
49
|
|
|
@@ -64,6 +68,92 @@ export class FileView extends FileTreeView {
|
|
|
64
68
|
this.toDispose.push(this.model.onOpenNode(this.openNode));
|
|
65
69
|
}
|
|
66
70
|
|
|
71
|
+
override onViewMount(): void {
|
|
72
|
+
super.onViewMount?.();
|
|
73
|
+
if (!this.container?.current) {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
const container = this.container.current;
|
|
77
|
+
const input = document.createElement('input');
|
|
78
|
+
input.type = 'file';
|
|
79
|
+
input.multiple = true;
|
|
80
|
+
input.onclick = this.onInputClicked;
|
|
81
|
+
input.onchange = this.onInputChanged;
|
|
82
|
+
input.style.display = 'none';
|
|
83
|
+
container.appendChild(input);
|
|
84
|
+
this.uploadInput = input;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
uploadSubmit = (basePath?: string) => {
|
|
88
|
+
if (this.uploadInput) {
|
|
89
|
+
this.uploadInput.setAttribute('data-path', basePath || '');
|
|
90
|
+
this.uploadInput.click();
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
/**
|
|
94
|
+
* Perform the actual upload.
|
|
95
|
+
*/
|
|
96
|
+
protected async doUpload(file: File, basePath: string): Promise<IContentsModel> {
|
|
97
|
+
// Gather the file model parameters.
|
|
98
|
+
let path = basePath;
|
|
99
|
+
path = path ? path + '/' + file.name : file.name;
|
|
100
|
+
const name = file.name;
|
|
101
|
+
const type = 'file';
|
|
102
|
+
const format = 'base64';
|
|
103
|
+
|
|
104
|
+
const uploadInner = async (blob: Blob, chunk?: number): Promise<IContentsModel> => {
|
|
105
|
+
const reader = new FileReader();
|
|
106
|
+
reader.readAsDataURL(blob);
|
|
107
|
+
await new Promise((resolve, reject) => {
|
|
108
|
+
reader.onload = resolve;
|
|
109
|
+
reader.onerror = (event) => reject(`Failed to upload "${file.name}":` + event);
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
// remove header https://stackoverflow.com/a/24289420/907060
|
|
113
|
+
const content = (reader.result as string).split(',')[1];
|
|
114
|
+
|
|
115
|
+
const model: Partial<IContentsModel> = {
|
|
116
|
+
type,
|
|
117
|
+
format,
|
|
118
|
+
name,
|
|
119
|
+
chunk,
|
|
120
|
+
content,
|
|
121
|
+
};
|
|
122
|
+
return await this.contentsManager.save(path, model);
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
return await uploadInner(file);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
onInputChanged = () => {
|
|
129
|
+
if (!this.uploadInput) {
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
let path = this.uploadInput.getAttribute('data-path') || '';
|
|
133
|
+
if (!path) {
|
|
134
|
+
path = this.model.location?.path.toString() || '';
|
|
135
|
+
}
|
|
136
|
+
if (!path) {
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
const files = Array.prototype.slice.call(this.uploadInput.files) as File[];
|
|
140
|
+
const pending = files.map((file) => this.doUpload(file, path));
|
|
141
|
+
Promise.all(pending)
|
|
142
|
+
.then(() => {
|
|
143
|
+
this.model.refresh();
|
|
144
|
+
return;
|
|
145
|
+
})
|
|
146
|
+
.catch((error) => {
|
|
147
|
+
console.error('Upload Error:', error);
|
|
148
|
+
});
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
onInputClicked = () => {
|
|
152
|
+
if (this.uploadInput) {
|
|
153
|
+
this.uploadInput.value = '';
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
|
|
67
157
|
openNode = async (treeNode: TreeNode) => {
|
|
68
158
|
if (FileStatNode.is(treeNode) && !treeNode.fileStat.isDirectory) {
|
|
69
159
|
if (
|
|
@@ -3,6 +3,7 @@ import type { VirtualizedManager } from '@difizen/libro-core';
|
|
|
3
3
|
import {
|
|
4
4
|
ContentsManager,
|
|
5
5
|
ExecutableNotebookModel,
|
|
6
|
+
isDisplayDataMsg,
|
|
6
7
|
LibroKernelConnectionManager,
|
|
7
8
|
ServerConnection,
|
|
8
9
|
ServerManager,
|
|
@@ -16,6 +17,7 @@ import { l10n } from '@difizen/mana-l10n';
|
|
|
16
17
|
|
|
17
18
|
import {
|
|
18
19
|
ExecutedWithKernelCellModel,
|
|
20
|
+
libroArgsMimetype,
|
|
19
21
|
LibroFileService,
|
|
20
22
|
} from './libro-jupyter-protocol.js';
|
|
21
23
|
import { SaveFileErrorModal } from './toolbar/save-file-error.js';
|
|
@@ -81,6 +83,21 @@ export class LibroJupyterModel extends LibroModel implements ExecutableNotebookM
|
|
|
81
83
|
this.modalService = modalService;
|
|
82
84
|
this.dndAreaNullEnable = true;
|
|
83
85
|
this.virtualizedManager = virtualizedManagerHelper.getOrCreate(this);
|
|
86
|
+
this.kcReady
|
|
87
|
+
.then(() => {
|
|
88
|
+
this.kernelConnection?.futureMessage((msg) => {
|
|
89
|
+
if (isDisplayDataMsg(msg) && libroArgsMimetype in msg.content.data) {
|
|
90
|
+
this.metadata = {
|
|
91
|
+
...this.metadata,
|
|
92
|
+
args: msg.content.data[libroArgsMimetype],
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
return;
|
|
97
|
+
})
|
|
98
|
+
.catch(() => {
|
|
99
|
+
return;
|
|
100
|
+
});
|
|
84
101
|
}
|
|
85
102
|
|
|
86
103
|
get isKernelIdle() {
|