@difizen/libro-jupyter 0.1.16 → 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.
@@ -1 +1 @@
1
- {"version":3,"file":"config-contribution.d.ts","sourceRoot":"","sources":["../../src/config/config-contribution.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,yBAAyB,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AACpF,OAAO,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAAC;AAK5D,qBACa,+BAAgC,YAAW,yBAAyB;IAC/E,sBAAsB;CAGvB;AACD,qBACa,qBAAsB,YAAW,uBAAuB;IACrC,oBAAoB,EAAE,oBAAoB,CAAC;IACzE,WAAW;CAIZ"}
1
+ {"version":3,"file":"config-contribution.d.ts","sourceRoot":"","sources":["../../src/config/config-contribution.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,yBAAyB,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AACpF,OAAO,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAAC;AAK5D,qBACa,+BAAgC,YAAW,yBAAyB;IAC/E,sBAAsB;CAQvB;AACD,qBACa,qBAAsB,YAAW,uBAAuB;IACrC,oBAAoB,EAAE,oBAAoB,CAAC;IACzE,WAAW;CAIZ"}
@@ -22,7 +22,7 @@ export var LibroJupyterSettingContribution = (_dec = singleton({
22
22
  _createClass(LibroJupyterSettingContribution, [{
23
23
  key: "registerConfigurations",
24
24
  value: function registerConfigurations() {
25
- return [LibroJupyterConfiguration.AutoSave, LibroJupyterConfiguration.OpenSlot];
25
+ return [LibroJupyterConfiguration.AutoSave, LibroJupyterConfiguration.OpenSlot, LibroJupyterConfiguration.AllowDownload, LibroJupyterConfiguration.AllowUpload];
26
26
  }
27
27
  }]);
28
28
  return LibroJupyterSettingContribution;
@@ -1,8 +1,12 @@
1
1
  import type { ConfigurationNode } from '@difizen/mana-app';
2
2
  export declare const LibroConfigAutoSave: ConfigurationNode<boolean>;
3
3
  export declare const LibroConfigOpenSlot: ConfigurationNode<string>;
4
+ export declare const LibroConfigAllowDownload: ConfigurationNode<boolean>;
5
+ export declare const LibroConfigAllowUpload: ConfigurationNode<boolean>;
4
6
  export declare const LibroJupyterConfiguration: {
5
7
  AutoSave: ConfigurationNode<boolean>;
6
8
  OpenSlot: ConfigurationNode<string>;
9
+ AllowUpload: ConfigurationNode<boolean>;
10
+ AllowDownload: ConfigurationNode<boolean>;
7
11
  };
8
12
  //# sourceMappingURL=config.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/config/config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAG3D,eAAO,MAAM,mBAAmB,EAAE,iBAAiB,CAAC,OAAO,CAS1D,CAAC;AAEF,eAAO,MAAM,mBAAmB,EAAE,iBAAiB,CAAC,MAAM,CASzD,CAAC;AAEF,eAAO,MAAM,yBAAyB;;;CAGrC,CAAC"}
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/config/config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAG3D,eAAO,MAAM,mBAAmB,EAAE,iBAAiB,CAAC,OAAO,CAS1D,CAAC;AAEF,eAAO,MAAM,mBAAmB,EAAE,iBAAiB,CAAC,MAAM,CASzD,CAAC;AAEF,eAAO,MAAM,wBAAwB,EAAE,iBAAiB,CAAC,OAAO,CAS/D,CAAC;AAEF,eAAO,MAAM,sBAAsB,EAAE,iBAAiB,CAAC,OAAO,CAS7D,CAAC;AAEF,eAAO,MAAM,yBAAyB;;;;;CAKrC,CAAC"}
@@ -2,7 +2,7 @@ import { l10n } from '@difizen/mana-l10n';
2
2
  export var LibroConfigAutoSave = {
3
3
  id: 'libro.autosave',
4
4
  description: l10n.t('是否自动保存修改'),
5
- title: 'checkbox',
5
+ title: '自动保存',
6
6
  type: 'checkbox',
7
7
  defaultValue: false,
8
8
  schema: {
@@ -13,13 +13,35 @@ export var LibroConfigOpenSlot = {
13
13
  id: 'libro.jupyter.open.slot',
14
14
  description: '文件默认打开位置',
15
15
  title: '文件默认打开位置',
16
- type: 'checkbox',
16
+ type: 'input',
17
17
  defaultValue: 'main',
18
18
  schema: {
19
19
  type: 'string'
20
20
  }
21
21
  };
22
+ export var LibroConfigAllowDownload = {
23
+ id: 'libro.jupyter.allow.download',
24
+ description: '是否允许下载',
25
+ title: '允许下载',
26
+ type: 'checkbox',
27
+ defaultValue: true,
28
+ schema: {
29
+ type: 'boolean'
30
+ }
31
+ };
32
+ export var LibroConfigAllowUpload = {
33
+ id: 'libro.jupyter.allow.upload',
34
+ description: '是否允许上传',
35
+ title: '允许上传',
36
+ type: 'checkbox',
37
+ defaultValue: true,
38
+ schema: {
39
+ type: 'boolean'
40
+ }
41
+ };
22
42
  export var LibroJupyterConfiguration = {
23
43
  AutoSave: LibroConfigAutoSave,
24
- OpenSlot: LibroConfigOpenSlot
44
+ OpenSlot: LibroConfigOpenSlot,
45
+ AllowUpload: LibroConfigAllowUpload,
46
+ AllowDownload: LibroConfigAllowDownload
25
47
  };
@@ -1,5 +1,6 @@
1
+ import { ContentsManager } from '@difizen/libro-kernel';
1
2
  import type { CommandRegistry, MenuPath, MenuRegistry, ToolbarRegistry } from '@difizen/mana-app';
2
- import { ViewManager } from '@difizen/mana-app';
3
+ import { ViewManager, ConfigurationService } from '@difizen/mana-app';
3
4
  import { CommandContribution, FileStatNode, MenuContribution, ModalService, OpenerService, ToolbarContribution } from '@difizen/mana-app';
4
5
  import { JupyterFileService } from './file-service.js';
5
6
  import { FileView } from './file-view/index.js';
@@ -49,16 +50,29 @@ export declare const FileCommands: {
49
50
  id: string;
50
51
  label: string;
51
52
  };
53
+ DOWNLOAD: {
54
+ id: string;
55
+ label: string;
56
+ };
57
+ UPLOAD: {
58
+ id: string;
59
+ label: string;
60
+ };
52
61
  };
53
62
  export declare const FileTreeContextMenuPath: MenuPath;
63
+ export declare const FileTreeContextMenuGroups: Record<string, MenuPath>;
54
64
  export declare class FileCommandContribution implements CommandContribution, MenuContribution, ToolbarContribution {
55
65
  protected viewManager: ViewManager;
56
66
  fileService: JupyterFileService;
57
67
  modalService: ModalService;
58
68
  protected openService: OpenerService;
69
+ configurationService: ConfigurationService;
70
+ contentsManager: ContentsManager;
59
71
  fileView: FileView;
60
72
  lastAction: 'COPY' | 'CUT';
61
73
  lastActionNode: FileStatNode;
74
+ allowDownload: boolean;
75
+ allowUpload: boolean;
62
76
  constructor(viewManager: ViewManager);
63
77
  registerMenus(menu: MenuRegistry): void;
64
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,KAAK,EACV,eAAe,EACf,QAAQ,EACR,YAAY,EACZ,eAAe,EAChB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA6CxB,CAAC;AACF,eAAO,MAAM,uBAAuB,EAAE,QAAqC,CAAC;AAE5E,qBAGa,uBACX,YAAW,mBAAmB,EAAE,gBAAgB,EAAE,mBAAmB;IAErE,SAAS,CAAC,WAAW,EAAE,WAAW,CAAC;IACP,WAAW,EAAE,kBAAkB,CAAC;IACtC,YAAY,EAAE,YAAY,C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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"}
@@ -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, _descriptor3;
2
+ var _dec, _dec2, _dec3, _dec4, _dec5, _dec6, _class, _class2, _descriptor, _descriptor2, _descriptor3, _descriptor4, _descriptor5;
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); }); }; }
@@ -16,7 +16,8 @@ function _applyDecoratedDescriptor(target, property, decorators, descriptor, con
16
16
  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.'); }
17
17
  import pathUtil from 'path';
18
18
  import { ReloadOutlined } from '@ant-design/icons';
19
- import { ViewManager } from '@difizen/mana-app';
19
+ import { ContentsManager } from '@difizen/libro-kernel';
20
+ import { ViewManager, ConfigurationService } from '@difizen/mana-app';
20
21
  import { CommandContribution, FileStatNode, inject, MenuContribution, ModalService, OpenerService, singleton, ToolbarContribution, URI } from '@difizen/mana-app';
21
22
  import { message, Modal } from 'antd';
22
23
  import { FileCreateModal } from "./file-create-modal.js";
@@ -71,12 +72,26 @@ export var FileCommands = {
71
72
  REMOVE: {
72
73
  id: 'fileTree.command.remove',
73
74
  label: '删除'
75
+ },
76
+ DOWNLOAD: {
77
+ id: 'fileTree.command.download',
78
+ label: '下载'
79
+ },
80
+ UPLOAD: {
81
+ id: 'fileTree.command.upload',
82
+ label: '上传'
74
83
  }
75
84
  };
76
85
  export var FileTreeContextMenuPath = ['file-tree-context-menu'];
86
+ export var FileTreeContextMenuGroups = {
87
+ new: [].concat(FileTreeContextMenuPath, ['a_new']),
88
+ operator: [].concat(FileTreeContextMenuPath, ['b_operator']),
89
+ change: [].concat(FileTreeContextMenuPath, ['c_change']),
90
+ extra: [].concat(FileTreeContextMenuPath, ['d_extra'])
91
+ };
77
92
  export var FileCommandContribution = (_dec = singleton({
78
93
  contrib: [CommandContribution, MenuContribution, ToolbarContribution]
79
- }), _dec2 = inject(JupyterFileService), _dec3 = inject(ModalService), _dec4 = inject(OpenerService), _dec(_class = (_class2 = /*#__PURE__*/function () {
94
+ }), _dec2 = inject(JupyterFileService), _dec3 = inject(ModalService), _dec4 = inject(OpenerService), _dec5 = inject(ConfigurationService), _dec6 = inject(ContentsManager), _dec(_class = (_class2 = /*#__PURE__*/function () {
80
95
  function FileCommandContribution(viewManager) {
81
96
  var _this = this;
82
97
  _classCallCheck(this, FileCommandContribution);
@@ -84,9 +99,13 @@ export var FileCommandContribution = (_dec = singleton({
84
99
  _initializerDefineProperty(this, "fileService", _descriptor, this);
85
100
  _initializerDefineProperty(this, "modalService", _descriptor2, this);
86
101
  _initializerDefineProperty(this, "openService", _descriptor3, this);
102
+ _initializerDefineProperty(this, "configurationService", _descriptor4, this);
103
+ _initializerDefineProperty(this, "contentsManager", _descriptor5, this);
87
104
  this.fileView = void 0;
88
105
  this.lastAction = void 0;
89
106
  this.lastActionNode = void 0;
107
+ this.allowDownload = false;
108
+ this.allowUpload = false;
90
109
  this.viewManager = viewManager;
91
110
  this.viewManager.getOrCreateView(FileView).then(function (view) {
92
111
  _this.fileView = view;
@@ -99,55 +118,69 @@ export var FileCommandContribution = (_dec = singleton({
99
118
  _createClass(FileCommandContribution, [{
100
119
  key: "registerMenus",
101
120
  value: function registerMenus(menu) {
102
- menu.registerMenuAction(FileTreeContextMenuPath, {
121
+ menu.registerGroupMenu(FileTreeContextMenuGroups['new']);
122
+ menu.registerGroupMenu(FileTreeContextMenuGroups['operator']);
123
+ menu.registerGroupMenu(FileTreeContextMenuGroups['change']);
124
+ menu.registerGroupMenu(FileTreeContextMenuGroups['extra']);
125
+ menu.registerMenuAction(FileTreeContextMenuGroups['new'], {
103
126
  id: FileCommands.CREATE_FILE.id,
104
127
  command: FileCommands.CREATE_FILE.id,
105
128
  order: 'a'
106
129
  });
107
- menu.registerMenuAction(FileTreeContextMenuPath, {
130
+ menu.registerMenuAction(FileTreeContextMenuGroups['new'], {
108
131
  id: FileCommands.CREATE_DIR.id,
109
132
  command: FileCommands.CREATE_DIR.id,
110
133
  order: 'a'
111
134
  });
112
- menu.registerMenuAction(FileTreeContextMenuPath, {
135
+ menu.registerMenuAction(FileTreeContextMenuGroups['new'], {
113
136
  id: FileCommands.OPEN_FILE.id,
114
137
  command: FileCommands.OPEN_FILE.id,
115
138
  order: 'a'
116
139
  });
117
- menu.registerMenuAction(FileTreeContextMenuPath, {
140
+ menu.registerMenuAction(FileTreeContextMenuGroups['operator'], {
118
141
  id: FileCommands.COPY.id,
119
142
  command: FileCommands.COPY.id,
120
143
  order: 'b'
121
144
  });
122
- menu.registerMenuAction(FileTreeContextMenuPath, {
145
+ menu.registerMenuAction(FileTreeContextMenuGroups['operator'], {
123
146
  id: FileCommands.PASTE.id,
124
147
  command: FileCommands.PASTE.id,
125
148
  order: 'c'
126
149
  });
127
- menu.registerMenuAction(FileTreeContextMenuPath, {
150
+ menu.registerMenuAction(FileTreeContextMenuGroups['operator'], {
128
151
  id: FileCommands.CUT.id,
129
152
  command: FileCommands.CUT.id,
130
153
  order: 'd'
131
154
  });
132
- menu.registerMenuAction(FileTreeContextMenuPath, _objectSpread({
155
+ menu.registerMenuAction(FileTreeContextMenuGroups['change'], _objectSpread({
133
156
  command: FileCommands.REMOVE.id,
134
157
  order: 'd'
135
158
  }, FileCommands.REMOVE));
136
- menu.registerMenuAction(FileTreeContextMenuPath, {
159
+ menu.registerMenuAction(FileTreeContextMenuGroups['change'], {
137
160
  id: FileCommands.RENAME.id,
138
161
  command: FileCommands.RENAME.id,
139
162
  order: 'e'
140
163
  });
141
- menu.registerMenuAction(FileTreeContextMenuPath, {
164
+ menu.registerMenuAction(FileTreeContextMenuGroups['extra'], {
142
165
  id: FileCommands.COPY_PATH.id,
143
166
  command: FileCommands.COPY_PATH.id,
144
- order: 'g'
167
+ order: 'f'
145
168
  });
146
- menu.registerMenuAction(FileTreeContextMenuPath, {
169
+ menu.registerMenuAction(FileTreeContextMenuGroups['extra'], {
147
170
  id: FileCommands.COPY_RELATIVE_PATH.id,
148
171
  command: FileCommands.COPY_RELATIVE_PATH.id,
149
172
  order: 'g'
150
173
  });
174
+ menu.registerMenuAction(FileTreeContextMenuGroups['extra'], {
175
+ id: FileCommands.DOWNLOAD.id,
176
+ command: FileCommands.DOWNLOAD.id,
177
+ order: 'h'
178
+ });
179
+ menu.registerMenuAction(FileTreeContextMenuGroups['extra'], {
180
+ id: FileCommands.UPLOAD.id,
181
+ command: FileCommands.UPLOAD.id,
182
+ order: 'i'
183
+ });
151
184
  }
152
185
  }, {
153
186
  key: "registerCommands",
@@ -450,6 +483,60 @@ export var FileCommandContribution = (_dec = singleton({
450
483
  return view instanceof FileView;
451
484
  }
452
485
  });
486
+ command.registerCommand(FileCommands.DOWNLOAD, {
487
+ execute: function execute(data) {
488
+ if (!FileStatNode.is(data)) {
489
+ return;
490
+ }
491
+ var path = data.uri.path.toString();
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
+ }
498
+ var element = document.createElement('a');
499
+ element.href = url;
500
+ element.download = '';
501
+ element.target = '_blank';
502
+ document.body.appendChild(element);
503
+ element.click();
504
+ document.body.removeChild(element);
505
+ return;
506
+ }).catch(console.error);
507
+ },
508
+ isVisible: function isVisible(data) {
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;
538
+ }
539
+ });
453
540
  }
454
541
  }, {
455
542
  key: "registerToolbarItems",
@@ -478,4 +565,14 @@ export var FileCommandContribution = (_dec = singleton({
478
565
  enumerable: true,
479
566
  writable: true,
480
567
  initializer: null
568
+ }), _descriptor4 = _applyDecoratedDescriptor(_class2.prototype, "configurationService", [_dec5], {
569
+ configurable: true,
570
+ enumerable: true,
571
+ writable: true,
572
+ initializer: null
573
+ }), _descriptor5 = _applyDecoratedDescriptor(_class2.prototype, "contentsManager", [_dec6], {
574
+ configurable: true,
575
+ enumerable: true,
576
+ writable: true,
577
+ initializer: null
481
578
  })), _class2)) || _class);
@@ -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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AG1B,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, "command", _descriptor2, _assertThisInitialized(_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, "command", [_dec4], {
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":[],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AAI,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,GA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roFileService = 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.16",
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.16",
35
- "@difizen/libro-code-editor": "^0.1.16",
36
- "@difizen/libro-code-cell": "^0.1.16",
37
- "@difizen/libro-codemirror": "^0.1.16",
38
- "@difizen/libro-rendermime": "^0.1.16",
39
- "@difizen/libro-common": "^0.1.16",
40
- "@difizen/libro-core": "^0.1.16",
41
- "@difizen/libro-kernel": "^0.1.16",
42
- "@difizen/libro-l10n": "^0.1.16",
43
- "@difizen/libro-output": "^0.1.16",
44
- "@difizen/libro-search": "^0.1.16",
45
- "@difizen/libro-search-code-cell": "^0.1.16",
46
- "@difizen/libro-lsp": "^0.1.16",
47
- "@difizen/libro-markdown-cell": "^0.1.16",
48
- "@difizen/libro-raw-cell": "^0.1.16",
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",
@@ -8,7 +8,12 @@ import { LibroJupyterConfiguration } from './config.js';
8
8
  @singleton({ contrib: ConfigurationContribution })
9
9
  export class LibroJupyterSettingContribution implements ConfigurationContribution {
10
10
  registerConfigurations() {
11
- return [LibroJupyterConfiguration.AutoSave, LibroJupyterConfiguration.OpenSlot];
11
+ return [
12
+ LibroJupyterConfiguration.AutoSave,
13
+ LibroJupyterConfiguration.OpenSlot,
14
+ LibroJupyterConfiguration.AllowDownload,
15
+ LibroJupyterConfiguration.AllowUpload,
16
+ ];
12
17
  }
13
18
  }
14
19
  @singleton({ contrib: ApplicationContribution })
@@ -4,7 +4,7 @@ import { l10n } from '@difizen/mana-l10n';
4
4
  export const LibroConfigAutoSave: ConfigurationNode<boolean> = {
5
5
  id: 'libro.autosave',
6
6
  description: l10n.t('是否自动保存修改'),
7
- title: 'checkbox',
7
+ title: '自动保存',
8
8
  type: 'checkbox',
9
9
  defaultValue: false,
10
10
  schema: {
@@ -16,14 +16,38 @@ export const LibroConfigOpenSlot: ConfigurationNode<string> = {
16
16
  id: 'libro.jupyter.open.slot',
17
17
  description: '文件默认打开位置',
18
18
  title: '文件默认打开位置',
19
- type: 'checkbox',
19
+ type: 'input',
20
20
  defaultValue: 'main',
21
21
  schema: {
22
22
  type: 'string',
23
23
  },
24
24
  };
25
25
 
26
+ export const LibroConfigAllowDownload: ConfigurationNode<boolean> = {
27
+ id: 'libro.jupyter.allow.download',
28
+ description: '是否允许下载',
29
+ title: '允许下载',
30
+ type: 'checkbox',
31
+ defaultValue: true,
32
+ schema: {
33
+ type: 'boolean',
34
+ },
35
+ };
36
+
37
+ export const LibroConfigAllowUpload: ConfigurationNode<boolean> = {
38
+ id: 'libro.jupyter.allow.upload',
39
+ description: '是否允许上传',
40
+ title: '允许上传',
41
+ type: 'checkbox',
42
+ defaultValue: true,
43
+ schema: {
44
+ type: 'boolean',
45
+ },
46
+ };
47
+
26
48
  export const LibroJupyterConfiguration = {
27
49
  AutoSave: LibroConfigAutoSave,
28
50
  OpenSlot: LibroConfigOpenSlot,
51
+ AllowUpload: LibroConfigAllowUpload,
52
+ AllowDownload: LibroConfigAllowDownload,
29
53
  };
@@ -1,13 +1,14 @@
1
1
  import pathUtil from 'path';
2
2
 
3
3
  import { ReloadOutlined } from '@ant-design/icons';
4
+ import { ContentsManager } from '@difizen/libro-kernel';
4
5
  import type {
5
6
  CommandRegistry,
6
7
  MenuPath,
7
8
  MenuRegistry,
8
9
  ToolbarRegistry,
9
10
  } from '@difizen/mana-app';
10
- import { ViewManager } from '@difizen/mana-app';
11
+ import { ViewManager, ConfigurationService } from '@difizen/mana-app';
11
12
  import {
12
13
  CommandContribution,
13
14
  FileStatNode,
@@ -74,8 +75,22 @@ export const FileCommands = {
74
75
  id: 'fileTree.command.remove',
75
76
  label: '删除',
76
77
  },
78
+ DOWNLOAD: {
79
+ id: 'fileTree.command.download',
80
+ label: '下载',
81
+ },
82
+ UPLOAD: {
83
+ id: 'fileTree.command.upload',
84
+ label: '上传',
85
+ },
77
86
  };
78
87
  export const FileTreeContextMenuPath: MenuPath = ['file-tree-context-menu'];
88
+ export const FileTreeContextMenuGroups: Record<string, MenuPath> = {
89
+ new: [...FileTreeContextMenuPath, 'a_new'],
90
+ operator: [...FileTreeContextMenuPath, 'b_operator'],
91
+ change: [...FileTreeContextMenuPath, 'c_change'],
92
+ extra: [...FileTreeContextMenuPath, 'd_extra'],
93
+ };
79
94
 
80
95
  @singleton({
81
96
  contrib: [CommandContribution, MenuContribution, ToolbarContribution],
@@ -87,9 +102,14 @@ export class FileCommandContribution
87
102
  @inject(JupyterFileService) fileService: JupyterFileService;
88
103
  @inject(ModalService) modalService: ModalService;
89
104
  @inject(OpenerService) protected openService: OpenerService;
105
+ @inject(ConfigurationService) configurationService: ConfigurationService;
106
+ @inject(ContentsManager) contentsManager: ContentsManager;
107
+
90
108
  fileView: FileView;
91
109
  lastAction: 'COPY' | 'CUT';
92
110
  lastActionNode: FileStatNode;
111
+ allowDownload = false;
112
+ allowUpload = false;
93
113
 
94
114
  constructor(@inject(ViewManager) viewManager: ViewManager) {
95
115
  this.viewManager = viewManager;
@@ -105,56 +125,71 @@ export class FileCommandContribution
105
125
  }
106
126
 
107
127
  registerMenus(menu: MenuRegistry) {
108
- menu.registerMenuAction(FileTreeContextMenuPath, {
128
+ menu.registerGroupMenu(FileTreeContextMenuGroups['new']);
129
+ menu.registerGroupMenu(FileTreeContextMenuGroups['operator']);
130
+ menu.registerGroupMenu(FileTreeContextMenuGroups['change']);
131
+ menu.registerGroupMenu(FileTreeContextMenuGroups['extra']);
132
+
133
+ menu.registerMenuAction(FileTreeContextMenuGroups['new'], {
109
134
  id: FileCommands.CREATE_FILE.id,
110
135
  command: FileCommands.CREATE_FILE.id,
111
136
  order: 'a',
112
137
  });
113
- menu.registerMenuAction(FileTreeContextMenuPath, {
138
+ menu.registerMenuAction(FileTreeContextMenuGroups['new'], {
114
139
  id: FileCommands.CREATE_DIR.id,
115
140
  command: FileCommands.CREATE_DIR.id,
116
141
  order: 'a',
117
142
  });
118
- menu.registerMenuAction(FileTreeContextMenuPath, {
143
+ menu.registerMenuAction(FileTreeContextMenuGroups['new'], {
119
144
  id: FileCommands.OPEN_FILE.id,
120
145
  command: FileCommands.OPEN_FILE.id,
121
146
  order: 'a',
122
147
  });
123
- menu.registerMenuAction(FileTreeContextMenuPath, {
148
+ menu.registerMenuAction(FileTreeContextMenuGroups['operator'], {
124
149
  id: FileCommands.COPY.id,
125
150
  command: FileCommands.COPY.id,
126
151
  order: 'b',
127
152
  });
128
- menu.registerMenuAction(FileTreeContextMenuPath, {
153
+ menu.registerMenuAction(FileTreeContextMenuGroups['operator'], {
129
154
  id: FileCommands.PASTE.id,
130
155
  command: FileCommands.PASTE.id,
131
156
  order: 'c',
132
157
  });
133
- menu.registerMenuAction(FileTreeContextMenuPath, {
158
+ menu.registerMenuAction(FileTreeContextMenuGroups['operator'], {
134
159
  id: FileCommands.CUT.id,
135
160
  command: FileCommands.CUT.id,
136
161
  order: 'd',
137
162
  });
138
- menu.registerMenuAction(FileTreeContextMenuPath, {
163
+ menu.registerMenuAction(FileTreeContextMenuGroups['change'], {
139
164
  command: FileCommands.REMOVE.id,
140
165
  order: 'd',
141
166
  ...FileCommands.REMOVE,
142
167
  });
143
- menu.registerMenuAction(FileTreeContextMenuPath, {
168
+ menu.registerMenuAction(FileTreeContextMenuGroups['change'], {
144
169
  id: FileCommands.RENAME.id,
145
170
  command: FileCommands.RENAME.id,
146
171
  order: 'e',
147
172
  });
148
- menu.registerMenuAction(FileTreeContextMenuPath, {
173
+ menu.registerMenuAction(FileTreeContextMenuGroups['extra'], {
149
174
  id: FileCommands.COPY_PATH.id,
150
175
  command: FileCommands.COPY_PATH.id,
151
- order: 'g',
176
+ order: 'f',
152
177
  });
153
- menu.registerMenuAction(FileTreeContextMenuPath, {
178
+ menu.registerMenuAction(FileTreeContextMenuGroups['extra'], {
154
179
  id: FileCommands.COPY_RELATIVE_PATH.id,
155
180
  command: FileCommands.COPY_RELATIVE_PATH.id,
156
181
  order: 'g',
157
182
  });
183
+ menu.registerMenuAction(FileTreeContextMenuGroups['extra'], {
184
+ id: FileCommands.DOWNLOAD.id,
185
+ command: FileCommands.DOWNLOAD.id,
186
+ order: 'h',
187
+ });
188
+ menu.registerMenuAction(FileTreeContextMenuGroups['extra'], {
189
+ id: FileCommands.UPLOAD.id,
190
+ command: FileCommands.UPLOAD.id,
191
+ order: 'i',
192
+ });
158
193
  }
159
194
  registerCommands(command: CommandRegistry): void {
160
195
  command.registerCommand(FileCommands.OPEN_FILE, {
@@ -321,6 +356,65 @@ export class FileCommandContribution
321
356
  return view instanceof FileView;
322
357
  },
323
358
  });
359
+
360
+ command.registerCommand(FileCommands.DOWNLOAD, {
361
+ execute: (data) => {
362
+ if (!FileStatNode.is(data)) {
363
+ return;
364
+ }
365
+ const path = data.uri.path.toString();
366
+ this.contentsManager
367
+ .getDownloadUrl(path)
368
+ .then((url) => {
369
+ const urlObj = new URL(url);
370
+ if (urlObj.origin !== location.origin) {
371
+ // not same origin
372
+ return;
373
+ }
374
+ const element = document.createElement('a');
375
+ element.href = url;
376
+ element.download = '';
377
+ element.target = '_blank';
378
+ document.body.appendChild(element);
379
+ element.click();
380
+ document.body.removeChild(element);
381
+ return;
382
+ })
383
+ .catch(console.error);
384
+ },
385
+ isVisible: (data) => {
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;
416
+ },
417
+ });
324
418
  }
325
419
 
326
420
  registerToolbarItems(toolbarRegistry: ToolbarRegistry): void {
@@ -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() {
@@ -57,3 +57,5 @@ export const ServerLaunchManager = Symbol('ServerLaunchManager');
57
57
  export interface ServerLaunchManager {
58
58
  launch: () => Promise<any>;
59
59
  }
60
+
61
+ export const libroArgsMimetype = 'application/vnd.libro.args+json';