@jupyterlab/docregistry
Advanced tools
Comparing version 4.0.0-alpha.17 to 4.0.0-alpha.18
import { ISessionContext, SessionContext } from '@jupyterlab/apputils'; | ||
import { IDocumentProviderFactory } from '@jupyterlab/docprovider'; | ||
import { IRenderMime } from '@jupyterlab/rendermime-interfaces'; | ||
@@ -227,2 +226,5 @@ import { Contents, ServiceManager } from '@jupyterlab/services'; | ||
protected translator: ITranslator; | ||
private _isReady; | ||
private _isDisposed; | ||
private _isPopulated; | ||
private _trans; | ||
@@ -238,5 +240,2 @@ private _manager; | ||
private _populatedPromise; | ||
private _isPopulated; | ||
private _isReady; | ||
private _isDisposed; | ||
private _pathChanged; | ||
@@ -247,3 +246,2 @@ private _fileChanged; | ||
private _dialogs; | ||
private _provider; | ||
private _lastModifiedCheckMargin; | ||
@@ -277,6 +275,2 @@ private _timeConflictModalIsOpen; | ||
/** | ||
* An factory method for the document provider. | ||
*/ | ||
docProviderFactory?: IDocumentProviderFactory<ISharedDocument>; | ||
/** | ||
* An optional callback for opening sibling widgets. | ||
@@ -283,0 +277,0 @@ */ |
@@ -6,3 +6,2 @@ // Copyright (c) Jupyter Development Team. | ||
import { PathExt } from '@jupyterlab/coreutils'; | ||
import { ProviderMock } from '@jupyterlab/docprovider'; | ||
import { RenderMimeRegistry } from '@jupyterlab/rendermime'; | ||
@@ -24,2 +23,5 @@ import { nullTranslator } from '@jupyterlab/translation'; | ||
constructor(options) { | ||
this._isReady = false; | ||
this._isDisposed = false; | ||
this._isPopulated = false; | ||
this._path = ''; | ||
@@ -29,5 +31,2 @@ this._lineEnding = null; | ||
this._populatedPromise = new PromiseDelegate(); | ||
this._isPopulated = false; | ||
this._isReady = false; | ||
this._isDisposed = false; | ||
this._pathChanged = new Signal(this); | ||
@@ -49,13 +48,14 @@ this._fileChanged = new Signal(this); | ||
const lang = this._factory.preferredLanguage(PathExt.basename(localPath)); | ||
this._model = this._factory.createNew(lang, PageConfig.getOption('collaborative') === 'true'); | ||
const docProviderFactory = options.docProviderFactory; | ||
this._provider = docProviderFactory | ||
? docProviderFactory({ | ||
path: this._path, | ||
contentType: this._factory.contentType, | ||
format: this._factory.fileFormat, | ||
model: this._model.sharedModel, | ||
collaborative: this._model.collaborative | ||
}) | ||
: new ProviderMock(); | ||
const sharedFactory = this._manager.contents.getSharedModelFactory(this._path); | ||
const sharedModel = sharedFactory === null || sharedFactory === void 0 ? void 0 : sharedFactory.createNew({ | ||
path: localPath, | ||
format: this._factory.fileFormat, | ||
contentType: this._factory.contentType, | ||
collaborative: this._factory.collaborative | ||
}); | ||
this._model = this._factory.createNew({ | ||
languagePreference: lang, | ||
sharedModel, | ||
collaborationEnabled: PageConfig.getOption('collaborative') === 'true' | ||
}); | ||
this._readyPromise = manager.ready.then(() => { | ||
@@ -80,3 +80,2 @@ return this._populatedPromise.promise; | ||
}); | ||
this.model.sharedModel.setState('path', this._path); | ||
this.model.sharedModel.changed.connect(this.onStateChanged, this); | ||
@@ -172,3 +171,4 @@ } | ||
this._model.dispose(); | ||
this._provider.dispose(); | ||
// Ensure we dispose the `sharedModel` as it may have been generated in the context | ||
// through the shared model factory. | ||
this._model.sharedModel.dispose(); | ||
@@ -364,9 +364,26 @@ this._disposed.emit(void 0); | ||
changes.stateChange.forEach(change => { | ||
var _a; | ||
if (change.name === 'path' && change.newValue !== change.oldValue) { | ||
this.urlResolver.path = | ||
change.newValue; | ||
this._path = change.newValue; | ||
(_a = this.sessionContext.session) === null || _a === void 0 ? void 0 : _a.setPath(change.newValue); | ||
this._pathChanged.emit(this.path); | ||
var _a, _b; | ||
if (change.name === 'path') { | ||
const driveName = this._manager.contents.driveName(this._path); | ||
let newPath = change.newValue; | ||
if (driveName) { | ||
newPath = `${driveName}:${change.newValue}`; | ||
} | ||
if (this._path !== newPath) { | ||
this._path = newPath; | ||
const localPath = this._manager.contents.localPath(newPath); | ||
const name = PathExt.basename(localPath); | ||
(_a = this.sessionContext.session) === null || _a === void 0 ? void 0 : _a.setPath(newPath); | ||
void ((_b = this.sessionContext.session) === null || _b === void 0 ? void 0 : _b.setName(name)); | ||
this.urlResolver.path = newPath; | ||
if (this._contentsModel) { | ||
const contentsModel = { | ||
...this._contentsModel, | ||
name: name, | ||
path: newPath | ||
}; | ||
this._updateContentsModel(contentsModel); | ||
} | ||
this._pathChanged.emit(newPath); | ||
} | ||
} | ||
@@ -400,3 +417,2 @@ }); | ||
this._path = newPath; | ||
void ((_b = this.sessionContext.session) === null || _b === void 0 ? void 0 : _b.setPath(newPath)); | ||
const updateModel = { | ||
@@ -407,5 +423,8 @@ ...this._contentsModel, | ||
const localPath = this._manager.contents.localPath(newPath); | ||
void ((_b = this.sessionContext.session) === null || _b === void 0 ? void 0 : _b.setPath(newPath)); | ||
void ((_c = this.sessionContext.session) === null || _c === void 0 ? void 0 : _c.setName(PathExt.basename(localPath))); | ||
this.urlResolver.path = newPath; | ||
this._updateContentsModel(updateModel); | ||
this._model.sharedModel.setState('path', this._path); | ||
this._model.sharedModel.setState('path', localPath); | ||
this._pathChanged.emit(newPath); | ||
} | ||
@@ -423,3 +442,15 @@ } | ||
this._path = path; | ||
this._model.sharedModel.setState('path', this._path); | ||
const localPath = this._manager.contents.localPath(path); | ||
const name = PathExt.basename(localPath); | ||
this.urlResolver.path = path; | ||
if (this._contentsModel) { | ||
const contentsModel = { | ||
...this._contentsModel, | ||
name: name, | ||
path: path | ||
}; | ||
this._updateContentsModel(contentsModel); | ||
} | ||
this._model.sharedModel.setState('path', localPath); | ||
this._pathChanged.emit(path); | ||
} | ||
@@ -454,3 +485,2 @@ } | ||
async _populate() { | ||
await this._provider.ready; | ||
this._isPopulated = true; | ||
@@ -495,2 +525,3 @@ this._isReady = true; | ||
} | ||
// rename triggers a fileChanged which updates the contents model | ||
await this._manager.contents.rename(this.path, newPath); | ||
@@ -500,3 +531,6 @@ await ((_a = this.sessionContext.session) === null || _a === void 0 ? void 0 : _a.setPath(newPath)); | ||
this._path = newPath; | ||
this._model.sharedModel.setState('path', this._path); | ||
const localPath = this._manager.contents.localPath(this._path); | ||
this.urlResolver.path = newPath; | ||
this._model.sharedModel.setState('path', localPath); | ||
this._pathChanged.emit(newPath); | ||
} | ||
@@ -799,3 +833,7 @@ /** | ||
// we must rename the document before saving with the new path | ||
this._model.sharedModel.setState('path', this._path); | ||
const localPath = this._manager.contents.localPath(this._path); | ||
this.urlResolver.path = newPath; | ||
this._model.sharedModel.setState('path', localPath); | ||
this._pathChanged.emit(newPath); | ||
// save triggers a fileChanged which updates the contents model | ||
await this.save(); | ||
@@ -802,0 +840,0 @@ await this._maybeCheckpoint(true); |
@@ -18,3 +18,3 @@ import { MainAreaWidget } from '@jupyterlab/apputils'; | ||
*/ | ||
constructor(languagePreference?: string, collaborationEnabled?: boolean); | ||
constructor(options?: DocumentRegistry.IModelOptions<ISharedFile>); | ||
/** | ||
@@ -151,3 +151,3 @@ * A signal emitted when the document content changes. | ||
*/ | ||
createNew(languagePreference?: string, collaborationEnabled?: boolean): DocumentRegistry.ICodeModel; | ||
createNew(options?: DocumentRegistry.IModelOptions<ISharedFile>): DocumentRegistry.ICodeModel; | ||
/** | ||
@@ -154,0 +154,0 @@ * Get the preferred kernel language given a file path. |
@@ -16,4 +16,5 @@ // Copyright (c) Jupyter Development Team. | ||
*/ | ||
constructor(languagePreference, collaborationEnabled) { | ||
super(); | ||
constructor(options = {}) { | ||
var _a; | ||
super({ sharedModel: options.sharedModel }); | ||
this._defaultLang = ''; | ||
@@ -24,5 +25,5 @@ this._dirty = false; | ||
this._stateChanged = new Signal(this); | ||
this._defaultLang = languagePreference || ''; | ||
this._defaultLang = (_a = options.languagePreference) !== null && _a !== void 0 ? _a : ''; | ||
this._collaborationEnabled = !!options.collaborationEnabled; | ||
this.sharedModel.changed.connect(this._onStateChanged, this); | ||
this._collaborationEnabled = !!collaborationEnabled; | ||
} | ||
@@ -233,5 +234,8 @@ /** | ||
*/ | ||
createNew(languagePreference, collaborationEnabled) { | ||
const collaborative = collaborationEnabled && this.collaborative; | ||
return new DocumentModel(languagePreference, collaborative); | ||
createNew(options = {}) { | ||
const collaborative = options.collaborationEnabled && this.collaborative; | ||
return new DocumentModel({ | ||
...options, | ||
collaborationEnabled: collaborative | ||
}); | ||
} | ||
@@ -238,0 +242,0 @@ /** |
@@ -585,3 +585,3 @@ import { ISessionContext, ToolbarRegistry } from '@jupyterlab/apputils'; | ||
*/ | ||
interface IModelFactory<T extends IModel> extends IDisposable { | ||
interface IModelFactory<T extends IModel, U extends ISharedDocument = ISharedDocument> extends IDisposable { | ||
/** | ||
@@ -606,7 +606,7 @@ * The name of the model. | ||
* | ||
* @param languagePreference - An optional kernel language preference. | ||
* @param options - Optional parameters to construct the model. | ||
* | ||
* @returns A new document model. | ||
*/ | ||
createNew(languagePreference?: string, collaborationEnabled?: boolean): T; | ||
createNew(options?: IModelOptions<U>): T; | ||
/** | ||
@@ -618,2 +618,19 @@ * Get the preferred kernel language given a file path. | ||
/** | ||
* The options used to create a document model. | ||
*/ | ||
interface IModelOptions<T extends ISharedDocument = ISharedDocument> { | ||
/** | ||
* The preferred language. | ||
*/ | ||
languagePreference?: string; | ||
/** | ||
* The shared model. | ||
*/ | ||
sharedModel?: T; | ||
/** | ||
* Whether the model is collaborative or not. | ||
*/ | ||
collaborationEnabled?: boolean; | ||
} | ||
/** | ||
* A type alias for a standard model factory. | ||
@@ -620,0 +637,0 @@ */ |
{ | ||
"name": "@jupyterlab/docregistry", | ||
"version": "4.0.0-alpha.17", | ||
"version": "4.0.0-alpha.18", | ||
"description": "JupyterLab - Document Registry", | ||
@@ -44,14 +44,13 @@ "homepage": "https://github.com/jupyterlab/jupyterlab", | ||
"dependencies": { | ||
"@jupyter/ydoc": "~0.2.2", | ||
"@jupyterlab/apputils": "^4.0.0-alpha.17", | ||
"@jupyterlab/codeeditor": "^4.0.0-alpha.17", | ||
"@jupyterlab/codemirror": "^4.0.0-alpha.17", | ||
"@jupyterlab/coreutils": "^6.0.0-alpha.17", | ||
"@jupyterlab/docprovider": "^4.0.0-alpha.17", | ||
"@jupyterlab/observables": "^5.0.0-alpha.17", | ||
"@jupyterlab/rendermime": "^4.0.0-alpha.17", | ||
"@jupyterlab/rendermime-interfaces": "^3.8.0-alpha.17", | ||
"@jupyterlab/services": "^7.0.0-alpha.17", | ||
"@jupyterlab/translation": "^4.0.0-alpha.17", | ||
"@jupyterlab/ui-components": "^4.0.0-alpha.32", | ||
"@jupyter/ydoc": "^0.3.1", | ||
"@jupyterlab/apputils": "^4.0.0-alpha.18", | ||
"@jupyterlab/codeeditor": "^4.0.0-alpha.18", | ||
"@jupyterlab/codemirror": "^4.0.0-alpha.18", | ||
"@jupyterlab/coreutils": "^6.0.0-alpha.18", | ||
"@jupyterlab/observables": "^5.0.0-alpha.18", | ||
"@jupyterlab/rendermime": "^4.0.0-alpha.18", | ||
"@jupyterlab/rendermime-interfaces": "^3.8.0-alpha.18", | ||
"@jupyterlab/services": "^7.0.0-alpha.18", | ||
"@jupyterlab/translation": "^4.0.0-alpha.18", | ||
"@jupyterlab/ui-components": "^4.0.0-alpha.33", | ||
"@lumino/algorithm": "^2.0.0-alpha.6", | ||
@@ -66,3 +65,3 @@ "@lumino/coreutils": "^2.0.0-alpha.6", | ||
"devDependencies": { | ||
"@jupyterlab/testing": "^4.0.0-alpha.17", | ||
"@jupyterlab/testing": "^4.0.0-alpha.18", | ||
"@types/jest": "^29.2.0", | ||
@@ -69,0 +68,0 @@ "rimraf": "~3.0.0", |
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
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
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
212416
18
4330
- Removed@jupyter/ydoc@0.2.5(transitive)
- Removed@jupyterlab/docprovider@4.0.0-alpha.18(transitive)
- Removedabstract-leveldown@6.2.3(transitive)
- Removedasync-limiter@1.0.1(transitive)
- Removedbase64-js@1.5.1(transitive)
- Removedbuffer@5.7.1(transitive)
- Removeddeferred-leveldown@5.3.0(transitive)
- Removedencoding-down@6.3.0(transitive)
- Removederrno@0.1.8(transitive)
- Removedieee754@1.2.1(transitive)
- Removedimmediate@3.3.0(transitive)
- Removedinherits@2.0.4(transitive)
- Removedlevel@6.0.1(transitive)
- Removedlevel-codec@9.0.2(transitive)
- Removedlevel-concat-iterator@2.0.1(transitive)
- Removedlevel-errors@2.0.1(transitive)
- Removedlevel-iterator-stream@4.0.2(transitive)
- Removedlevel-js@5.0.2(transitive)
- Removedlevel-packager@5.1.1(transitive)
- Removedlevel-supports@1.0.1(transitive)
- Removedleveldown@5.6.0(transitive)
- Removedlevelup@4.4.0(transitive)
- Removedlodash.debounce@4.0.8(transitive)
- Removedltgt@2.2.1(transitive)
- Removednapi-macros@2.0.0(transitive)
- Removednode-gyp-build@4.1.1(transitive)
- Removedprr@1.0.1(transitive)
- Removedreadable-stream@3.6.2(transitive)
- Removedsafe-buffer@5.2.1(transitive)
- Removedstring_decoder@1.3.0(transitive)
- Removedutil-deprecate@1.0.2(transitive)
- Removedws@6.2.3(transitive)
- Removedxtend@4.0.2(transitive)
- Removedy-leveldb@0.1.2(transitive)
- Removedy-websocket@1.5.4(transitive)
Updated@jupyter/ydoc@^0.3.1