@jupyterlab/docprovider
Advanced tools
Comparing version 3.1.0-alpha.13 to 3.1.0-beta.0
@@ -8,2 +8,3 @@ import { IDocumentProvider } from './index'; | ||
destroy(): void; | ||
setPath(path: string): void; | ||
} |
@@ -17,3 +17,6 @@ export class ProviderMock { | ||
} | ||
setPath(path) { | ||
/* nop */ | ||
} | ||
} | ||
//# sourceMappingURL=mock.js.map |
@@ -31,2 +31,6 @@ import { DocumentChange, YDocument } from '@jupyterlab/shared-models'; | ||
/** | ||
* This should be called by the docregistry when the file has been renamed to update the websocket connection url | ||
*/ | ||
setPath(newPath: string): void; | ||
/** | ||
* Destroy the provider. | ||
@@ -51,3 +55,4 @@ */ | ||
*/ | ||
guid: string; | ||
path: string; | ||
contentType: string; | ||
/** | ||
@@ -54,0 +59,0 @@ * The YNotebook. |
import { WebsocketProvider } from 'y-websocket'; | ||
import { IDocumentProviderFactory } from './tokens'; | ||
import { IDocumentProvider, IDocumentProviderFactory } from './tokens'; | ||
/** | ||
* A class to provide Yjs synchronization over WebSocket. | ||
* | ||
* The user can specify their own user-name and user-color by adding urlparameters: | ||
* ?username=Alice&usercolor=007007 | ||
* wher usercolor must be a six-digit hexadicimal encoded RGB value without the hash token. | ||
* | ||
* We specify custom messages that the server can interpret. For reference please look in yjs_ws_server. | ||
* | ||
*/ | ||
export declare class WebSocketProviderWithLocks extends WebsocketProvider { | ||
export declare class WebSocketProviderWithLocks extends WebsocketProvider implements IDocumentProvider { | ||
/** | ||
@@ -13,2 +20,3 @@ * Construct a new WebSocketProviderWithLocks | ||
constructor(options: WebSocketProviderWithLocks.IOptions); | ||
setPath(newPath: string): void; | ||
/** | ||
@@ -45,2 +53,5 @@ * Resolves to true if the initial content has been initialized on the server. false otherwise. | ||
private _onConnectionStatus; | ||
private _path; | ||
private _contentType; | ||
private _serverUrl; | ||
private _isInitialized; | ||
@@ -47,0 +58,0 @@ private _currentLockRequest; |
@@ -9,4 +9,13 @@ /* ----------------------------------------------------------------------------- | ||
import * as Y from 'yjs'; | ||
import { getAnonymousUserName, getRandomColor } from './awareness'; | ||
import * as env from 'lib0/environment'; | ||
/** | ||
* A class to provide Yjs synchronization over WebSocket. | ||
* | ||
* The user can specify their own user-name and user-color by adding urlparameters: | ||
* ?username=Alice&usercolor=007007 | ||
* wher usercolor must be a six-digit hexadicimal encoded RGB value without the hash token. | ||
* | ||
* We specify custom messages that the server can interpret. For reference please look in yjs_ws_server. | ||
* | ||
*/ | ||
@@ -20,3 +29,3 @@ export class WebSocketProviderWithLocks extends WebsocketProvider { | ||
constructor(options) { | ||
super(options.url, options.guid, options.ymodel.ydoc, { | ||
super(options.url, options.contentType + ':' + options.path, options.ymodel.ydoc, { | ||
awareness: options.ymodel.awareness | ||
@@ -26,2 +35,16 @@ }); | ||
this._initialContentRequest = null; | ||
this._path = options.path; | ||
this._contentType = options.contentType; | ||
this._serverUrl = options.url; | ||
const color = '#' + env.getParam('--usercolor', getRandomColor().slice(1)); | ||
const name = env.getParam('--username', getAnonymousUserName()); | ||
const awareness = options.ymodel.awareness; | ||
const currState = awareness.getLocalState(); | ||
// only set if this was not already set by another plugin | ||
if (currState && currState.name == null) { | ||
options.ymodel.awareness.setLocalStateField('user', { | ||
name, | ||
color | ||
}); | ||
} | ||
// Message handler that confirms when a lock has been acquired | ||
@@ -57,2 +80,20 @@ this.messageHandlers[127] = (encoder, decoder, provider, emitSynced, messageType) => { | ||
} | ||
setPath(newPath) { | ||
if (newPath !== this._path) { | ||
this._path = newPath; | ||
// The next time the provider connects, we should connect through a different server url | ||
this.bcChannel = | ||
this._serverUrl + '/' + this._contentType + ':' + this._path; | ||
this.url = this.bcChannel; | ||
const encoder = encoding.createEncoder(); | ||
encoding.write(encoder, 123); | ||
// writing a utf8 string to the encoder | ||
const escapedPath = unescape(encodeURIComponent(this._contentType + ':' + newPath)); | ||
for (let i = 0; i < escapedPath.length; i++) { | ||
encoding.write(encoder, | ||
/** @type {number} */ escapedPath.codePointAt(i)); | ||
} | ||
this._sendMessage(encoding.toUint8Array(encoder)); | ||
} | ||
} | ||
/** | ||
@@ -59,0 +100,0 @@ * Resolves to true if the initial content has been initialized on the server. false otherwise. |
{ | ||
"name": "@jupyterlab/docprovider", | ||
"version": "3.1.0-alpha.13", | ||
"version": "3.1.0-beta.0", | ||
"description": "JupyterLab - Document Provider", | ||
@@ -41,3 +41,3 @@ "homepage": "https://github.com/jupyterlab/jupyterlab", | ||
"dependencies": { | ||
"@jupyterlab/shared-models": "^3.1.0-alpha.13", | ||
"@jupyterlab/shared-models": "^3.1.0-beta.0", | ||
"@lumino/coreutils": "^1.5.3", | ||
@@ -49,3 +49,3 @@ "lib0": "^0.2.42", | ||
"devDependencies": { | ||
"@jupyterlab/testutils": "^3.1.0-alpha.13", | ||
"@jupyterlab/testutils": "^3.1.0-beta.0", | ||
"@types/jest": "^26.0.10", | ||
@@ -60,3 +60,3 @@ "jest": "^26.4.2", | ||
}, | ||
"gitHead": "a7d05695d6fd893a2f0f8c411c930aa4e5ce758f" | ||
"gitHead": "acd4b259a99ca58dbb8a14bfe73d6f5ad2262991" | ||
} |
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
26802
17
493
1