Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@jupyterlab/filebrowser

Package Overview
Dependencies
Maintainers
9
Versions
396
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@jupyterlab/filebrowser - npm Package Compare versions

Comparing version 0.16.3 to 0.17.0-0

2

lib/browser.d.ts

@@ -97,3 +97,3 @@ import { Toolbar } from '@jupyterlab/apputils';

*/
private _onConnectionFailure(sender, args);
private _onConnectionFailure;
private _crumbs;

@@ -100,0 +100,0 @@ private _listing;

"use strict";
// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.
var __extends = (this && this.__extends) || (function () {
var extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
var apputils_1 = require("@jupyterlab/apputils");
var services_1 = require("@jupyterlab/services");
var widgets_1 = require("@phosphor/widgets");
var crumbs_1 = require("./crumbs");
var listing_1 = require("./listing");
var upload_1 = require("./upload");
const apputils_1 = require("@jupyterlab/apputils");
const services_1 = require("@jupyterlab/services");
const widgets_1 = require("@phosphor/widgets");
const crumbs_1 = require("./crumbs");
const listing_1 = require("./listing");
const upload_1 = require("./upload");
/**
* The class name added to file browsers.
*/
var FILE_BROWSER_CLASS = 'jp-FileBrowser';
const FILE_BROWSER_CLASS = 'jp-FileBrowser';
/**
* The class name added to the filebrowser crumbs node.
*/
var CRUMBS_CLASS = 'jp-FileBrowser-crumbs';
const CRUMBS_CLASS = 'jp-FileBrowser-crumbs';
/**
* The class name added to the filebrowser toolbar node.
*/
var TOOLBAR_CLASS = 'jp-FileBrowser-toolbar';
const TOOLBAR_CLASS = 'jp-FileBrowser-toolbar';
/**
* The class name added to the filebrowser listing node.
*/
var LISTING_CLASS = 'jp-FileBrowser-listing';
const LISTING_CLASS = 'jp-FileBrowser-listing';
/**
* The class name added to the refresh button.
*/
var REFRESH_BUTTON = 'jp-RefreshIcon';
const REFRESH_BUTTON = 'jp-RefreshIcon';
/**
* The class name added to a material icon button.
*/
var MATERIAL_CLASS = 'jp-MaterialIcon';
const MATERIAL_CLASS = 'jp-MaterialIcon';
/**

@@ -52,4 +42,3 @@ * A widget which hosts a file browser.

*/
var FileBrowser = /** @class */ (function (_super) {
__extends(FileBrowser, _super);
class FileBrowser extends widgets_1.Widget {
/**

@@ -60,17 +49,17 @@ * Construct a new file browser.

*/
function FileBrowser(options) {
var _this = _super.call(this) || this;
_this._showingError = false;
_this.addClass(FILE_BROWSER_CLASS);
_this.id = options.id;
var model = _this.model = options.model;
var renderer = options.renderer;
model.connectionFailure.connect(_this._onConnectionFailure, _this);
_this._manager = model.manager;
_this._crumbs = new crumbs_1.BreadCrumbs({ model: model });
_this.toolbar = new apputils_1.Toolbar();
var directoryPending = false;
var newFolder = new apputils_1.ToolbarButton({
constructor(options) {
super();
this._showingError = false;
this.addClass(FILE_BROWSER_CLASS);
this.id = options.id;
const model = this.model = options.model;
const renderer = options.renderer;
model.connectionFailure.connect(this._onConnectionFailure, this);
this._manager = model.manager;
this._crumbs = new crumbs_1.BreadCrumbs({ model });
this.toolbar = new apputils_1.Toolbar();
let directoryPending = false;
let newFolder = new apputils_1.ToolbarButton({
className: 'jp-newFolderIcon',
onClick: function () {
onClick: () => {
if (directoryPending === true) {

@@ -80,9 +69,9 @@ return;

directoryPending = true;
_this._manager.newUntitled({
this._manager.newUntitled({
path: model.path,
type: 'directory'
}).then(function (model) {
_this._listing.selectItemByName(model.name);
}).then(model => {
this._listing.selectItemByName(model.name);
directoryPending = false;
}).catch(function (err) {
}).catch(err => {
directoryPending = false;

@@ -94,6 +83,6 @@ });

newFolder.addClass(MATERIAL_CLASS);
var uploader = new upload_1.Uploader({ model: model });
var refresher = new apputils_1.ToolbarButton({
let uploader = new upload_1.Uploader({ model });
let refresher = new apputils_1.ToolbarButton({
className: REFRESH_BUTTON,
onClick: function () {
onClick: () => {
model.refresh();

@@ -104,16 +93,15 @@ },

refresher.addClass(MATERIAL_CLASS);
_this.toolbar.addItem('newFolder', newFolder);
_this.toolbar.addItem('upload', uploader);
_this.toolbar.addItem('refresher', refresher);
_this._listing = new listing_1.DirListing({ model: model, renderer: renderer });
_this._crumbs.addClass(CRUMBS_CLASS);
_this.toolbar.addClass(TOOLBAR_CLASS);
_this._listing.addClass(LISTING_CLASS);
var layout = new widgets_1.PanelLayout();
layout.addWidget(_this.toolbar);
layout.addWidget(_this._crumbs);
layout.addWidget(_this._listing);
_this.layout = layout;
model.restore(_this.id);
return _this;
this.toolbar.addItem('newFolder', newFolder);
this.toolbar.addItem('upload', uploader);
this.toolbar.addItem('refresher', refresher);
this._listing = new listing_1.DirListing({ model, renderer });
this._crumbs.addClass(CRUMBS_CLASS);
this.toolbar.addClass(TOOLBAR_CLASS);
this._listing.addClass(LISTING_CLASS);
let layout = new widgets_1.PanelLayout();
layout.addWidget(this.toolbar);
layout.addWidget(this._crumbs);
layout.addWidget(this._listing);
this.layout = layout;
model.restore(this.id);
}

@@ -125,5 +113,5 @@ /**

*/
FileBrowser.prototype.selectedItems = function () {
selectedItems() {
return this._listing.selectedItems();
};
}
/**

@@ -134,17 +122,17 @@ * Rename the first currently selected item.

*/
FileBrowser.prototype.rename = function () {
rename() {
return this._listing.rename();
};
}
/**
* Cut the selected items.
*/
FileBrowser.prototype.cut = function () {
cut() {
this._listing.cut();
};
}
/**
* Copy the selected items.
*/
FileBrowser.prototype.copy = function () {
copy() {
this._listing.copy();
};
}
/**

@@ -155,5 +143,5 @@ * Paste the items from the clipboard.

*/
FileBrowser.prototype.paste = function () {
paste() {
return this._listing.paste();
};
}
/**

@@ -164,5 +152,5 @@ * Delete the currently selected item(s).

*/
FileBrowser.prototype.delete = function () {
delete() {
return this._listing.delete();
};
}
/**

@@ -173,11 +161,11 @@ * Duplicate the currently selected item(s).

*/
FileBrowser.prototype.duplicate = function () {
duplicate() {
return this._listing.duplicate();
};
}
/**
* Download the currently selected item(s).
*/
FileBrowser.prototype.download = function () {
download() {
this._listing.download();
};
}
/**

@@ -188,17 +176,17 @@ * Shut down kernels on the applicable currently selected items.

*/
FileBrowser.prototype.shutdownKernels = function () {
shutdownKernels() {
return this._listing.shutdownKernels();
};
}
/**
* Select next item.
*/
FileBrowser.prototype.selectNext = function () {
selectNext() {
this._listing.selectNext();
};
}
/**
* Select previous item.
*/
FileBrowser.prototype.selectPrevious = function () {
selectPrevious() {
this._listing.selectPrevious();
};
}
/**

@@ -211,10 +199,9 @@ * Find a model given a click.

*/
FileBrowser.prototype.modelForClick = function (event) {
modelForClick(event) {
return this._listing.modelForClick(event);
};
}
/**
* Handle a connection lost signal from the model.
*/
FileBrowser.prototype._onConnectionFailure = function (sender, args) {
var _this = this;
_onConnectionFailure(sender, args) {
if (this._showingError) {

@@ -224,4 +211,4 @@ return;

this._showingError = true;
var title = 'Server Connection Error';
var networkMsg = ('A connection to the Jupyter server could not be established.\n' +
let title = 'Server Connection Error';
let networkMsg = ('A connection to the Jupyter server could not be established.\n' +
'JupyterLab will continue trying to reconnect.\n' +

@@ -236,11 +223,10 @@ 'Check your network connection or Jupyter server configuration.\n');

title = 'Directory not found';
args.message = "Directory not found: \"" + this.model.path + "\"";
args.message = `Directory not found: "${this.model.path}"`;
}
}
apputils_1.showErrorMessage(title, args).then(function () {
_this._showingError = false;
apputils_1.showErrorMessage(title, args).then(() => {
this._showingError = false;
});
};
return FileBrowser;
}(widgets_1.Widget));
}
}
exports.FileBrowser = FileBrowser;

@@ -40,19 +40,19 @@ import { Message } from '@phosphor/messaging';

*/
private _evtClick(event);
private _evtClick;
/**
* Handle the `'p-dragenter'` event for the widget.
*/
private _evtDragEnter(event);
private _evtDragEnter;
/**
* Handle the `'p-dragleave'` event for the widget.
*/
private _evtDragLeave(event);
private _evtDragLeave;
/**
* Handle the `'p-dragover'` event for the widget.
*/
private _evtDragOver(event);
private _evtDragOver;
/**
* Handle the `'p-drop'` event for the widget.
*/
private _evtDrop(event);
private _evtDrop;
private _model;

@@ -59,0 +59,0 @@ private _crumbs;

"use strict";
// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.
var __extends = (this && this.__extends) || (function () {
var extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
var algorithm_1 = require("@phosphor/algorithm");
var domutils_1 = require("@phosphor/domutils");
var widgets_1 = require("@phosphor/widgets");
var apputils_1 = require("@jupyterlab/apputils");
var coreutils_1 = require("@jupyterlab/coreutils");
var docmanager_1 = require("@jupyterlab/docmanager");
const algorithm_1 = require("@phosphor/algorithm");
const domutils_1 = require("@phosphor/domutils");
const widgets_1 = require("@phosphor/widgets");
const apputils_1 = require("@jupyterlab/apputils");
const coreutils_1 = require("@jupyterlab/coreutils");
const docmanager_1 = require("@jupyterlab/docmanager");
/**
* The class name added to material icons
*/
var MATERIAL_CLASS = 'jp-MaterialIcon';
const MATERIAL_CLASS = 'jp-MaterialIcon';
/**
* The class name added to the breadcrumb node.
*/
var BREADCRUMB_CLASS = 'jp-BreadCrumbs';
const BREADCRUMB_CLASS = 'jp-BreadCrumbs';
/**
* The class name added to add the home icon for the breadcrumbs
*/
var BREADCRUMB_HOME = 'jp-HomeIcon';
const BREADCRUMB_HOME = 'jp-HomeIcon';
/**
* The class named associated to the ellipses icon
*/
var BREADCRUMB_ELLIPSES = 'jp-EllipsesIcon';
const BREADCRUMB_ELLIPSES = 'jp-EllipsesIcon';
/**
* The class name added to the breadcrumb node.
*/
var BREADCRUMB_ITEM_CLASS = 'jp-BreadCrumbs-item';
const BREADCRUMB_ITEM_CLASS = 'jp-BreadCrumbs-item';
/**
* Bread crumb paths.
*/
var BREAD_CRUMB_PATHS = ['/', '../../', '../', ''];
const BREAD_CRUMB_PATHS = ['/', '../../', '../', ''];
/**
* The mime type for a contents drag object.
*/
var CONTENTS_MIME = 'application/x-jupyter-icontents';
const CONTENTS_MIME = 'application/x-jupyter-icontents';
/**
* The class name added to drop targets.
*/
var DROP_TARGET_CLASS = 'jp-mod-dropTarget';
const DROP_TARGET_CLASS = 'jp-mod-dropTarget';
/**
* A class which hosts folder breadcrumbs.
*/
var BreadCrumbs = /** @class */ (function (_super) {
__extends(BreadCrumbs, _super);
class BreadCrumbs extends widgets_1.Widget {
/**

@@ -63,11 +52,10 @@ * Construct a new file browser crumb widget.

*/
function BreadCrumbs(options) {
var _this = _super.call(this) || this;
_this._model = options.model;
_this.addClass(BREADCRUMB_CLASS);
_this._crumbs = Private.createCrumbs();
_this._crumbSeps = Private.createCrumbSeparators();
_this.node.appendChild(_this._crumbs[Private.Crumb.Home]);
_this._model.refreshed.connect(_this.update, _this);
return _this;
constructor(options) {
super();
this._model = options.model;
this.addClass(BREADCRUMB_CLASS);
this._crumbs = Private.createCrumbs();
this._crumbSeps = Private.createCrumbSeparators();
this.node.appendChild(this._crumbs[Private.Crumb.Home]);
this._model.refreshed.connect(this.update, this);
}

@@ -84,3 +72,3 @@ /**

*/
BreadCrumbs.prototype.handleEvent = function (event) {
handleEvent(event) {
switch (event.type) {

@@ -105,10 +93,10 @@ case 'click':

}
};
}
/**
* A message handler invoked on an `'after-attach'` message.
*/
BreadCrumbs.prototype.onAfterAttach = function (msg) {
_super.prototype.onAfterAttach.call(this, msg);
onAfterAttach(msg) {
super.onAfterAttach(msg);
this.update();
var node = this.node;
let node = this.node;
node.addEventListener('click', this);

@@ -119,9 +107,9 @@ node.addEventListener('p-dragenter', this);

node.addEventListener('p-drop', this);
};
}
/**
* A message handler invoked on a `'before-detach'` message.
*/
BreadCrumbs.prototype.onBeforeDetach = function (msg) {
_super.prototype.onBeforeDetach.call(this, msg);
var node = this.node;
onBeforeDetach(msg) {
super.onBeforeDetach(msg);
let node = this.node;
node.removeEventListener('click', this);

@@ -132,16 +120,16 @@ node.removeEventListener('p-dragenter', this);

node.removeEventListener('p-drop', this);
};
}
/**
* A handler invoked on an `'update-request'` message.
*/
BreadCrumbs.prototype.onUpdateRequest = function (msg) {
onUpdateRequest(msg) {
// Update the breadcrumb list.
var contents = this._model.manager.services.contents;
var localPath = contents.localPath(this._model.path);
const contents = this._model.manager.services.contents;
const localPath = contents.localPath(this._model.path);
Private.updateCrumbs(this._crumbs, this._crumbSeps, localPath);
};
}
/**
* Handle the `'click'` event for the widget.
*/
BreadCrumbs.prototype._evtClick = function (event) {
_evtClick(event) {
// Do nothing if it's not a left mouse press.

@@ -152,9 +140,7 @@ if (event.button !== 0) {

// Find a valid click target.
var node = event.target;
let node = event.target;
while (node && node !== this.node) {
if (node.classList.contains(BREADCRUMB_ITEM_CLASS)) {
var index = algorithm_1.ArrayExt.findFirstIndex(this._crumbs, function (value) { return value === node; });
this._model.cd(BREAD_CRUMB_PATHS[index]).catch(function (error) {
return apputils_1.showErrorMessage('Open Error', error);
});
let index = algorithm_1.ArrayExt.findFirstIndex(this._crumbs, value => value === node);
this._model.cd(BREAD_CRUMB_PATHS[index]).catch(error => apputils_1.showErrorMessage('Open Error', error));
// Stop the event propagation.

@@ -167,9 +153,9 @@ event.preventDefault();

}
};
}
/**
* Handle the `'p-dragenter'` event for the widget.
*/
BreadCrumbs.prototype._evtDragEnter = function (event) {
_evtDragEnter(event) {
if (event.mimeData.hasData(CONTENTS_MIME)) {
var index = algorithm_1.ArrayExt.findFirstIndex(this._crumbs, function (node) { return domutils_1.ElementExt.hitTest(node, event.clientX, event.clientY); });
let index = algorithm_1.ArrayExt.findFirstIndex(this._crumbs, node => domutils_1.ElementExt.hitTest(node, event.clientX, event.clientY));
if (index !== -1) {

@@ -183,34 +169,34 @@ if (index !== Private.Crumb.Current) {

}
};
}
/**
* Handle the `'p-dragleave'` event for the widget.
*/
BreadCrumbs.prototype._evtDragLeave = function (event) {
_evtDragLeave(event) {
event.preventDefault();
event.stopPropagation();
var dropTarget = apputils_1.DOMUtils.findElement(this.node, DROP_TARGET_CLASS);
let dropTarget = apputils_1.DOMUtils.findElement(this.node, DROP_TARGET_CLASS);
if (dropTarget) {
dropTarget.classList.remove(DROP_TARGET_CLASS);
}
};
}
/**
* Handle the `'p-dragover'` event for the widget.
*/
BreadCrumbs.prototype._evtDragOver = function (event) {
_evtDragOver(event) {
event.preventDefault();
event.stopPropagation();
event.dropAction = event.proposedAction;
var dropTarget = apputils_1.DOMUtils.findElement(this.node, DROP_TARGET_CLASS);
let dropTarget = apputils_1.DOMUtils.findElement(this.node, DROP_TARGET_CLASS);
if (dropTarget) {
dropTarget.classList.remove(DROP_TARGET_CLASS);
}
var index = algorithm_1.ArrayExt.findFirstIndex(this._crumbs, function (node) { return domutils_1.ElementExt.hitTest(node, event.clientX, event.clientY); });
let index = algorithm_1.ArrayExt.findFirstIndex(this._crumbs, node => domutils_1.ElementExt.hitTest(node, event.clientX, event.clientY));
if (index !== -1) {
this._crumbs[index].classList.add(DROP_TARGET_CLASS);
}
};
}
/**
* Handle the `'p-drop'` event for the widget.
*/
BreadCrumbs.prototype._evtDrop = function (event) {
_evtDrop(event) {
event.preventDefault();

@@ -226,3 +212,3 @@ event.stopPropagation();

event.dropAction = event.proposedAction;
var target = event.target;
let target = event.target;
while (target && target.parentElement) {

@@ -236,25 +222,23 @@ if (target.classList.contains(DROP_TARGET_CLASS)) {

// Get the path based on the target node.
var index = algorithm_1.ArrayExt.findFirstIndex(this._crumbs, function (node) { return node === target; });
let index = algorithm_1.ArrayExt.findFirstIndex(this._crumbs, node => node === target);
if (index === -1) {
return;
}
var model = this._model;
var path = coreutils_1.PathExt.resolve(model.path, BREAD_CRUMB_PATHS[index]);
var manager = model.manager;
const model = this._model;
const path = coreutils_1.PathExt.resolve(model.path, BREAD_CRUMB_PATHS[index]);
const manager = model.manager;
// Move all of the items.
var promises = [];
var oldPaths = event.mimeData.getData(CONTENTS_MIME);
for (var _i = 0, oldPaths_1 = oldPaths; _i < oldPaths_1.length; _i++) {
var oldPath = oldPaths_1[_i];
var localOldPath = manager.services.contents.localPath(oldPath);
var name_1 = coreutils_1.PathExt.basename(localOldPath);
var newPath = coreutils_1.PathExt.join(path, name_1);
let promises = [];
let oldPaths = event.mimeData.getData(CONTENTS_MIME);
for (let oldPath of oldPaths) {
let localOldPath = manager.services.contents.localPath(oldPath);
let name = coreutils_1.PathExt.basename(localOldPath);
let newPath = coreutils_1.PathExt.join(path, name);
promises.push(docmanager_1.renameFile(manager, oldPath, newPath));
}
Promise.all(promises).catch(function (err) {
Promise.all(promises).catch(err => {
apputils_1.showErrorMessage('Move Error', err);
});
};
return BreadCrumbs;
}(widgets_1.Widget));
}
}
exports.BreadCrumbs = BreadCrumbs;

@@ -269,3 +253,3 @@ /**

*/
var Crumb;
let Crumb;
(function (Crumb) {

@@ -281,13 +265,13 @@ Crumb[Crumb["Home"] = 0] = "Home";

function updateCrumbs(breadcrumbs, separators, path) {
var node = breadcrumbs[0].parentNode;
let node = breadcrumbs[0].parentNode;
// Remove all but the home node.
var firstChild = node.firstChild;
let firstChild = node.firstChild;
while (firstChild && firstChild.nextSibling) {
node.removeChild(firstChild.nextSibling);
}
var parts = path.split('/');
let parts = path.split('/');
if (parts.length > 2) {
node.appendChild(separators[0]);
node.appendChild(breadcrumbs[Crumb.Ellipsis]);
var grandParent = parts.slice(0, parts.length - 2).join('/');
let grandParent = parts.slice(0, parts.length - 2).join('/');
breadcrumbs[Crumb.Ellipsis].title = grandParent;

@@ -300,4 +284,4 @@ }

node.appendChild(breadcrumbs[Crumb.Parent]);
var parent_1 = parts.slice(0, parts.length - 1).join('/');
breadcrumbs[Crumb.Parent].title = parent_1;
let parent = parts.slice(0, parts.length - 1).join('/');
breadcrumbs[Crumb.Parent].title = parent;
}

@@ -315,10 +299,10 @@ node.appendChild(separators[2]);

function createCrumbs() {
var home = document.createElement('span');
let home = document.createElement('span');
home.className = MATERIAL_CLASS + ' ' + BREADCRUMB_HOME + ' ' + BREADCRUMB_ITEM_CLASS;
home.title = 'Home';
var ellipsis = document.createElement('span');
let ellipsis = document.createElement('span');
ellipsis.className = MATERIAL_CLASS + ' ' + BREADCRUMB_ELLIPSES + ' ' + BREADCRUMB_ITEM_CLASS;
var parent = document.createElement('span');
let parent = document.createElement('span');
parent.className = BREADCRUMB_ITEM_CLASS;
var current = document.createElement('span');
let current = document.createElement('span');
current.className = BREADCRUMB_ITEM_CLASS;

@@ -332,5 +316,5 @@ return [home, ellipsis, parent, current];

function createCrumbSeparators() {
var items = [];
for (var i = 0; i < 3; i++) {
var item = document.createElement('i');
let items = [];
for (let i = 0; i < 3; i++) {
let item = document.createElement('i');
item.className = 'fa fa-angle-right';

@@ -337,0 +321,0 @@ items.push(item);

@@ -5,3 +5,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
var coreutils_1 = require("@phosphor/coreutils");
const coreutils_1 = require("@phosphor/coreutils");
/* tslint:disable */

@@ -8,0 +8,0 @@ /**

@@ -179,91 +179,91 @@ import { DocumentRegistry } from '@jupyterlab/docregistry';

*/
private _evtClick(event);
private _evtClick;
/**
* Handle the `'scroll'` event for the widget.
*/
private _evtScroll(event);
private _evtScroll;
/**
* Handle the `'mousedown'` event for the widget.
*/
private _evtMousedown(event);
private _evtMousedown;
/**
* Handle the `'mouseup'` event for the widget.
*/
private _evtMouseup(event);
private _evtMouseup;
/**
* Handle the `'mousemove'` event for the widget.
*/
private _evtMousemove(event);
private _evtMousemove;
/**
* Handle the `'keydown'` event for the widget.
*/
private _evtKeydown(event);
private _evtKeydown;
/**
* Handle the `'dblclick'` event for the widget.
*/
private _evtDblClick(event);
private _evtDblClick;
/**
* Handle the `drop` event for the widget.
*/
private _evtNativeDrop(event);
private _evtNativeDrop;
/**
* Handle the `'p-dragenter'` event for the widget.
*/
private _evtDragEnter(event);
private _evtDragEnter;
/**
* Handle the `'p-dragleave'` event for the widget.
*/
private _evtDragLeave(event);
private _evtDragLeave;
/**
* Handle the `'p-dragover'` event for the widget.
*/
private _evtDragOver(event);
private _evtDragOver;
/**
* Handle the `'p-drop'` event for the widget.
*/
private _evtDrop(event);
private _evtDrop;
/**
* Start a drag event.
*/
private _startDrag(index, clientX, clientY);
private _startDrag;
/**
* Handle selection on a file node.
*/
private _handleFileSelect(event);
private _handleFileSelect;
/**
* Handle a multiple select on a file item node.
*/
private _handleMultiSelect(selected, index);
private _handleMultiSelect;
/**
* Copy the selected items, and optionally cut as well.
*/
private _copy();
private _copy;
/**
* Delete the files with the given names.
*/
private _delete(names);
private _delete;
/**
* Allow the user to rename item on a given row.
*/
private _doRename();
private _doRename;
/**
* Select a given item.
*/
private _selectItem(index, keepExisting);
private _selectItem;
/**
* Handle the `refreshed` signal from the model.
*/
private _onModelRefreshed();
private _onModelRefreshed;
/**
* Handle a `pathChanged` signal from the model.
*/
private _onPathChanged();
private _onPathChanged;
/**
* Handle a `fileChanged` signal from the model.
*/
private _onFileChanged(sender, args);
private _onFileChanged;
/**
* Handle an `activateRequested` signal from the manager.
*/
private _onActivateRequested(sender, args);
private _onActivateRequested;
private _model;

@@ -447,3 +447,3 @@ private _editNode;

*/
private _createHeaderItemNode(label);
private _createHeaderItemNode;
}

@@ -450,0 +450,0 @@ /**

"use strict";
// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.
var __extends = (this && this.__extends) || (function () {
var extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
var apputils_1 = require("@jupyterlab/apputils");
var coreutils_1 = require("@jupyterlab/coreutils");
var docmanager_1 = require("@jupyterlab/docmanager");
var algorithm_1 = require("@phosphor/algorithm");
var coreutils_2 = require("@phosphor/coreutils");
var dragdrop_1 = require("@phosphor/dragdrop");
var domutils_1 = require("@phosphor/domutils");
var messaging_1 = require("@phosphor/messaging");
var widgets_1 = require("@phosphor/widgets");
const apputils_1 = require("@jupyterlab/apputils");
const coreutils_1 = require("@jupyterlab/coreutils");
const docmanager_1 = require("@jupyterlab/docmanager");
const algorithm_1 = require("@phosphor/algorithm");
const coreutils_2 = require("@phosphor/coreutils");
const dragdrop_1 = require("@phosphor/dragdrop");
const domutils_1 = require("@phosphor/domutils");
const messaging_1 = require("@phosphor/messaging");
const widgets_1 = require("@phosphor/widgets");
/**
* The class name added to DirListing widget.
*/
var DIR_LISTING_CLASS = 'jp-DirListing';
const DIR_LISTING_CLASS = 'jp-DirListing';
/**
* The class name added to a dir listing header node.
*/
var HEADER_CLASS = 'jp-DirListing-header';
const HEADER_CLASS = 'jp-DirListing-header';
/**
* The class name added to a dir listing list header cell.
*/
var HEADER_ITEM_CLASS = 'jp-DirListing-headerItem';
const HEADER_ITEM_CLASS = 'jp-DirListing-headerItem';
/**
* The class name added to a header cell text node.
*/
var HEADER_ITEM_TEXT_CLASS = 'jp-DirListing-headerItemText';
const HEADER_ITEM_TEXT_CLASS = 'jp-DirListing-headerItemText';
/**
* The class name added to a header cell icon node.
*/
var HEADER_ITEM_ICON_CLASS = 'jp-DirListing-headerItemIcon';
const HEADER_ITEM_ICON_CLASS = 'jp-DirListing-headerItemIcon';
/**
* The class name added to the dir listing content node.
*/
var CONTENT_CLASS = 'jp-DirListing-content';
const CONTENT_CLASS = 'jp-DirListing-content';
/**
* The class name added to dir listing content item.
*/
var ITEM_CLASS = 'jp-DirListing-item';
const ITEM_CLASS = 'jp-DirListing-item';
/**
* The class name added to the listing item text cell.
*/
var ITEM_TEXT_CLASS = 'jp-DirListing-itemText';
const ITEM_TEXT_CLASS = 'jp-DirListing-itemText';
/**
* The class name added to the listing item icon cell.
*/
var ITEM_ICON_CLASS = 'jp-DirListing-itemIcon';
const ITEM_ICON_CLASS = 'jp-DirListing-itemIcon';
/**
* The class name added to the listing item modified cell.
*/
var ITEM_MODIFIED_CLASS = 'jp-DirListing-itemModified';
const ITEM_MODIFIED_CLASS = 'jp-DirListing-itemModified';
/**
* The class name added to the dir listing editor node.
*/
var EDITOR_CLASS = 'jp-DirListing-editor';
const EDITOR_CLASS = 'jp-DirListing-editor';
/**
* The class name added to the name column header cell.
*/
var NAME_ID_CLASS = 'jp-id-name';
const NAME_ID_CLASS = 'jp-id-name';
/**
* The class name added to the modified column header cell.
*/
var MODIFIED_ID_CLASS = 'jp-id-modified';
const MODIFIED_ID_CLASS = 'jp-id-modified';
/**
* The mime type for a con tents drag object.
*/
var CONTENTS_MIME = 'application/x-jupyter-icontents';
const CONTENTS_MIME = 'application/x-jupyter-icontents';
/**
* The class name added to drop targets.
*/
var DROP_TARGET_CLASS = 'jp-mod-dropTarget';
const DROP_TARGET_CLASS = 'jp-mod-dropTarget';
/**
* The class name added to selected rows.
*/
var SELECTED_CLASS = 'jp-mod-selected';
const SELECTED_CLASS = 'jp-mod-selected';
/**
* The class name added to drag state icons to add space between the icon and the file name
*/
var DRAG_ICON_CLASS = 'jp-DragIcon';
const DRAG_ICON_CLASS = 'jp-DragIcon';
/**
* The class name added to the widget when there are items on the clipboard.
*/
var CLIPBOARD_CLASS = 'jp-mod-clipboard';
const CLIPBOARD_CLASS = 'jp-mod-clipboard';
/**
* The class name added to cut rows.
*/
var CUT_CLASS = 'jp-mod-cut';
const CUT_CLASS = 'jp-mod-cut';
/**
* The class name added when there are more than one selected rows.
*/
var MULTI_SELECTED_CLASS = 'jp-mod-multiSelected';
const MULTI_SELECTED_CLASS = 'jp-mod-multiSelected';
/**
* The class name added to indicate running notebook.
*/
var RUNNING_CLASS = 'jp-mod-running';
const RUNNING_CLASS = 'jp-mod-running';
/**
* The class name added for a decending sort.
*/
var DESCENDING_CLASS = 'jp-mod-descending';
const DESCENDING_CLASS = 'jp-mod-descending';
/**
* The minimum duration for a rename select in ms.
*/
var RENAME_DURATION = 1000;
const RENAME_DURATION = 1000;
/**
* The maximum duration between two key presses when selecting files by prefix.
*/
var PREFIX_APPEND_DURATION = 1000;
const PREFIX_APPEND_DURATION = 1000;
/**
* The threshold in pixels to start a drag event.
*/
var DRAG_THRESHOLD = 5;
const DRAG_THRESHOLD = 5;
/**
* A boolean indicating whether the platform is Mac.
*/
var IS_MAC = !!navigator.platform.match(/Mac/i);
const IS_MAC = !!navigator.platform.match(/Mac/i);
/**
* The factory MIME type supported by phosphor dock panels.
*/
var FACTORY_MIME = 'application/vnd.phosphor.widget-factory';
const FACTORY_MIME = 'application/vnd.phosphor.widget-factory';
/**
* A widget which hosts a file list area.
*/
var DirListing = /** @class */ (function (_super) {
__extends(DirListing, _super);
class DirListing extends widgets_1.Widget {
/**

@@ -142,35 +131,34 @@ * Construct a new file browser directory listing widget.

*/
function DirListing(options) {
var _this = _super.call(this, {
constructor(options) {
super({
node: (options.renderer || DirListing.defaultRenderer).createNode()
}) || this;
_this._items = [];
_this._sortedItems = [];
_this._sortState = { direction: 'ascending', key: 'name' };
_this._drag = null;
_this._dragData = null;
_this._selectTimer = -1;
_this._noSelectTimer = -1;
_this._isCut = false;
_this._prevPath = '';
_this._clipboard = [];
_this._softSelection = '';
_this._selection = Object.create(null);
_this._searchPrefix = '';
_this._searchPrefixTimer = -1;
_this._inRename = false;
_this._isDirty = false;
_this.addClass(DIR_LISTING_CLASS);
_this._model = options.model;
_this._model.fileChanged.connect(_this._onFileChanged, _this);
_this._model.refreshed.connect(_this._onModelRefreshed, _this);
_this._model.pathChanged.connect(_this._onPathChanged, _this);
_this._editNode = document.createElement('input');
_this._editNode.className = EDITOR_CLASS;
_this._manager = _this._model.manager;
_this._renderer = options.renderer || DirListing.defaultRenderer;
var headerNode = apputils_1.DOMUtils.findElement(_this.node, HEADER_CLASS);
_this._renderer.populateHeaderNode(headerNode);
_this._manager.activateRequested.connect(_this._onActivateRequested, _this);
return _this;
});
this._items = [];
this._sortedItems = [];
this._sortState = { direction: 'ascending', key: 'name' };
this._drag = null;
this._dragData = null;
this._selectTimer = -1;
this._noSelectTimer = -1;
this._isCut = false;
this._prevPath = '';
this._clipboard = [];
this._softSelection = '';
this._selection = Object.create(null);
this._searchPrefix = '';
this._searchPrefixTimer = -1;
this._inRename = false;
this._isDirty = false;
this.addClass(DIR_LISTING_CLASS);
this._model = options.model;
this._model.fileChanged.connect(this._onFileChanged, this);
this._model.refreshed.connect(this._onModelRefreshed, this);
this._model.pathChanged.connect(this._onPathChanged, this);
this._editNode = document.createElement('input');
this._editNode.className = EDITOR_CLASS;
this._manager = this._model.manager;
this._renderer = options.renderer || DirListing.defaultRenderer;
const headerNode = apputils_1.DOMUtils.findElement(this.node, HEADER_CLASS);
this._renderer.populateHeaderNode(headerNode);
this._manager.activateRequested.connect(this._onActivateRequested, this);
}

@@ -180,69 +168,49 @@ /**

*/
DirListing.prototype.dispose = function () {
dispose() {
this._items.length = 0;
this._sortedItems.length = 0;
this._clipboard.length = 0;
_super.prototype.dispose.call(this);
};
Object.defineProperty(DirListing.prototype, "model", {
/**
* Get the model used by the listing.
*/
get: function () {
return this._model;
},
enumerable: true,
configurable: true
});
Object.defineProperty(DirListing.prototype, "headerNode", {
/**
* Get the dir listing header node.
*
* #### Notes
* This is the node which holds the header cells.
*
* Modifying this node directly can lead to undefined behavior.
*/
get: function () {
return apputils_1.DOMUtils.findElement(this.node, HEADER_CLASS);
},
enumerable: true,
configurable: true
});
Object.defineProperty(DirListing.prototype, "contentNode", {
/**
* Get the dir listing content node.
*
* #### Notes
* This is the node which holds the item nodes.
*
* Modifying this node directly can lead to undefined behavior.
*/
get: function () {
return apputils_1.DOMUtils.findElement(this.node, CONTENT_CLASS);
},
enumerable: true,
configurable: true
});
Object.defineProperty(DirListing.prototype, "renderer", {
/**
* The renderer instance used by the directory listing.
*/
get: function () {
return this._renderer;
},
enumerable: true,
configurable: true
});
Object.defineProperty(DirListing.prototype, "sortState", {
/**
* The current sort state.
*/
get: function () {
return this._sortState;
},
enumerable: true,
configurable: true
});
super.dispose();
}
/**
* Get the model used by the listing.
*/
get model() {
return this._model;
}
/**
* Get the dir listing header node.
*
* #### Notes
* This is the node which holds the header cells.
*
* Modifying this node directly can lead to undefined behavior.
*/
get headerNode() {
return apputils_1.DOMUtils.findElement(this.node, HEADER_CLASS);
}
/**
* Get the dir listing content node.
*
* #### Notes
* This is the node which holds the item nodes.
*
* Modifying this node directly can lead to undefined behavior.
*/
get contentNode() {
return apputils_1.DOMUtils.findElement(this.node, CONTENT_CLASS);
}
/**
* The renderer instance used by the directory listing.
*/
get renderer() {
return this._renderer;
}
/**
* The current sort state.
*/
get sortState() {
return this._sortState;
}
/**
* Create an iterator over the listing's selected items.

@@ -252,7 +220,6 @@ *

*/
DirListing.prototype.selectedItems = function () {
var _this = this;
var items = this._sortedItems;
return algorithm_1.filter(items, function (item) { return _this._selection[item.name]; });
};
selectedItems() {
let items = this._sortedItems;
return algorithm_1.filter(items, item => this._selection[item.name]);
}
/**

@@ -263,13 +230,13 @@ * Create an iterator over the listing's sorted items.

*/
DirListing.prototype.sortedItems = function () {
sortedItems() {
return new algorithm_1.ArrayIterator(this._sortedItems);
};
}
/**
* Sort the items using a sort condition.
*/
DirListing.prototype.sort = function (state) {
sort(state) {
this._sortedItems = Private.sort(this.model.items(), state);
this._sortState = state;
this.update();
};
}
/**

@@ -280,19 +247,19 @@ * Rename the first currently selected item.

*/
DirListing.prototype.rename = function () {
rename() {
return this._doRename();
};
}
/**
* Cut the selected items.
*/
DirListing.prototype.cut = function () {
cut() {
this._isCut = true;
this._copy();
this.update();
};
}
/**
* Copy the selected items.
*/
DirListing.prototype.copy = function () {
copy() {
this._copy();
};
}
/**

@@ -303,4 +270,3 @@ * Paste the items from the clipboard.

*/
DirListing.prototype.paste = function () {
var _this = this;
paste() {
if (!this._clipboard.length) {

@@ -310,17 +276,17 @@ this._isCut = false;

}
var basePath = this._model.path;
var promises = [];
algorithm_1.each(this._clipboard, function (path) {
if (_this._isCut) {
var parts = path.split('/');
var name_1 = parts[parts.length - 1];
var newPath = coreutils_1.PathExt.join(basePath, name_1);
promises.push(_this._model.manager.rename(path, newPath));
const basePath = this._model.path;
let promises = [];
algorithm_1.each(this._clipboard, path => {
if (this._isCut) {
const parts = path.split('/');
const name = parts[parts.length - 1];
const newPath = coreutils_1.PathExt.join(basePath, name);
promises.push(this._model.manager.rename(path, newPath));
}
else {
promises.push(_this._model.manager.copy(path, basePath));
promises.push(this._model.manager.copy(path, basePath));
}
});
// Remove any cut modifiers.
algorithm_1.each(this._items, function (item) {
algorithm_1.each(this._items, item => {
item.classList.remove(CUT_CLASS);

@@ -331,8 +297,8 @@ });

this.removeClass(CLIPBOARD_CLASS);
return Promise.all(promises).then(function () {
return Promise.all(promises).then(() => {
return undefined;
}).catch(function (error) {
}).catch(error => {
apputils_1.showErrorMessage('Paste Error', error);
});
};
}
/**

@@ -343,13 +309,12 @@ * Delete the currently selected item(s).

*/
DirListing.prototype.delete = function () {
var _this = this;
var names = [];
algorithm_1.each(this._sortedItems, function (item) {
if (_this._selection[item.name]) {
delete() {
let names = [];
algorithm_1.each(this._sortedItems, item => {
if (this._selection[item.name]) {
names.push(item.name);
}
});
var message = "Are you sure you want to permanently delete the " + names.length + " files/folders selected?";
let message = `Are you sure you want to permanently delete the ${names.length} files/folders selected?`;
if (names.length === 1) {
message = "Are you sure you want to permanently delete: " + names[0] + "?";
message = `Are you sure you want to permanently delete: ${names[0]}?`;
}

@@ -361,5 +326,5 @@ if (names.length) {

buttons: [apputils_1.Dialog.cancelButton(), apputils_1.Dialog.warnButton({ label: 'DELETE' })]
}).then(function (result) {
if (!_this.isDisposed && result.button.accept) {
return _this._delete(names);
}).then(result => {
if (!this.isDisposed && result.button.accept) {
return this._delete(names);
}

@@ -369,3 +334,3 @@ });

return Promise.resolve(void 0);
};
}
/**

@@ -376,29 +341,27 @@ * Duplicate the currently selected item(s).

*/
DirListing.prototype.duplicate = function () {
var _this = this;
var basePath = this._model.path;
var promises = [];
algorithm_1.each(this.selectedItems(), function (item) {
duplicate() {
const basePath = this._model.path;
let promises = [];
algorithm_1.each(this.selectedItems(), item => {
if (item.type !== 'directory') {
var oldPath = coreutils_1.PathExt.join(basePath, item.name);
promises.push(_this._model.manager.copy(oldPath, basePath));
let oldPath = coreutils_1.PathExt.join(basePath, item.name);
promises.push(this._model.manager.copy(oldPath, basePath));
}
});
return Promise.all(promises).then(function () {
return Promise.all(promises).then(() => {
return undefined;
}).catch(function (error) {
}).catch(error => {
apputils_1.showErrorMessage('Duplicate file', error);
});
};
}
/**
* Download the currently selected item(s).
*/
DirListing.prototype.download = function () {
var _this = this;
algorithm_1.each(this.selectedItems(), function (item) {
download() {
algorithm_1.each(this.selectedItems(), item => {
if (item.type !== 'directory') {
_this._model.download(item.path);
this._model.download(item.path);
}
});
};
}
/**

@@ -409,17 +372,16 @@ * Shut down kernels on the applicable currently selected items.

*/
DirListing.prototype.shutdownKernels = function () {
var _this = this;
var model = this._model;
var items = this._sortedItems;
var paths = items.map(function (item) { return item.path; });
var promises = algorithm_1.toArray(this._model.sessions()).filter(function (session) {
var index = algorithm_1.ArrayExt.firstIndexOf(paths, session.path);
return _this._selection[items[index].name];
}).map(function (session) { return model.manager.services.sessions.shutdown(session.id); });
return Promise.all(promises).then(function () {
shutdownKernels() {
const model = this._model;
const items = this._sortedItems;
const paths = items.map(item => item.path);
const promises = algorithm_1.toArray(this._model.sessions()).filter(session => {
let index = algorithm_1.ArrayExt.firstIndexOf(paths, session.path);
return this._selection[items[index].name];
}).map(session => model.manager.services.sessions.shutdown(session.id));
return Promise.all(promises).then(() => {
return undefined;
}).catch(function (error) {
}).catch(error => {
apputils_1.showErrorMessage('Shutdown kernel', error);
});
};
}
/**

@@ -430,11 +392,10 @@ * Select next item.

*/
DirListing.prototype.selectNext = function (keepExisting) {
if (keepExisting === void 0) { keepExisting = false; }
var index = -1;
var selected = Object.keys(this._selection);
var items = this._sortedItems;
selectNext(keepExisting = false) {
let index = -1;
let selected = Object.keys(this._selection);
let items = this._sortedItems;
if (selected.length === 1 || keepExisting) {
// Select the next item.
var name_2 = selected[selected.length - 1];
index = algorithm_1.ArrayExt.findFirstIndex(items, function (value) { return value.name === name_2; });
let name = selected[selected.length - 1];
index = algorithm_1.ArrayExt.findFirstIndex(items, value => value.name === name);
index += 1;

@@ -451,4 +412,4 @@ if (index === this._items.length) {

// Select the last selected item.
var name_3 = selected[selected.length - 1];
index = algorithm_1.ArrayExt.findFirstIndex(items, function (value) { return value.name === name_3; });
let name = selected[selected.length - 1];
index = algorithm_1.ArrayExt.findFirstIndex(items, value => value.name === name);
}

@@ -459,3 +420,3 @@ if (index !== -1) {

}
};
}
/**

@@ -466,11 +427,10 @@ * Select previous item.

*/
DirListing.prototype.selectPrevious = function (keepExisting) {
if (keepExisting === void 0) { keepExisting = false; }
var index = -1;
var selected = Object.keys(this._selection);
var items = this._sortedItems;
selectPrevious(keepExisting = false) {
let index = -1;
let selected = Object.keys(this._selection);
let items = this._sortedItems;
if (selected.length === 1 || keepExisting) {
// Select the previous item.
var name_4 = selected[0];
index = algorithm_1.ArrayExt.findFirstIndex(items, function (value) { return value.name === name_4; });
let name = selected[0];
index = algorithm_1.ArrayExt.findFirstIndex(items, value => value.name === name);
index -= 1;

@@ -487,4 +447,4 @@ if (index === -1) {

// Select the first selected item.
var name_5 = selected[0];
index = algorithm_1.ArrayExt.findFirstIndex(items, function (value) { return value.name === name_5; });
let name = selected[0];
index = algorithm_1.ArrayExt.findFirstIndex(items, value => value.name === name);
}

@@ -495,10 +455,10 @@ if (index !== -1) {

}
};
}
/**
* Select the first item that starts with prefix being typed.
*/
DirListing.prototype.selectByPrefix = function () {
var prefix = this._searchPrefix;
var items = this._sortedItems;
var index = algorithm_1.ArrayExt.findFirstIndex(items, function (value) {
selectByPrefix() {
const prefix = this._searchPrefix;
let items = this._sortedItems;
let index = algorithm_1.ArrayExt.findFirstIndex(items, value => {
return value.name.toLowerCase().substr(0, prefix.length) === prefix;

@@ -510,3 +470,3 @@ });

}
};
}
/**

@@ -519,5 +479,5 @@ * Get whether an item is selected by name.

*/
DirListing.prototype.isSelected = function (name) {
isSelected(name) {
return this._selection[name] === true;
};
}
/**

@@ -530,5 +490,5 @@ * Find a model given a click.

*/
DirListing.prototype.modelForClick = function (event) {
var items = this._sortedItems;
var index = Private.hitTestNodes(this._items, event.clientX, event.clientY);
modelForClick(event) {
let items = this._sortedItems;
let index = Private.hitTestNodes(this._items, event.clientX, event.clientY);
if (index !== -1) {

@@ -538,3 +498,3 @@ return items[index];

return undefined;
};
}
/**

@@ -547,19 +507,18 @@ * Select an item by name.

*/
DirListing.prototype.selectItemByName = function (name) {
var _this = this;
selectItemByName(name) {
// Make sure the file is available.
return this.model.refresh().then(function () {
if (_this.isDisposed) {
return this.model.refresh().then(() => {
if (this.isDisposed) {
throw new Error('File browser is disposed.');
}
var items = _this._sortedItems;
var index = algorithm_1.ArrayExt.findFirstIndex(items, function (value) { return value.name === name; });
let items = this._sortedItems;
let index = algorithm_1.ArrayExt.findFirstIndex(items, value => value.name === name);
if (index === -1) {
throw new Error('Item does not exist.');
}
_this._selectItem(index, false);
messaging_1.MessageLoop.sendMessage(_this, widgets_1.Widget.Msg.UpdateRequest);
domutils_1.ElementExt.scrollIntoViewIfNeeded(_this.contentNode, _this._items[index]);
this._selectItem(index, false);
messaging_1.MessageLoop.sendMessage(this, widgets_1.Widget.Msg.UpdateRequest);
domutils_1.ElementExt.scrollIntoViewIfNeeded(this.contentNode, this._items[index]);
});
};
}
/**

@@ -575,3 +534,3 @@ * Handle the DOM events for the directory listing.

*/
DirListing.prototype.handleEvent = function (event) {
handleEvent(event) {
switch (event.type) {

@@ -627,10 +586,10 @@ case 'mousedown':

}
};
}
/**
* A message handler invoked on an `'after-attach'` message.
*/
DirListing.prototype.onAfterAttach = function (msg) {
_super.prototype.onAfterAttach.call(this, msg);
var node = this.node;
var content = apputils_1.DOMUtils.findElement(node, CONTENT_CLASS);
onAfterAttach(msg) {
super.onAfterAttach(msg);
let node = this.node;
let content = apputils_1.DOMUtils.findElement(node, CONTENT_CLASS);
node.addEventListener('mousedown', this);

@@ -650,10 +609,10 @@ node.addEventListener('keydown', this);

content.addEventListener('p-drop', this);
};
}
/**
* A message handler invoked on a `'before-detach'` message.
*/
DirListing.prototype.onBeforeDetach = function (msg) {
_super.prototype.onBeforeDetach.call(this, msg);
var node = this.node;
var content = apputils_1.DOMUtils.findElement(node, CONTENT_CLASS);
onBeforeDetach(msg) {
super.onBeforeDetach(msg);
let node = this.node;
let content = apputils_1.DOMUtils.findElement(node, CONTENT_CLASS);
node.removeEventListener('mousedown', this);

@@ -675,7 +634,7 @@ node.removeEventListener('keydown', this);

document.removeEventListener('mouseup', this, true);
};
}
/**
* A message handler invoked on an `'after-show'` message.
*/
DirListing.prototype.onAfterShow = function (msg) {
onAfterShow(msg) {
if (this._isDirty) {

@@ -686,14 +645,13 @@ // Update the sorted items.

}
};
}
/**
* A handler invoked on an `'update-request'` message.
*/
DirListing.prototype.onUpdateRequest = function (msg) {
var _this = this;
onUpdateRequest(msg) {
this._isDirty = false;
// Fetch common variables.
var items = this._sortedItems;
var nodes = this._items;
var content = apputils_1.DOMUtils.findElement(this.node, CONTENT_CLASS);
var renderer = this._renderer;
let items = this._sortedItems;
let nodes = this._items;
let content = apputils_1.DOMUtils.findElement(this.node, CONTENT_CLASS);
let renderer = this._renderer;
this.removeClass(MULTI_SELECTED_CLASS);

@@ -707,3 +665,3 @@ this.removeClass(SELECTED_CLASS);

while (nodes.length < items.length) {
var node = renderer.createItemNode();
let node = renderer.createItemNode();
node.classList.add(ITEM_CLASS);

@@ -714,3 +672,3 @@ nodes.push(node);

// Remove extra classes from the nodes.
nodes.forEach(function (item) {
nodes.forEach(item => {
item.classList.remove(SELECTED_CLASS);

@@ -721,9 +679,9 @@ item.classList.remove(RUNNING_CLASS);

// Add extra classes to item nodes based on widget state.
items.forEach(function (item, i) {
var node = nodes[i];
var ft = _this._manager.registry.getFileTypeForModel(item);
items.forEach((item, i) => {
let node = nodes[i];
let ft = this._manager.registry.getFileTypeForModel(item);
renderer.updateItemNode(node, item, ft);
if (_this._selection[item.name]) {
if (this._selection[item.name]) {
node.classList.add(SELECTED_CLASS);
if (_this._isCut && _this._model.path === _this._prevPath) {
if (this._isCut && this._model.path === this._prevPath) {
node.classList.add(CUT_CLASS);

@@ -734,3 +692,3 @@ }

// Handle the selectors on the widget node.
var selected = Object.keys(this._selection).length;
let selected = Object.keys(this._selection).length;
if (selected) {

@@ -743,8 +701,8 @@ this.addClass(SELECTED_CLASS);

// Handle file session statuses.
var paths = items.map(function (item) { return item.path; });
algorithm_1.each(this._model.sessions(), function (session) {
var index = algorithm_1.ArrayExt.firstIndexOf(paths, session.path);
var node = nodes[index];
var name = session.kernel.name;
var specs = _this._model.specs;
let paths = items.map(item => item.path);
algorithm_1.each(this._model.sessions(), session => {
let index = algorithm_1.ArrayExt.firstIndexOf(paths, session.path);
let node = nodes[index];
let name = session.kernel.name;
let specs = this._model.specs;
node.classList.add(RUNNING_CLASS);

@@ -754,14 +712,14 @@ if (specs) {

}
node.title = node.title + "\nKernel: " + name;
node.title = `${node.title}\nKernel: ${name}`;
});
this._prevPath = this._model.path;
};
}
/**
* Handle the `'click'` event for the widget.
*/
DirListing.prototype._evtClick = function (event) {
var target = event.target;
var header = this.headerNode;
_evtClick(event) {
let target = event.target;
let header = this.headerNode;
if (header.contains(target)) {
var state = this.renderer.handleHeaderClick(header, event);
let state = this.renderer.handleHeaderClick(header, event);
if (state) {

@@ -772,13 +730,13 @@ this.sort(state);

}
};
}
/**
* Handle the `'scroll'` event for the widget.
*/
DirListing.prototype._evtScroll = function (event) {
_evtScroll(event) {
this.headerNode.scrollLeft = this.contentNode.scrollLeft;
};
}
/**
* Handle the `'mousedown'` event for the widget.
*/
DirListing.prototype._evtMousedown = function (event) {
_evtMousedown(event) {
// Bail if clicking within the edit node

@@ -799,3 +757,3 @@ if (event.target === this._editNode) {

}
var index = Private.hitTestNodes(this._items, event.clientX, event.clientY);
let index = Private.hitTestNodes(this._items, event.clientX, event.clientY);
if (index === -1) {

@@ -809,3 +767,3 @@ return;

// Check for clearing a context menu.
var newContext = (IS_MAC && event.ctrlKey) || (event.button === 2);
let newContext = (IS_MAC && event.ctrlKey) || (event.button === 2);
if (newContext) {

@@ -821,10 +779,10 @@ return;

}
};
}
/**
* Handle the `'mouseup'` event for the widget.
*/
DirListing.prototype._evtMouseup = function (event) {
_evtMouseup(event) {
// Handle any soft selection from the previous mouse down.
if (this._softSelection) {
var altered = event.metaKey || event.shiftKey || event.ctrlKey;
let altered = event.metaKey || event.shiftKey || event.ctrlKey;
// See if we need to clear the other selection.

@@ -846,7 +804,7 @@ if (!altered && event.button === 0) {

event.stopPropagation();
};
}
/**
* Handle the `'mousemove'` event for the widget.
*/
DirListing.prototype._evtMousemove = function (event) {
_evtMousemove(event) {
event.preventDefault();

@@ -859,5 +817,5 @@ event.stopPropagation();

// Check for a drag initialization.
var data = this._dragData;
var dx = Math.abs(event.clientX - data.pressX);
var dy = Math.abs(event.clientY - data.pressY);
let data = this._dragData;
let dx = Math.abs(event.clientX - data.pressX);
let dy = Math.abs(event.clientY - data.pressY);
if (dx < DRAG_THRESHOLD && dy < DRAG_THRESHOLD) {

@@ -867,10 +825,9 @@ return;

this._startDrag(data.index, event.clientX, event.clientY);
};
}
/**
* Handle the `'keydown'` event for the widget.
*/
DirListing.prototype._evtKeydown = function (event) {
var _this = this;
_evtKeydown(event) {
switch (event.keyCode) {
case 13:// Enter
case 13: // Enter
// Do nothing if any modifier keys are pressed.

@@ -882,22 +839,20 @@ if (event.ctrlKey || event.shiftKey || event.altKey || event.metaKey) {

event.stopPropagation();
var selected = Object.keys(this._selection);
var name_6 = selected[0];
var items = this._sortedItems;
var i = algorithm_1.ArrayExt.findFirstIndex(items, function (value) { return value.name === name_6; });
let selected = Object.keys(this._selection);
let name = selected[0];
let items = this._sortedItems;
let i = algorithm_1.ArrayExt.findFirstIndex(items, value => value.name === name);
if (i === -1) {
return;
}
var model = this._model;
var item = this._sortedItems[i];
let model = this._model;
let item = this._sortedItems[i];
if (item.type === 'directory') {
model.cd(item.name).catch(function (error) {
return apputils_1.showErrorMessage('Open directory', error);
});
model.cd(item.name).catch(error => apputils_1.showErrorMessage('Open directory', error));
}
else {
var path = item.path;
let path = item.path;
this._manager.openOrReveal(path);
}
break;
case 38:// Up arrow
case 38: // Up arrow
this.selectPrevious(event.shiftKey);

@@ -907,3 +862,3 @@ event.stopPropagation();

break;
case 40:// Down arrow
case 40: // Down arrow
this.selectNext(event.shiftKey);

@@ -922,4 +877,4 @@ event.stopPropagation();

clearTimeout(this._searchPrefixTimer);
this._searchPrefixTimer = window.setTimeout(function () {
_this._searchPrefix = '';
this._searchPrefixTimer = window.setTimeout(() => {
this._searchPrefix = '';
}, PREFIX_APPEND_DURATION);

@@ -930,8 +885,7 @@ this.selectByPrefix();

}
};
}
/**
* Handle the `'dblclick'` event for the widget.
*/
DirListing.prototype._evtDblClick = function (event) {
var _this = this;
_evtDblClick(event) {
// Do nothing if it's not a left mouse press.

@@ -949,29 +903,27 @@ if (event.button !== 0) {

clearTimeout(this._selectTimer);
this._noSelectTimer = window.setTimeout(function () {
_this._noSelectTimer = -1;
this._noSelectTimer = window.setTimeout(() => {
this._noSelectTimer = -1;
}, RENAME_DURATION);
this._editNode.blur();
// Find a valid double click target.
var target = event.target;
var i = algorithm_1.ArrayExt.findFirstIndex(this._items, function (node) { return node.contains(target); });
let target = event.target;
let i = algorithm_1.ArrayExt.findFirstIndex(this._items, node => node.contains(target));
if (i === -1) {
return;
}
var model = this._model;
var item = this._sortedItems[i];
let model = this._model;
let item = this._sortedItems[i];
if (item.type === 'directory') {
model.cd(item.name).catch(function (error) {
return apputils_1.showErrorMessage('Open directory', error);
});
model.cd(item.name).catch(error => apputils_1.showErrorMessage('Open directory', error));
}
else {
var path = item.path;
let path = item.path;
this._manager.openOrReveal(path);
}
};
}
/**
* Handle the `drop` event for the widget.
*/
DirListing.prototype._evtNativeDrop = function (event) {
var files = event.dataTransfer.files;
_evtNativeDrop(event) {
let files = event.dataTransfer.files;
if (files.length === 0) {

@@ -981,20 +933,20 @@ return;

event.preventDefault();
for (var i = 0; i < files.length; i++) {
for (let i = 0; i < files.length; i++) {
this._model.upload(files[i]);
}
};
}
/**
* Handle the `'p-dragenter'` event for the widget.
*/
DirListing.prototype._evtDragEnter = function (event) {
_evtDragEnter(event) {
if (event.mimeData.hasData(CONTENTS_MIME)) {
var index = Private.hitTestNodes(this._items, event.clientX, event.clientY);
let index = Private.hitTestNodes(this._items, event.clientX, event.clientY);
if (index === -1) {
return;
}
var item = this._sortedItems[index];
let item = this._sortedItems[index];
if (item.type !== 'directory' || this._selection[item.name]) {
return;
}
var target = event.target;
let target = event.target;
target.classList.add(DROP_TARGET_CLASS);

@@ -1004,32 +956,32 @@ event.preventDefault();

}
};
}
/**
* Handle the `'p-dragleave'` event for the widget.
*/
DirListing.prototype._evtDragLeave = function (event) {
_evtDragLeave(event) {
event.preventDefault();
event.stopPropagation();
var dropTarget = apputils_1.DOMUtils.findElement(this.node, DROP_TARGET_CLASS);
let dropTarget = apputils_1.DOMUtils.findElement(this.node, DROP_TARGET_CLASS);
if (dropTarget) {
dropTarget.classList.remove(DROP_TARGET_CLASS);
}
};
}
/**
* Handle the `'p-dragover'` event for the widget.
*/
DirListing.prototype._evtDragOver = function (event) {
_evtDragOver(event) {
event.preventDefault();
event.stopPropagation();
event.dropAction = event.proposedAction;
var dropTarget = apputils_1.DOMUtils.findElement(this.node, DROP_TARGET_CLASS);
let dropTarget = apputils_1.DOMUtils.findElement(this.node, DROP_TARGET_CLASS);
if (dropTarget) {
dropTarget.classList.remove(DROP_TARGET_CLASS);
}
var index = Private.hitTestNodes(this._items, event.clientX, event.clientY);
let index = Private.hitTestNodes(this._items, event.clientX, event.clientY);
this._items[index].classList.add(DROP_TARGET_CLASS);
};
}
/**
* Handle the `'p-drop'` event for the widget.
*/
DirListing.prototype._evtDrop = function (event) {
_evtDrop(event) {
event.preventDefault();

@@ -1046,3 +998,3 @@ event.stopPropagation();

event.dropAction = event.proposedAction;
var target = event.target;
let target = event.target;
while (target && target.parentElement) {

@@ -1056,17 +1008,16 @@ if (target.classList.contains(DROP_TARGET_CLASS)) {

// Get the path based on the target node.
var index = algorithm_1.ArrayExt.firstIndexOf(this._items, target);
var items = this._sortedItems;
var basePath = this._model.path;
const index = algorithm_1.ArrayExt.firstIndexOf(this._items, target);
const items = this._sortedItems;
let basePath = this._model.path;
if (items[index].type === 'directory') {
basePath = coreutils_1.PathExt.join(basePath, items[index].name);
}
var manager = this._manager;
const manager = this._manager;
// Handle the items.
var promises = [];
var paths = event.mimeData.getData(CONTENTS_MIME);
for (var _i = 0, paths_1 = paths; _i < paths_1.length; _i++) {
var path = paths_1[_i];
var localPath = manager.services.contents.localPath(path);
var name_7 = coreutils_1.PathExt.basename(localPath);
var newPath = coreutils_1.PathExt.join(basePath, name_7);
const promises = [];
const paths = event.mimeData.getData(CONTENTS_MIME);
for (let path of paths) {
let localPath = manager.services.contents.localPath(path);
let name = coreutils_1.PathExt.basename(localPath);
let newPath = coreutils_1.PathExt.join(basePath, name);
// Skip files that are not moving.

@@ -1078,15 +1029,14 @@ if (newPath === path) {

}
Promise.all(promises).catch(function (error) {
Promise.all(promises).catch(error => {
apputils_1.showErrorMessage('Move Error', error);
});
};
}
/**
* Start a drag event.
*/
DirListing.prototype._startDrag = function (index, clientX, clientY) {
var _this = this;
var selectedNames = Object.keys(this._selection);
var source = this._items[index];
var items = this._sortedItems;
var item;
_startDrag(index, clientX, clientY) {
let selectedNames = Object.keys(this._selection);
let source = this._items[index];
let items = this._sortedItems;
let item;
// If the source node is not selected, use just that node.

@@ -1098,4 +1048,4 @@ if (!source.classList.contains(SELECTED_CLASS)) {

else {
var name_8 = selectedNames[0];
item = algorithm_1.find(items, function (value) { return value.name === name_8; });
let name = selectedNames[0];
item = algorithm_1.find(items, value => value.name === name);
}

@@ -1106,7 +1056,7 @@ if (!item) {

// Create the drag image.
var ft = this._manager.registry.getFileTypeForModel(item);
var dragImage = this.renderer.createDragImage(source, selectedNames.length, ft);
let ft = this._manager.registry.getFileTypeForModel(item);
let dragImage = this.renderer.createDragImage(source, selectedNames.length, ft);
// Set up the drag event.
this._drag = new dragdrop_1.Drag({
dragImage: dragImage,
dragImage,
mimeData: new coreutils_2.MimeData(),

@@ -1116,4 +1066,4 @@ supportedActions: 'move',

});
var basePath = this._model.path;
var paths = algorithm_1.toArray(algorithm_1.map(selectedNames, function (name) {
let basePath = this._model.path;
let paths = algorithm_1.toArray(algorithm_1.map(selectedNames, name => {
return coreutils_1.PathExt.join(basePath, name);

@@ -1123,23 +1073,23 @@ }));

if (item && item.type !== 'directory') {
var otherPaths_1 = paths.slice(1).reverse();
this._drag.mimeData.setData(FACTORY_MIME, function () {
const otherPaths = paths.slice(1).reverse();
this._drag.mimeData.setData(FACTORY_MIME, () => {
if (!item) {
return;
}
var path = item.path;
var widget = _this._manager.findWidget(path);
let path = item.path;
let widget = this._manager.findWidget(path);
if (!widget) {
widget = _this._manager.open(item.path);
widget = this._manager.open(item.path);
}
if (otherPaths_1.length) {
var firstWidgetPlaced = new coreutils_2.PromiseDelegate();
firstWidgetPlaced.promise.then(function () {
var prevWidget = widget;
otherPaths_1.forEach(function (path) {
var options = {
if (otherPaths.length) {
const firstWidgetPlaced = new coreutils_2.PromiseDelegate();
firstWidgetPlaced.promise.then(() => {
let prevWidget = widget;
otherPaths.forEach(path => {
const options = {
ref: prevWidget.id,
mode: 'tab-after'
};
prevWidget = _this._manager.openOrReveal(path, void 0, void 0, options);
_this._manager.openOrReveal(item.path);
prevWidget = this._manager.openOrReveal(path, void 0, void 0, options);
this._manager.openOrReveal(item.path);
});

@@ -1156,17 +1106,16 @@ });

clearTimeout(this._selectTimer);
this._drag.start(clientX, clientY).then(function (action) {
_this._drag = null;
clearTimeout(_this._selectTimer);
this._drag.start(clientX, clientY).then(action => {
this._drag = null;
clearTimeout(this._selectTimer);
});
};
}
/**
* Handle selection on a file node.
*/
DirListing.prototype._handleFileSelect = function (event) {
var _this = this;
_handleFileSelect(event) {
// Fetch common variables.
var items = this._sortedItems;
var index = Private.hitTestNodes(this._items, event.clientX, event.clientY);
var target = event.target;
var inText = target.classList.contains(ITEM_TEXT_CLASS);
let items = this._sortedItems;
let index = Private.hitTestNodes(this._items, event.clientX, event.clientY);
let target = event.target;
let inText = target.classList.contains(ITEM_TEXT_CLASS);
clearTimeout(this._selectTimer);

@@ -1178,4 +1127,4 @@ if (index === -1) {

this._softSelection = '';
var name = items[index].name;
var selected = Object.keys(this._selection);
let name = items[index].name;
let selected = Object.keys(this._selection);
// Handle toggling.

@@ -1202,5 +1151,5 @@ if ((IS_MAC && event.metaKey) || (!IS_MAC && event.ctrlKey)) {

if (inText && selected.length === 1 && selected[0] === name) {
this._selectTimer = window.setTimeout(function () {
if (_this._noSelectTimer === -1) {
_this._doRename();
this._selectTimer = window.setTimeout(() => {
if (this._noSelectTimer === -1) {
this._doRename();
}

@@ -1214,16 +1163,16 @@ }, RENAME_DURATION);

this.update();
};
}
/**
* Handle a multiple select on a file item node.
*/
DirListing.prototype._handleMultiSelect = function (selected, index) {
_handleMultiSelect(selected, index) {
// Find the "nearest selected".
var items = this._sortedItems;
var nearestIndex = -1;
for (var i = 0; i < this._items.length; i++) {
let items = this._sortedItems;
let nearestIndex = -1;
for (let i = 0; i < this._items.length; i++) {
if (i === index) {
continue;
}
var name_9 = items[i].name;
if (selected.indexOf(name_9) !== -1) {
let name = items[i].name;
if (selected.indexOf(name) !== -1) {
if (nearestIndex === -1) {

@@ -1244,3 +1193,3 @@ nearestIndex = i;

// Select the rows between the current and the nearest selected.
for (var i = 0; i < this._items.length; i++) {
for (let i = 0; i < this._items.length; i++) {
if (nearestIndex >= i && index <= i ||

@@ -1251,23 +1200,21 @@ nearestIndex <= i && index >= i) {

}
};
}
/**
* Copy the selected items, and optionally cut as well.
*/
DirListing.prototype._copy = function () {
var _this = this;
_copy() {
this._clipboard.length = 0;
algorithm_1.each(this.selectedItems(), function (item) {
_this._clipboard.push(item.path);
algorithm_1.each(this.selectedItems(), item => {
this._clipboard.push(item.path);
});
};
}
/**
* Delete the files with the given names.
*/
DirListing.prototype._delete = function (names) {
var promises = [];
var basePath = this._model.path;
for (var _i = 0, names_1 = names; _i < names_1.length; _i++) {
var name_10 = names_1[_i];
var newPath = coreutils_1.PathExt.join(basePath, name_10);
var promise = this._model.manager.deleteFile(newPath).catch(function (err) {
_delete(names) {
const promises = [];
const basePath = this._model.path;
for (let name of names) {
let newPath = coreutils_1.PathExt.join(basePath, name);
let promise = this._model.manager.deleteFile(newPath).catch(err => {
apputils_1.showErrorMessage('Delete Failed', err);

@@ -1277,84 +1224,82 @@ });

}
return Promise.all(promises).then(function () { return undefined; });
};
return Promise.all(promises).then(() => undefined);
}
/**
* Allow the user to rename item on a given row.
*/
DirListing.prototype._doRename = function () {
var _this = this;
_doRename() {
this._inRename = true;
var items = this._sortedItems;
var name = Object.keys(this._selection)[0];
var index = algorithm_1.ArrayExt.findFirstIndex(items, function (value) { return value.name === name; });
var row = this._items[index];
var item = items[index];
var nameNode = this.renderer.getNameNode(row);
var original = item.name;
let items = this._sortedItems;
let name = Object.keys(this._selection)[0];
let index = algorithm_1.ArrayExt.findFirstIndex(items, value => value.name === name);
let row = this._items[index];
let item = items[index];
let nameNode = this.renderer.getNameNode(row);
let original = item.name;
this._editNode.value = original;
this._selectItem(index, false);
return Private.doRename(nameNode, this._editNode).then(function (newName) {
return Private.doRename(nameNode, this._editNode).then(newName => {
if (!newName || newName === original) {
_this._inRename = false;
this._inRename = false;
return original;
}
if (!docmanager_1.isValidFileName(newName)) {
apputils_1.showErrorMessage('Rename Error', Error("\"" + newName + "\" is not a valid name for a file. " +
"Names must have nonzero length, " +
"and cannot include \"/\", \"\\\", or \":\""));
_this._inRename = false;
apputils_1.showErrorMessage('Rename Error', Error(`"${newName}" is not a valid name for a file. ` +
`Names must have nonzero length, ` +
`and cannot include "/", "\\", or ":"`));
this._inRename = false;
return original;
}
if (_this.isDisposed) {
_this._inRename = false;
if (this.isDisposed) {
this._inRename = false;
throw new Error('File browser is disposed.');
}
var manager = _this._manager;
var oldPath = coreutils_1.PathExt.join(_this._model.path, original);
var newPath = coreutils_1.PathExt.join(_this._model.path, newName);
var promise = docmanager_1.renameFile(manager, oldPath, newPath);
return promise.catch(function (error) {
const manager = this._manager;
const oldPath = coreutils_1.PathExt.join(this._model.path, original);
const newPath = coreutils_1.PathExt.join(this._model.path, newName);
const promise = docmanager_1.renameFile(manager, oldPath, newPath);
return promise.catch(error => {
if (error !== 'File not renamed') {
apputils_1.showErrorMessage('Rename Error', error);
}
_this._inRename = false;
this._inRename = false;
return original;
}).then(function () {
if (_this.isDisposed) {
_this._inRename = false;
}).then(() => {
if (this.isDisposed) {
this._inRename = false;
throw new Error('File browser is disposed.');
}
if (_this._inRename) {
if (this._inRename) {
// No need to catch because `newName` will always exit.
_this.selectItemByName(newName);
this.selectItemByName(newName);
}
_this._inRename = false;
this._inRename = false;
return newName;
});
});
};
}
/**
* Select a given item.
*/
DirListing.prototype._selectItem = function (index, keepExisting) {
_selectItem(index, keepExisting) {
// Selected the given row(s)
var items = this._sortedItems;
let items = this._sortedItems;
if (!keepExisting) {
this._selection = Object.create(null);
}
var name = items[index].name;
let name = items[index].name;
this._selection[name] = true;
this.update();
};
}
/**
* Handle the `refreshed` signal from the model.
*/
DirListing.prototype._onModelRefreshed = function () {
var _this = this;
_onModelRefreshed() {
// Update the selection.
var existing = Object.keys(this._selection);
let existing = Object.keys(this._selection);
this._selection = Object.create(null);
algorithm_1.each(this._model.items(), function (item) {
var name = item.name;
algorithm_1.each(this._model.items(), item => {
let name = item.name;
if (existing.indexOf(name) !== -1) {
_this._selection[name] = true;
this._selection[name] = true;
}

@@ -1369,7 +1314,7 @@ });

}
};
}
/**
* Handle a `pathChanged` signal from the model.
*/
DirListing.prototype._onPathChanged = function () {
_onPathChanged() {
// Reset the selection.

@@ -1379,9 +1324,8 @@ this._selection = Object.create(null);

this.sort(this.sortState);
};
}
/**
* Handle a `fileChanged` signal from the model.
*/
DirListing.prototype._onFileChanged = function (sender, args) {
var _this = this;
var newValue = args.newValue;
_onFileChanged(sender, args) {
let newValue = args.newValue;
if (!newValue) {

@@ -1393,22 +1337,21 @@ return;

}
this.selectItemByName(name).then(function () {
if (!_this.isDisposed && newValue.type === 'directory') {
_this._doRename();
this.selectItemByName(name).then(() => {
if (!this.isDisposed && newValue.type === 'directory') {
this._doRename();
}
}).catch(function () { });
};
}).catch(() => { });
}
/**
* Handle an `activateRequested` signal from the manager.
*/
DirListing.prototype._onActivateRequested = function (sender, args) {
var dirname = coreutils_1.PathExt.dirname(args);
_onActivateRequested(sender, args) {
let dirname = coreutils_1.PathExt.dirname(args);
if (dirname !== this._model.path) {
return;
}
var basename = coreutils_1.PathExt.basename(args);
let basename = coreutils_1.PathExt.basename(args);
this.selectItemByName(basename)
.catch(function () { });
};
return DirListing;
}(widgets_1.Widget));
.catch(() => { });
}
}
exports.DirListing = DirListing;

@@ -1422,12 +1365,10 @@ /**

*/
var Renderer = /** @class */ (function () {
function Renderer() {
}
class Renderer {
/**
* Create the DOM node for a dir listing.
*/
Renderer.prototype.createNode = function () {
var node = document.createElement('div');
var header = document.createElement('div');
var content = document.createElement('ul');
createNode() {
let node = document.createElement('div');
let header = document.createElement('div');
let content = document.createElement('ul');
content.className = CONTENT_CLASS;

@@ -1439,3 +1380,3 @@ header.className = HEADER_CLASS;

return node;
};
}
/**

@@ -1446,5 +1387,5 @@ * Populate and empty header node for a dir listing.

*/
Renderer.prototype.populateHeaderNode = function (node) {
var name = this._createHeaderItemNode('Name');
var modified = this._createHeaderItemNode('Last Modified');
populateHeaderNode(node) {
let name = this._createHeaderItemNode('Name');
let modified = this._createHeaderItemNode('Last Modified');
name.classList.add(NAME_ID_CLASS);

@@ -1455,3 +1396,3 @@ name.classList.add(SELECTED_CLASS);

node.appendChild(modified);
};
}
/**

@@ -1466,7 +1407,7 @@ * Handle a header click.

*/
Renderer.prototype.handleHeaderClick = function (node, event) {
var name = apputils_1.DOMUtils.findElement(node, NAME_ID_CLASS);
var modified = apputils_1.DOMUtils.findElement(node, MODIFIED_ID_CLASS);
var state = { direction: 'ascending', key: 'name' };
var target = event.target;
handleHeaderClick(node, event) {
let name = apputils_1.DOMUtils.findElement(node, NAME_ID_CLASS);
let modified = apputils_1.DOMUtils.findElement(node, MODIFIED_ID_CLASS);
let state = { direction: 'ascending', key: 'name' };
let target = event.target;
if (name.contains(target)) {

@@ -1510,3 +1451,3 @@ if (name.classList.contains(SELECTED_CLASS)) {

return state;
};
}
/**

@@ -1517,7 +1458,7 @@ * Create a new item node for a dir listing.

*/
Renderer.prototype.createItemNode = function () {
var node = document.createElement('li');
var icon = document.createElement('span');
var text = document.createElement('span');
var modified = document.createElement('span');
createItemNode() {
let node = document.createElement('li');
let icon = document.createElement('span');
let text = document.createElement('span');
let modified = document.createElement('span');
icon.className = ITEM_ICON_CLASS;

@@ -1530,3 +1471,3 @@ text.className = ITEM_TEXT_CLASS;

return node;
};
}
/**

@@ -1542,9 +1483,9 @@ * Update an item node to reflect the current state of a model.

*/
Renderer.prototype.updateItemNode = function (node, model, fileType) {
var icon = apputils_1.DOMUtils.findElement(node, ITEM_ICON_CLASS);
var text = apputils_1.DOMUtils.findElement(node, ITEM_TEXT_CLASS);
var modified = apputils_1.DOMUtils.findElement(node, ITEM_MODIFIED_CLASS);
updateItemNode(node, model, fileType) {
let icon = apputils_1.DOMUtils.findElement(node, ITEM_ICON_CLASS);
let text = apputils_1.DOMUtils.findElement(node, ITEM_TEXT_CLASS);
let modified = apputils_1.DOMUtils.findElement(node, ITEM_MODIFIED_CLASS);
if (fileType) {
icon.textContent = fileType.iconLabel || '';
icon.className = ITEM_ICON_CLASS + " " + (fileType.iconClass || '');
icon.className = `${ITEM_ICON_CLASS} ${fileType.iconClass || ''}`;
}

@@ -1560,4 +1501,4 @@ else {

}
var modText = '';
var modTitle = '';
let modText = '';
let modTitle = '';
if (model.last_modified) {

@@ -1569,3 +1510,3 @@ modText = coreutils_1.Time.formatHuman(new Date(model.last_modified));

modified.title = modTitle;
};
}
/**

@@ -1578,5 +1519,5 @@ * Get the node containing the file name.

*/
Renderer.prototype.getNameNode = function (node) {
getNameNode(node) {
return apputils_1.DOMUtils.findElement(node, ITEM_TEXT_CLASS);
};
}
/**

@@ -1593,6 +1534,6 @@ * Create a drag image for an item.

*/
Renderer.prototype.createDragImage = function (node, count, fileType) {
var dragImage = node.cloneNode(true);
var modified = apputils_1.DOMUtils.findElement(dragImage, ITEM_MODIFIED_CLASS);
var icon = apputils_1.DOMUtils.findElement(dragImage, ITEM_ICON_CLASS);
createDragImage(node, count, fileType) {
let dragImage = node.cloneNode(true);
let modified = apputils_1.DOMUtils.findElement(dragImage, ITEM_MODIFIED_CLASS);
let icon = apputils_1.DOMUtils.findElement(dragImage, ITEM_ICON_CLASS);
dragImage.removeChild(modified);

@@ -1609,14 +1550,14 @@ if (!fileType) {

if (count > 1) {
var nameNode = apputils_1.DOMUtils.findElement(dragImage, ITEM_TEXT_CLASS);
let nameNode = apputils_1.DOMUtils.findElement(dragImage, ITEM_TEXT_CLASS);
nameNode.textContent = count + ' Items';
}
return dragImage;
};
}
/**
* Create a node for a header item.
*/
Renderer.prototype._createHeaderItemNode = function (label) {
var node = document.createElement('div');
var text = document.createElement('span');
var icon = document.createElement('span');
_createHeaderItemNode(label) {
let node = document.createElement('div');
let text = document.createElement('span');
let icon = document.createElement('span');
node.className = HEADER_ITEM_CLASS;

@@ -1629,5 +1570,4 @@ text.className = HEADER_ITEM_TEXT_CLASS;

return node;
};
return Renderer;
}());
}
}
DirListing.Renderer = Renderer;

@@ -1639,3 +1579,2 @@ /**

})(DirListing = exports.DirListing || (exports.DirListing = {}));
exports.DirListing = DirListing;
/**

@@ -1652,6 +1591,6 @@ * The namespace for the listing private data.

function doRename(text, edit) {
var parent = text.parentElement;
let parent = text.parentElement;
parent.replaceChild(edit, text);
edit.focus();
var index = edit.value.lastIndexOf('.');
let index = edit.value.lastIndexOf('.');
if (index === -1) {

@@ -1663,10 +1602,10 @@ edit.setSelectionRange(0, edit.value.length);

}
return new Promise(function (resolve, reject) {
edit.onblur = function () {
return new Promise((resolve, reject) => {
edit.onblur = () => {
parent.replaceChild(text, edit);
resolve(edit.value);
};
edit.onkeydown = function (event) {
edit.onkeydown = (event) => {
switch (event.keyCode) {
case 13:// Enter
case 13: // Enter
event.stopPropagation();

@@ -1676,3 +1615,3 @@ event.preventDefault();

break;
case 27:// Escape
case 27: // Escape
event.stopPropagation();

@@ -1682,3 +1621,3 @@ event.preventDefault();

break;
case 38:// Up arrow
case 38: // Up arrow
event.stopPropagation();

@@ -1690,3 +1629,3 @@ event.preventDefault();

break;
case 40:// Down arrow
case 40: // Down arrow
event.stopPropagation();

@@ -1709,14 +1648,14 @@ event.preventDefault();

function sort(items, state) {
var copy = algorithm_1.toArray(items);
let copy = algorithm_1.toArray(items);
if (state.key === 'last_modified') {
// Sort by type and then by last modified.
copy.sort(function (a, b) {
copy.sort((a, b) => {
// Compare based on type.
var t1 = typeWeight(a);
var t2 = typeWeight(b);
let t1 = typeWeight(a);
let t2 = typeWeight(b);
if (t1 !== t2) {
return t1 < t2 ? -1 : 1; // Infinity safe
}
var valA = new Date(a.last_modified).getTime();
var valB = new Date(b.last_modified).getTime();
let valA = new Date(a.last_modified).getTime();
let valB = new Date(b.last_modified).getTime();
if (state.direction === 'descending') {

@@ -1730,6 +1669,6 @@ return valA - valB;

// Sort by type and then by name.
copy.sort(function (a, b) {
copy.sort((a, b) => {
// Compare based on type.
var t1 = typeWeight(a);
var t2 = typeWeight(b);
let t1 = typeWeight(a);
let t2 = typeWeight(b);
if (t1 !== t2) {

@@ -1752,3 +1691,3 @@ return t1 < t2 ? -1 : 1; // Infinity safe

function hitTestNodes(nodes, x, y) {
return algorithm_1.ArrayExt.findFirstIndex(nodes, function (node) { return domutils_1.ElementExt.hitTest(node, x, y); });
return algorithm_1.ArrayExt.findFirstIndex(nodes, node => domutils_1.ElementExt.hitTest(node, x, y));
}

@@ -1755,0 +1694,0 @@ Private.hitTestNodes = hitTestNodes;

@@ -8,2 +8,20 @@ import { IChangedArgs, IStateDB } from '@jupyterlab/coreutils';

/**
* The maximum upload size (in bytes) for notebook version < 5.1.0
*/
export declare const LARGE_FILE_SIZE: number;
/**
* The size (in bytes) of the biggest chunk we should upload at once.
*/
export declare const CHUNK_SIZE: number;
/**
* An upload progress event for a file at `path`.
*/
export interface IUploadModel {
path: string;
/**
* % uploaded [0, 1)
*/
progress: number;
}
/**
* An implementation of a file browser model.

@@ -57,2 +75,10 @@ *

/**
* A signal emitted when an upload progresses.
*/
readonly uploadChanged: ISignal<this, IChangedArgs<IUploadModel>>;
/**
* Create an iterator over the status of all in progress uploads.
*/
uploads(): IIterator<IUploadModel>;
/**
* Dispose of the resources held by the model.

@@ -114,34 +140,37 @@ */

* #### Notes
* This will fail to upload files that are too big to be sent in one
* request to the server.
* On Notebook version < 5.1.0, this will fail to upload files that are too
* big to be sent in one request to the server. On newer versions, it will
* ask for confirmation then upload the file in 1 MB chunks.
*/
upload(file: File): Promise<Contents.IModel>;
private _shouldUploadLarge;
/**
* Perform the actual upload.
*/
private _upload(file);
private _upload;
private _uploadCheckDisposed;
/**
* Handle an updated contents model.
*/
private _handleContents(contents);
private _handleContents;
/**
* Handle a change to the running sessions.
*/
private _onRunningChanged(sender, models);
private _onRunningChanged;
/**
* Handle a change on the contents manager.
*/
private _onFileChanged(sender, change);
private _onFileChanged;
/**
* Populate the model's sessions collection.
*/
private _populateSessions(models);
private _populateSessions;
/**
* Start the internal refresh timer.
*/
private _startTimer();
private _startTimer;
/**
* Handle internal model refresh logic.
*/
private _scheduleUpdate();
private _scheduleUpdate;
private _connectionFailure;

@@ -151,3 +180,2 @@ private _fileChanged;

private _key;
private _maxUploadSizeMb;
private _model;

@@ -168,2 +196,5 @@ private _pathChanged;

private _restored;
private _uploads;
private _uploadChanged;
private _unloadEventListener;
}

@@ -170,0 +201,0 @@ /**

"use strict";
// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
var coreutils_1 = require("@jupyterlab/coreutils");
var docmanager_1 = require("@jupyterlab/docmanager");
var algorithm_1 = require("@phosphor/algorithm");
var coreutils_2 = require("@phosphor/coreutils");
var signaling_1 = require("@phosphor/signaling");
const coreutils_1 = require("@jupyterlab/coreutils");
const docmanager_1 = require("@jupyterlab/docmanager");
const algorithm_1 = require("@phosphor/algorithm");
const coreutils_2 = require("@phosphor/coreutils");
const signaling_1 = require("@phosphor/signaling");
const apputils_1 = require("@jupyterlab/apputils");
/**
* The duration of auto-refresh in ms.
*/
var REFRESH_DURATION = 10000;
const REFRESH_DURATION = 10000;
/**
* The enforced time between refreshes in ms.
*/
var MIN_REFRESH = 1000;
const MIN_REFRESH = 1000;
/**
* The maximum upload size (in bytes) for notebook version < 5.1.0
*/
exports.LARGE_FILE_SIZE = 15 * 1024 * 1024;
/**
* The size (in bytes) of the biggest chunk we should upload at once.
*/
exports.CHUNK_SIZE = 1024 * 1024;
/**
* An implementation of a file browser model.

@@ -25,7 +42,7 @@ *

*/
var FileBrowserModel = /** @class */ (function () {
class FileBrowserModel {
/**
* Construct a new file browser model.
*/
function FileBrowserModel(options) {
constructor(options) {
this._connectionFailure = new signaling_1.Signal(this);

@@ -35,3 +52,2 @@ this._fileChanged = new signaling_1.Signal(this);

this._key = '';
this._maxUploadSizeMb = 15;
this._pathChanged = new signaling_1.Signal(this);

@@ -50,5 +66,7 @@ this._paths = new Set();

this._restored = new coreutils_2.PromiseDelegate();
this._uploads = [];
this._uploadChanged = new signaling_1.Signal(this);
this.manager = options.manager;
this._driveName = options.driveName || '';
var rootPath = this._driveName ? this._driveName + ':' : '';
let rootPath = this._driveName ? this._driveName + ':' : '';
this._model = {

@@ -66,95 +84,84 @@ path: rootPath,

this._state = options.state || null;
var services = options.manager.services;
const { services } = options.manager;
services.contents.fileChanged.connect(this._onFileChanged, this);
services.sessions.runningChanged.connect(this._onRunningChanged, this);
this._unloadEventListener = (e) => {
if (this._uploads.length > 0) {
const confirmationMessage = 'Files still uploading';
e.returnValue = confirmationMessage;
return confirmationMessage;
}
};
window.addEventListener('beforeunload', this._unloadEventListener);
this._scheduleUpdate();
this._startTimer();
}
Object.defineProperty(FileBrowserModel.prototype, "connectionFailure", {
/**
* A signal emitted when the file browser model loses connection.
*/
get: function () {
return this._connectionFailure;
},
enumerable: true,
configurable: true
});
Object.defineProperty(FileBrowserModel.prototype, "restored", {
/**
* A promise that resolves when the model is first restored.
*/
get: function () {
return this._restored.promise;
},
enumerable: true,
configurable: true
});
Object.defineProperty(FileBrowserModel.prototype, "fileChanged", {
/**
* Get the file path changed signal.
*/
get: function () {
return this._fileChanged;
},
enumerable: true,
configurable: true
});
Object.defineProperty(FileBrowserModel.prototype, "path", {
/**
* Get the current path.
*/
get: function () {
return this._model ? this._model.path : '';
},
enumerable: true,
configurable: true
});
Object.defineProperty(FileBrowserModel.prototype, "pathChanged", {
/**
* A signal emitted when the path changes.
*/
get: function () {
return this._pathChanged;
},
enumerable: true,
configurable: true
});
Object.defineProperty(FileBrowserModel.prototype, "refreshed", {
/**
* A signal emitted when the directory listing is refreshed.
*/
get: function () {
return this._refreshed;
},
enumerable: true,
configurable: true
});
Object.defineProperty(FileBrowserModel.prototype, "specs", {
/**
* Get the kernel spec models.
*/
get: function () {
return this.manager.services.sessions.specs;
},
enumerable: true,
configurable: true
});
Object.defineProperty(FileBrowserModel.prototype, "isDisposed", {
/**
* Get whether the model is disposed.
*/
get: function () {
return this._isDisposed;
},
enumerable: true,
configurable: true
});
/**
* A signal emitted when the file browser model loses connection.
*/
get connectionFailure() {
return this._connectionFailure;
}
/**
* A promise that resolves when the model is first restored.
*/
get restored() {
return this._restored.promise;
}
/**
* Get the file path changed signal.
*/
get fileChanged() {
return this._fileChanged;
}
/**
* Get the current path.
*/
get path() {
return this._model ? this._model.path : '';
}
/**
* A signal emitted when the path changes.
*/
get pathChanged() {
return this._pathChanged;
}
/**
* A signal emitted when the directory listing is refreshed.
*/
get refreshed() {
return this._refreshed;
}
/**
* Get the kernel spec models.
*/
get specs() {
return this.manager.services.sessions.specs;
}
/**
* Get whether the model is disposed.
*/
get isDisposed() {
return this._isDisposed;
}
/**
* A signal emitted when an upload progresses.
*/
get uploadChanged() {
return this._uploadChanged;
}
/**
* Create an iterator over the status of all in progress uploads.
*/
uploads() {
return new algorithm_1.ArrayIterator(this._uploads);
}
/**
* Dispose of the resources held by the model.
*/
FileBrowserModel.prototype.dispose = function () {
dispose() {
if (this.isDisposed) {
return;
}
window.removeEventListener('beforeunload', this._unloadEventListener);
this._isDisposed = true;

@@ -165,3 +172,3 @@ clearTimeout(this._timeoutId);

signaling_1.Signal.clearData(this);
};
}
/**

@@ -172,5 +179,5 @@ * Create an iterator over the model's items.

*/
FileBrowserModel.prototype.items = function () {
items() {
return new algorithm_1.ArrayIterator(this._items);
};
}
/**

@@ -181,13 +188,13 @@ * Create an iterator over the active sessions in the directory.

*/
FileBrowserModel.prototype.sessions = function () {
sessions() {
return new algorithm_1.ArrayIterator(this._sessions);
};
}
/**
* Force a refresh of the directory contents.
*/
FileBrowserModel.prototype.refresh = function () {
refresh() {
this._lastRefresh = new Date().getTime();
this._requested = false;
return this.cd('.');
};
}
/**

@@ -200,5 +207,3 @@ * Change directory.

*/
FileBrowserModel.prototype.cd = function (newValue) {
var _this = this;
if (newValue === void 0) { newValue = '.'; }
cd(newValue = '.') {
if (newValue !== '.') {

@@ -214,4 +219,4 @@ newValue = Private.normalizePath(this.manager.services.contents, this._model.path, newValue);

}
var oldValue = this.path;
var options = { content: true };
let oldValue = this.path;
let options = { content: true };
this._pendingPath = newValue;

@@ -221,38 +226,38 @@ if (oldValue !== newValue) {

}
var services = this.manager.services;
this._pending = services.contents.get(newValue, options).then(function (contents) {
if (_this.isDisposed) {
let services = this.manager.services;
this._pending = services.contents.get(newValue, options).then(contents => {
if (this.isDisposed) {
return;
}
_this._refreshDuration = REFRESH_DURATION;
_this._handleContents(contents);
_this._pendingPath = null;
this._refreshDuration = REFRESH_DURATION;
this._handleContents(contents);
this._pendingPath = null;
if (oldValue !== newValue) {
// If there is a state database and a unique key, save the new path.
if (_this._state && _this._key) {
_this._state.save(_this._key, { path: newValue });
if (this._state && this._key) {
this._state.save(this._key, { path: newValue });
}
_this._pathChanged.emit({
this._pathChanged.emit({
name: 'path',
oldValue: oldValue,
newValue: newValue
oldValue,
newValue
});
}
_this._onRunningChanged(services.sessions, services.sessions.running());
_this._refreshed.emit(void 0);
}).catch(function (error) {
_this._pendingPath = null;
this._onRunningChanged(services.sessions, services.sessions.running());
this._refreshed.emit(void 0);
}).catch(error => {
this._pendingPath = null;
if (error.message === 'Not Found') {
error.message = "Directory not found: \"" + _this._model.path + "\"";
error.message = `Directory not found: "${this._model.path}"`;
console.error(error);
_this._connectionFailure.emit(error);
_this.cd('/');
this._connectionFailure.emit(error);
this.cd('/');
}
else {
_this._refreshDuration = REFRESH_DURATION * 10;
_this._connectionFailure.emit(error);
this._refreshDuration = REFRESH_DURATION * 10;
this._connectionFailure.emit(error);
}
});
return this._pending;
};
}
/**

@@ -266,5 +271,5 @@ * Download a file.

*/
FileBrowserModel.prototype.download = function (path) {
return this.manager.services.contents.getDownloadUrl(path).then(function (url) {
var element = document.createElement('a');
download(path) {
return this.manager.services.contents.getDownloadUrl(path).then(url => {
let element = document.createElement('a');
document.body.appendChild(element);

@@ -277,3 +282,3 @@ element.setAttribute('href', url);

});
};
}
/**

@@ -290,29 +295,27 @@ * Restore the state of the file browser.

*/
FileBrowserModel.prototype.restore = function (id) {
var _this = this;
var state = this._state;
var restored = !!this._key;
restore(id) {
const state = this._state;
const restored = !!this._key;
if (!state || restored) {
return Promise.resolve(void 0);
}
var manager = this.manager;
var key = "file-browser-" + id + ":cwd";
var ready = manager.services.ready;
return Promise.all([state.fetch(key), ready]).then(function (_a) {
var cwd = _a[0];
const manager = this.manager;
const key = `file-browser-${id}:cwd`;
const ready = manager.services.ready;
return Promise.all([state.fetch(key), ready]).then(([cwd]) => {
if (!cwd) {
_this._restored.resolve(void 0);
this._restored.resolve(void 0);
return;
}
var path = cwd['path'];
var localPath = manager.services.contents.localPath(path);
const path = cwd['path'];
const localPath = manager.services.contents.localPath(path);
return manager.services.contents.get(path)
.then(function () { return _this.cd(localPath); })
.catch(function () { return state.remove(key); });
}).catch(function () { return state.remove(key); })
.then(function () {
_this._key = key;
_this._restored.resolve(void 0);
.then(() => this.cd(localPath))
.catch(() => state.remove(key));
}).catch(() => state.remove(key))
.then(() => {
this._key = key;
this._restored.resolve(void 0);
}); // Set key after restoration is done.
};
}
/**

@@ -326,72 +329,122 @@ * Upload a `File` object.

* #### Notes
* This will fail to upload files that are too big to be sent in one
* request to the server.
* On Notebook version < 5.1.0, this will fail to upload files that are too
* big to be sent in one request to the server. On newer versions, it will
* ask for confirmation then upload the file in 1 MB chunks.
*/
FileBrowserModel.prototype.upload = function (file) {
var _this = this;
// Skip large files with a warning.
if (file.size > this._maxUploadSizeMb * 1024 * 1024) {
var msg = "Cannot upload file (>" + this._maxUploadSizeMb + " MB) ";
msg += "\"" + file.name + "\"";
console.warn(msg);
return Promise.reject(new Error(msg));
}
return this.refresh().then(function () {
if (_this.isDisposed) {
return Promise.resolve(false);
upload(file) {
return __awaiter(this, void 0, void 0, function* () {
const supportsChunked = coreutils_1.PageConfig.getNotebookVersion() >= [5, 1, 0];
const largeFile = file.size > exports.LARGE_FILE_SIZE;
const isNotebook = file.name.indexOf('.ipynb') !== -1;
const canSendChunked = supportsChunked && !isNotebook;
if (largeFile && !canSendChunked) {
let msg = `Cannot upload file (>${exports.LARGE_FILE_SIZE / (1024 * 1024)} MB). ${file.name}`;
console.warn(msg);
throw msg;
}
var item = algorithm_1.find(_this._items, function (i) { return i.name === file.name; });
if (item) {
return docmanager_1.shouldOverwrite(file.name);
const err = 'File not uploaded';
if (largeFile && !(yield this._shouldUploadLarge(file))) {
throw 'Cancelled large file upload';
}
return Promise.resolve(true);
}).then(function (value) {
if (value) {
return _this._upload(file);
yield this._uploadCheckDisposed();
yield this.refresh();
yield this._uploadCheckDisposed();
if (algorithm_1.find(this._items, i => i.name === file.name) && !(yield docmanager_1.shouldOverwrite(file.name))) {
throw err;
}
return Promise.reject('File not uploaded');
yield this._uploadCheckDisposed();
const chunkedUpload = supportsChunked && file.size > exports.CHUNK_SIZE;
return yield this._upload(file, isNotebook, chunkedUpload);
});
};
}
_shouldUploadLarge(file) {
return __awaiter(this, void 0, void 0, function* () {
const { button } = yield apputils_1.showDialog({
title: 'Large file size warning',
body: `The file size is ${Math.round(file.size / (1024 * 1024))} MB. Do you still want to upload it?`,
buttons: [apputils_1.Dialog.cancelButton(), apputils_1.Dialog.warnButton({ label: 'UPLOAD' })]
});
return button.accept;
});
}
/**
* Perform the actual upload.
*/
FileBrowserModel.prototype._upload = function (file) {
var _this = this;
// Gather the file model parameters.
var path = this._model.path;
path = path ? path + '/' + file.name : file.name;
var name = file.name;
var isNotebook = file.name.indexOf('.ipynb') !== -1;
var type = isNotebook ? 'notebook' : 'file';
var format = isNotebook ? 'json' : 'base64';
// Get the file content.
var reader = new FileReader();
if (isNotebook) {
reader.readAsText(file);
}
else {
reader.readAsArrayBuffer(file);
}
return new Promise(function (resolve, reject) {
reader.onload = function (event) {
var model = {
type: type,
format: format,
name: name,
_upload(file, isNotebook, chunked) {
return __awaiter(this, void 0, void 0, function* () {
// Gather the file model parameters.
let path = this._model.path;
path = path ? path + '/' + file.name : file.name;
let name = file.name;
let type = isNotebook ? 'notebook' : 'file';
let format = isNotebook ? 'json' : 'base64';
const uploadInner = (blob, chunk) => __awaiter(this, void 0, void 0, function* () {
yield this._uploadCheckDisposed();
let reader = new FileReader();
if (isNotebook) {
reader.readAsText(blob);
}
else {
reader.readAsArrayBuffer(blob);
}
yield new Promise((resolve, reject) => {
reader.onload = resolve;
reader.onerror = event => reject(`Failed to upload "${file.name}":` + event);
});
yield this._uploadCheckDisposed();
let model = {
type,
format,
name,
chunk,
content: Private.getContent(reader)
};
_this.manager.services.contents.save(path, model).then(function (contents) {
resolve(contents);
}).catch(reject);
};
reader.onerror = function (event) {
reject(Error("Failed to upload \"" + file.name + "\":" + event));
};
return yield this.manager.services.contents.save(path, model);
});
if (!chunked) {
return yield uploadInner(file);
}
let finalModel;
let upload = { path, progress: 0 };
this._uploadChanged.emit({ name: 'start',
newValue: upload,
oldValue: null
});
for (let start = 0; !finalModel; start += exports.CHUNK_SIZE) {
const end = start + exports.CHUNK_SIZE;
const lastChunk = end >= file.size;
const chunk = lastChunk ? -1 : end / exports.CHUNK_SIZE;
const newUpload = { path, progress: start / file.size };
this._uploads.splice(this._uploads.indexOf(upload));
this._uploads.push(newUpload);
this._uploadChanged.emit({
name: 'update',
newValue: newUpload,
oldValue: upload
});
upload = newUpload;
const currentModel = yield uploadInner(file.slice(start, end), chunk);
if (lastChunk) {
finalModel = currentModel;
}
}
this._uploads.splice(this._uploads.indexOf(upload));
this._uploadChanged.emit({
name: 'finish',
newValue: null,
oldValue: upload
});
return finalModel;
});
};
}
_uploadCheckDisposed() {
if (this.isDisposed) {
return Promise.reject('Filemanager disposed. File upload canceled');
}
return Promise.resolve();
}
/**
* Handle an updated contents model.
*/
FileBrowserModel.prototype._handleContents = function (contents) {
var _this = this;
_handleContents(contents) {
// Update our internal data.

@@ -411,21 +464,21 @@ this._model = {

this._paths.clear();
contents.content.forEach(function (model) {
_this._paths.add(model.path);
contents.content.forEach((model) => {
this._paths.add(model.path);
});
};
}
/**
* Handle a change to the running sessions.
*/
FileBrowserModel.prototype._onRunningChanged = function (sender, models) {
_onRunningChanged(sender, models) {
this._populateSessions(models);
this._refreshed.emit(void 0);
};
}
/**
* Handle a change on the contents manager.
*/
FileBrowserModel.prototype._onFileChanged = function (sender, change) {
var path = this._model.path;
var sessions = this.manager.services.sessions;
var oldValue = change.oldValue, newValue = change.newValue;
var value = oldValue && oldValue.path &&
_onFileChanged(sender, change) {
let path = this._model.path;
let { sessions } = this.manager.services;
let { oldValue, newValue } = change;
let value = oldValue && oldValue.path &&
coreutils_1.PathExt.dirname(oldValue.path) === path ? oldValue

@@ -441,23 +494,21 @@ : newValue && newValue.path && coreutils_1.PathExt.dirname(newValue.path) === path

}
};
}
/**
* Populate the model's sessions collection.
*/
FileBrowserModel.prototype._populateSessions = function (models) {
var _this = this;
_populateSessions(models) {
this._sessions.length = 0;
algorithm_1.each(models, function (model) {
if (_this._paths.has(model.path)) {
_this._sessions.push(model);
algorithm_1.each(models, model => {
if (this._paths.has(model.path)) {
this._sessions.push(model);
}
});
};
}
/**
* Start the internal refresh timer.
*/
FileBrowserModel.prototype._startTimer = function () {
var _this = this;
this._timeoutId = window.setInterval(function () {
if (_this._requested) {
_this.refresh();
_startTimer() {
this._timeoutId = window.setInterval(() => {
if (this._requested) {
this.refresh();
return;

@@ -469,13 +520,13 @@ }

}
var date = new Date().getTime();
if ((date - _this._lastRefresh) > _this._refreshDuration) {
_this.refresh();
let date = new Date().getTime();
if ((date - this._lastRefresh) > this._refreshDuration) {
this.refresh();
}
}, MIN_REFRESH);
};
}
/**
* Handle internal model refresh logic.
*/
FileBrowserModel.prototype._scheduleUpdate = function () {
var date = new Date().getTime();
_scheduleUpdate() {
let date = new Date().getTime();
if ((date - this._lastRefresh) > MIN_REFRESH) {

@@ -487,5 +538,4 @@ this.refresh();

}
};
return FileBrowserModel;
}());
}
}
exports.FileBrowserModel = FileBrowserModel;

@@ -506,6 +556,6 @@ /**

// Base64-encode binary file data.
var bytes = '';
var buf = new Uint8Array(reader.result);
var nbytes = buf.byteLength;
for (var i = 0; i < nbytes; i++) {
let bytes = '';
let buf = new Uint8Array(reader.result);
let nbytes = buf.byteLength;
for (let i = 0; i < nbytes; i++) {
bytes += String.fromCharCode(buf[i]);

@@ -524,8 +574,8 @@ }

function normalizePath(contents, root, path) {
var driveName = contents.driveName(root);
var localPath = contents.localPath(root);
var resolved = coreutils_1.PathExt.resolve(localPath, path);
return driveName ? driveName + ":" + resolved : resolved;
const driveName = contents.driveName(root);
const localPath = contents.localPath(root);
const resolved = coreutils_1.PathExt.resolve(localPath, path);
return driveName ? `${driveName}:${resolved}` : resolved;
}
Private.normalizePath = normalizePath;
})(Private || (Private = {}));
"use strict";
// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.
var __extends = (this && this.__extends) || (function () {
var extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
var apputils_1 = require("@jupyterlab/apputils");
const apputils_1 = require("@jupyterlab/apputils");
/**
* The class name added to a button content node.
*/
var CONTENT_CLASS = 'jp-FileButtons-buttonContent';
const CONTENT_CLASS = 'jp-FileButtons-buttonContent';
/**
* The class name added to a button icon node.
*/
var ICON_CLASS = 'jp-FileButtons-buttonIcon';
const ICON_CLASS = 'jp-FileButtons-buttonIcon';
/**
* The class name added to the upload button.
*/
var MATERIAL_UPLOAD = 'jp-UploadIcon';
const MATERIAL_UPLOAD = 'jp-UploadIcon';
/**
* The class name added to a material icon button.
*/
var MATERIAL_CLASS = 'jp-MaterialIcon';
const MATERIAL_CLASS = 'jp-MaterialIcon';
/**
* The class name added to the upload button.
*/
var UPLOAD_CLASS = 'jp-id-upload';
const UPLOAD_CLASS = 'jp-id-upload';
/**
* A widget which provides an upload button.
*/
var Uploader = /** @class */ (function (_super) {
__extends(Uploader, _super);
class Uploader extends apputils_1.ToolbarButton {
/**
* Construct a new file browser buttons widget.
*/
function Uploader(options) {
var _this = _super.call(this, {
constructor(options) {
super({
className: UPLOAD_CLASS,
onClick: function () {
_this._input.click();
onClick: () => {
this._input.click();
},
tooltip: 'Upload Files'
}) || this;
});
/**
* The 'change' handler for the input field.
*/
_this._onInputChanged = function () {
var files = Array.prototype.slice.call(_this._input.files);
var pending = files.map(function (file) { return _this.model.upload(file); });
Promise.all(pending).catch(function (error) {
this._onInputChanged = () => {
let files = Array.prototype.slice.call(this._input.files);
let pending = files.map(file => this.model.upload(file));
Promise.all(pending).catch(error => {
apputils_1.showErrorMessage('Upload Error', error);

@@ -65,21 +54,19 @@ });

*/
_this._onInputClicked = function () {
this._onInputClicked = () => {
// In order to allow repeated uploads of the same file (with delete in between),
// we need to clear the input value to trigger a change event.
_this._input.value = '';
this._input.value = '';
};
_this._input = Private.createUploadInput();
var uploadContent = document.createElement('span');
var uploadIcon = document.createElement('span');
this._input = Private.createUploadInput();
let uploadContent = document.createElement('span');
let uploadIcon = document.createElement('span');
uploadContent.className = CONTENT_CLASS;
uploadIcon.className = ICON_CLASS + ' ' + MATERIAL_CLASS + ' ' + MATERIAL_UPLOAD;
uploadContent.appendChild(uploadIcon);
_this.node.appendChild(uploadContent);
_this.model = options.model;
_this._input.onclick = _this._onInputClicked;
_this._input.onchange = _this._onInputChanged;
return _this;
this.node.appendChild(uploadContent);
this.model = options.model;
this._input.onclick = this._onInputClicked;
this._input.onchange = this._onInputChanged;
}
return Uploader;
}(apputils_1.ToolbarButton));
}
exports.Uploader = Uploader;

@@ -95,3 +82,3 @@ /**

function createUploadInput() {
var input = document.createElement('input');
let input = document.createElement('input');
input.type = 'file';

@@ -98,0 +85,0 @@ input.multiple = true;

{
"name": "@jupyterlab/filebrowser",
"version": "0.16.3",
"version": "0.17.0-0",
"description": "JupyterLab - FileBrowser Widget",

@@ -30,12 +30,12 @@ "homepage": "https://github.com/jupyterlab/jupyterlab",

"prepublishOnly": "npm run build",
"watch": "tsc -w"
"watch": "tsc -w --listEmittedFiles"
},
"dependencies": {
"@jupyterlab/apputils": "^0.16.4",
"@jupyterlab/coreutils": "^1.1.3",
"@jupyterlab/docmanager": "^0.16.3",
"@jupyterlab/docregistry": "^0.16.3",
"@jupyterlab/services": "^2.0.3",
"@jupyterlab/apputils": "^0.17.0-0",
"@jupyterlab/coreutils": "^2.0.0-0",
"@jupyterlab/docmanager": "^0.17.0-0",
"@jupyterlab/docregistry": "^0.17.0-0",
"@jupyterlab/services": "^3.0.0-0",
"@phosphor/algorithm": "^1.1.2",
"@phosphor/commands": "^1.4.0",
"@phosphor/commands": "^1.5.0",
"@phosphor/coreutils": "^1.3.0",

@@ -47,8 +47,8 @@ "@phosphor/disposable": "^1.1.2",

"@phosphor/signaling": "^1.2.2",
"@phosphor/widgets": "^1.5.0"
"@phosphor/widgets": "^1.6.0"
},
"devDependencies": {
"rimraf": "~2.6.2",
"typescript": "~2.6.2"
"typescript": "~2.9.2"
}
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc