@jupyterlab/docregistry
Advanced tools
Comparing version 0.15.5 to 0.16.0
@@ -85,8 +85,9 @@ import { Contents, ServiceManager } from '@jupyterlab/services'; | ||
/** | ||
* Populate the contents of the model, either from | ||
* disk or from the modelDB backend. | ||
* Initialize the context. | ||
* | ||
* @returns a promise that resolves upon model population. | ||
* @param isNew - Whether it is a new file. | ||
* | ||
* @returns a promise that resolves upon initialization. | ||
*/ | ||
fromStore(): Promise<void>; | ||
initialize(isNew: boolean): Promise<void>; | ||
/** | ||
@@ -151,2 +152,10 @@ * Save the document contents to disk. | ||
/** | ||
* Save the document contents to disk. | ||
*/ | ||
private _save(); | ||
/** | ||
* Revert the document contents to disk contents. | ||
*/ | ||
private _revert(); | ||
/** | ||
* Save a file, dealing with conflicts. | ||
@@ -153,0 +162,0 @@ */ |
@@ -220,17 +220,21 @@ "use strict"; | ||
/** | ||
* Populate the contents of the model, either from | ||
* disk or from the modelDB backend. | ||
* Initialize the context. | ||
* | ||
* @returns a promise that resolves upon model population. | ||
* @param isNew - Whether it is a new file. | ||
* | ||
* @returns a promise that resolves upon initialization. | ||
*/ | ||
Context.prototype.fromStore = function () { | ||
Context.prototype.initialize = function (isNew) { | ||
var _this = this; | ||
if (isNew) { | ||
return this._save(); | ||
} | ||
if (this._modelDB) { | ||
return this._modelDB.connected.then(function () { | ||
if (_this._modelDB.isPrepopulated) { | ||
_this.save(); | ||
_this._save(); | ||
return void 0; | ||
} | ||
else { | ||
return _this.revert(); | ||
return _this._revert(); | ||
} | ||
@@ -240,3 +244,3 @@ }); | ||
else { | ||
return this.revert(); | ||
return this._revert(); | ||
} | ||
@@ -249,34 +253,4 @@ }; | ||
var _this = this; | ||
var model = this._model; | ||
var content; | ||
if (this._factory.fileFormat === 'json') { | ||
content = model.toJSON(); | ||
} | ||
else { | ||
content = model.toString(); | ||
} | ||
var options = { | ||
type: this._factory.contentType, | ||
format: this._factory.fileFormat, | ||
content: content | ||
}; | ||
return this._manager.ready.then(function () { | ||
if (!model.modelDB.isCollaborative) { | ||
return _this._maybeSave(options); | ||
} | ||
return _this._manager.contents.save(_this._path, options); | ||
}).then(function (value) { | ||
if (_this.isDisposed) { | ||
return; | ||
} | ||
model.dirty = false; | ||
_this._updateContentsModel(value); | ||
if (!_this._isPopulated) { | ||
return _this._populate(); | ||
} | ||
}).catch(function (err) { | ||
var localPath = _this._manager.contents.localPath(_this._path); | ||
var name = coreutils_2.PathExt.basename(localPath); | ||
_this._handleError(err, "File Save Error for " + name); | ||
throw err; | ||
return this.ready.then(function () { | ||
return _this._save(); | ||
}); | ||
@@ -289,3 +263,5 @@ }; | ||
var _this = this; | ||
return Private.getSavePath(this._path).then(function (newPath) { | ||
return this.ready.then(function () { | ||
return Private.getSavePath(_this._path); | ||
}).then(function (newPath) { | ||
if (_this.isDisposed || !newPath) { | ||
@@ -315,39 +291,4 @@ return; | ||
var _this = this; | ||
var opts = { | ||
format: this._factory.fileFormat, | ||
type: this._factory.contentType, | ||
content: true | ||
}; | ||
var path = this._path; | ||
var model = this._model; | ||
return this._manager.ready.then(function () { | ||
return _this._manager.contents.get(path, opts); | ||
}).then(function (contents) { | ||
if (_this.isDisposed) { | ||
return; | ||
} | ||
var dirty = false; | ||
if (contents.format === 'json') { | ||
model.fromJSON(contents.content); | ||
} | ||
else { | ||
var content = contents.content; | ||
// Convert line endings if necessary, marking the file | ||
// as dirty. | ||
if (content.indexOf('\r') !== -1) { | ||
dirty = true; | ||
content = content.replace(/\r\n|\r/g, '\n'); | ||
} | ||
model.fromString(content); | ||
} | ||
_this._updateContentsModel(contents); | ||
model.dirty = dirty; | ||
if (!_this._isPopulated) { | ||
return _this._populate(); | ||
} | ||
}).catch(function (err) { | ||
var localPath = _this._manager.contents.localPath(_this._path); | ||
var name = coreutils_2.PathExt.basename(localPath); | ||
_this._handleError(err, "File Load Error for " + name); | ||
throw err; | ||
return this.ready.then(function () { | ||
return _this._revert(); | ||
}); | ||
@@ -486,2 +427,4 @@ }; | ||
this._isPopulated = true; | ||
this._isReady = true; | ||
this._populatedPromise.resolve(void 0); | ||
// Add a checkpoint if none exists and the file is writable. | ||
@@ -495,9 +438,99 @@ return this._maybeCheckpoint(false).then(function () { | ||
_this.session.kernelPreference = __assign({}, _this.session.kernelPreference, { name: name, language: _this._model.defaultKernelLanguage }); | ||
return _this.session.initialize(); | ||
}).then(function () { | ||
_this._isReady = true; | ||
_this._populatedPromise.resolve(void 0); | ||
_this.session.initialize(); | ||
}); | ||
}; | ||
/** | ||
* Save the document contents to disk. | ||
*/ | ||
Context.prototype._save = function () { | ||
var _this = this; | ||
var model = this._model; | ||
var content; | ||
if (this._factory.fileFormat === 'json') { | ||
content = model.toJSON(); | ||
} | ||
else { | ||
content = model.toString(); | ||
} | ||
var options = { | ||
type: this._factory.contentType, | ||
format: this._factory.fileFormat, | ||
content: content | ||
}; | ||
return this._manager.ready.then(function () { | ||
if (!model.modelDB.isCollaborative) { | ||
return _this._maybeSave(options); | ||
} | ||
return _this._manager.contents.save(_this._path, options); | ||
}).then(function (value) { | ||
if (_this.isDisposed) { | ||
return; | ||
} | ||
model.dirty = false; | ||
_this._updateContentsModel(value); | ||
if (!_this._isPopulated) { | ||
return _this._populate(); | ||
} | ||
}).catch(function (err) { | ||
// If the save has been canceled by the user, | ||
// throw the error so that whoever called save() | ||
// can decide what to do. | ||
if (err.message === 'Cancel') { | ||
throw err; | ||
} | ||
// Otherwise show an error message and throw the error. | ||
var localPath = _this._manager.contents.localPath(_this._path); | ||
var name = coreutils_2.PathExt.basename(localPath); | ||
_this._handleError(err, "File Save Error for " + name); | ||
throw err; | ||
}); | ||
}; | ||
/** | ||
* Revert the document contents to disk contents. | ||
*/ | ||
Context.prototype._revert = function () { | ||
var _this = this; | ||
var opts = { | ||
format: this._factory.fileFormat, | ||
type: this._factory.contentType, | ||
content: true | ||
}; | ||
var path = this._path; | ||
var model = this._model; | ||
return this._manager.ready.then(function () { | ||
return _this._manager.contents.get(path, opts); | ||
}).then(function (contents) { | ||
if (_this.isDisposed) { | ||
return; | ||
} | ||
var dirty = false; | ||
if (contents.format === 'json') { | ||
model.fromJSON(contents.content); | ||
} | ||
else { | ||
var content = contents.content; | ||
// Convert line endings if necessary, marking the file | ||
// as dirty. | ||
if (content.indexOf('\r') !== -1) { | ||
dirty = true; | ||
content = content.replace(/\r\n|\r/g, '\n'); | ||
} | ||
model.fromString(content); | ||
} | ||
_this._updateContentsModel(contents); | ||
model.dirty = dirty; | ||
if (!_this._isPopulated) { | ||
return _this._populate(); | ||
} | ||
}).catch(function (err) { | ||
var localPath = _this._manager.contents.localPath(_this._path); | ||
var name = coreutils_2.PathExt.basename(localPath); | ||
if (err.message === 'Invalid response: 400 bad format') { | ||
err = new Error('JupyterLab is unable to open this file type.'); | ||
} | ||
_this._handleError(err, "File Load Error for " + name); | ||
throw err; | ||
}); | ||
}; | ||
/** | ||
* Save a file, dealing with conflicts. | ||
@@ -512,3 +545,3 @@ */ | ||
if (_this.isDisposed) { | ||
return Promise.reject('Disposed'); | ||
return Promise.reject(new Error('Disposed')); | ||
} | ||
@@ -595,3 +628,3 @@ // We want to check last_modified (disk) > last_modified (client) | ||
var body = "The file has changed on disk since the last time it " + | ||
"ws opened or saved. " + | ||
"was opened or saved. " + | ||
"Do you want to overwrite the file on disk with the version " + | ||
@@ -606,3 +639,3 @@ " open here, or load the version on disk (revert)?"; | ||
if (_this.isDisposed) { | ||
return Promise.reject('Disposed'); | ||
return Promise.reject(new Error('Disposed')); | ||
} | ||
@@ -612,5 +645,6 @@ if (result.button.label === 'OVERWRITE') { | ||
} | ||
else if (result.button.label === 'REVERT') { | ||
if (result.button.label === 'REVERT') { | ||
return _this.revert().then(function () { return model; }); | ||
} | ||
return Promise.reject(new Error('Cancel')); // Otherwise cancel the save. | ||
}); | ||
@@ -630,3 +664,3 @@ }; | ||
if (_this.isDisposed) { | ||
return Promise.reject('Disposed'); | ||
return Promise.reject(new Error('Disposed')); | ||
} | ||
@@ -633,0 +667,0 @@ if (result.button.label === 'OVERWRITE') { |
@@ -566,8 +566,2 @@ "use strict"; | ||
{ | ||
name: 'xls', | ||
displayName: 'Spreadsheet', | ||
extensions: ['.xls'], | ||
iconClass: 'jp-MaterialIcon jp-SpreadsheetIcon' | ||
}, | ||
{ | ||
name: 'r', | ||
@@ -574,0 +568,0 @@ displayName: 'R File', |
{ | ||
"name": "@jupyterlab/docregistry", | ||
"version": "0.15.5", | ||
"version": "0.16.0", | ||
"description": "JupyterLab - Document Registry", | ||
@@ -33,10 +33,10 @@ "homepage": "https://github.com/jupyterlab/jupyterlab", | ||
"dependencies": { | ||
"@jupyterlab/apputils": "^0.15.5", | ||
"@jupyterlab/codeeditor": "^0.15.4", | ||
"@jupyterlab/codemirror": "^0.15.4", | ||
"@jupyterlab/coreutils": "^1.0.6", | ||
"@jupyterlab/observables": "^1.0.6", | ||
"@jupyterlab/rendermime": "^0.15.4", | ||
"@jupyterlab/rendermime-interfaces": "^1.0.6", | ||
"@jupyterlab/services": "^1.1.4", | ||
"@jupyterlab/apputils": "^0.16.0", | ||
"@jupyterlab/codeeditor": "^0.15.5", | ||
"@jupyterlab/codemirror": "^0.16.0", | ||
"@jupyterlab/coreutils": "^1.1.0", | ||
"@jupyterlab/observables": "^1.0.7", | ||
"@jupyterlab/rendermime": "^0.16.0", | ||
"@jupyterlab/rendermime-interfaces": "^1.0.7", | ||
"@jupyterlab/services": "^2.0.0", | ||
"@phosphor/algorithm": "^1.1.2", | ||
@@ -43,0 +43,0 @@ "@phosphor/coreutils": "^1.3.0", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
227518
3285
1
+ Added@jupyterlab/apputils@0.16.4(transitive)
+ Added@jupyterlab/codeeditor@0.16.2(transitive)
+ Added@jupyterlab/codemirror@0.16.3(transitive)
+ Added@jupyterlab/rendermime@0.16.3(transitive)
+ Added@jupyterlab/services@2.0.3(transitive)
+ Addedansi_up@3.0.0(transitive)
+ Addedcodemirror@5.35.0(transitive)
+ Addedreact@16.2.0(transitive)
+ Addedreact-dom@16.2.1(transitive)
- Removed@jupyterlab/apputils@0.15.5(transitive)
- Removed@jupyterlab/codemirror@0.15.4(transitive)
- Removed@jupyterlab/rendermime@0.15.4(transitive)
- Removed@jupyterlab/services@1.1.4(transitive)
- Removedansi_up@1.3.0(transitive)
- Removedcodemirror@5.24.2(transitive)
- Removedreact@16.0.0(transitive)
- Removedreact-dom@16.0.1(transitive)
Updated@jupyterlab/apputils@^0.16.0
Updated@jupyterlab/coreutils@^1.1.0
Updated@jupyterlab/services@^2.0.0