@jupyter/docprovider 2.0.0 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/utils.d.ts +0 -8
- package/lib/utils.js +0 -9
- package/lib/yprovider.d.ts +0 -5
- package/lib/yprovider.js +0 -58
- package/package.json +1 -1
package/lib/utils.d.ts
CHANGED
package/lib/utils.js
CHANGED
|
@@ -4,14 +4,5 @@
|
|
|
4
4
|
|----------------------------------------------------------------------------*/
|
|
5
5
|
export var MessageType;
|
|
6
6
|
(function (MessageType) {
|
|
7
|
-
MessageType[MessageType["ROOM"] = 124] = "ROOM";
|
|
8
7
|
MessageType[MessageType["CHAT"] = 125] = "CHAT";
|
|
9
8
|
})(MessageType || (MessageType = {}));
|
|
10
|
-
export var RoomMessage;
|
|
11
|
-
(function (RoomMessage) {
|
|
12
|
-
RoomMessage[RoomMessage["RELOAD"] = 0] = "RELOAD";
|
|
13
|
-
RoomMessage[RoomMessage["OVERWRITE"] = 1] = "OVERWRITE";
|
|
14
|
-
RoomMessage[RoomMessage["FILE_CHANGED"] = 2] = "FILE_CHANGED";
|
|
15
|
-
RoomMessage[RoomMessage["FILE_OVERWRITTEN"] = 3] = "FILE_OVERWRITTEN";
|
|
16
|
-
RoomMessage[RoomMessage["DOC_OVERWRITTEN"] = 4] = "DOC_OVERWRITTEN";
|
|
17
|
-
})(RoomMessage || (RoomMessage = {}));
|
package/lib/yprovider.d.ts
CHANGED
|
@@ -40,11 +40,6 @@ export declare class WebSocketProvider implements IDocumentProvider {
|
|
|
40
40
|
private _onUserChanged;
|
|
41
41
|
private _onConnectionClosed;
|
|
42
42
|
private _onSync;
|
|
43
|
-
private _handleRoomMessage;
|
|
44
|
-
private _handleFileChanged;
|
|
45
|
-
private _sendReloadMsg;
|
|
46
|
-
private _sendOverwriteMsg;
|
|
47
|
-
private _dialog;
|
|
48
43
|
private _awareness;
|
|
49
44
|
private _contentType;
|
|
50
45
|
private _format;
|
package/lib/yprovider.js
CHANGED
|
@@ -5,11 +5,8 @@
|
|
|
5
5
|
import { showErrorMessage, Dialog } from '@jupyterlab/apputils';
|
|
6
6
|
import { PromiseDelegate } from '@lumino/coreutils';
|
|
7
7
|
import { Signal } from '@lumino/signaling';
|
|
8
|
-
import * as decoding from 'lib0/decoding';
|
|
9
|
-
import * as encoding from 'lib0/encoding';
|
|
10
8
|
import { WebsocketProvider as YWebsocketProvider } from 'y-websocket';
|
|
11
9
|
import { requestDocSession } from './requests';
|
|
12
|
-
import { MessageType, RoomMessage } from './utils';
|
|
13
10
|
/**
|
|
14
11
|
* A class to provide Yjs synchronization over WebSocket.
|
|
15
12
|
*
|
|
@@ -41,7 +38,6 @@ export class WebSocketProvider {
|
|
|
41
38
|
(_a = this._yWebsocketProvider) === null || _a === void 0 ? void 0 : _a.off('sync', this._onSync);
|
|
42
39
|
}
|
|
43
40
|
};
|
|
44
|
-
this._dialog = null;
|
|
45
41
|
this._ready = new PromiseDelegate();
|
|
46
42
|
this._isDisposed = false;
|
|
47
43
|
this._path = options.path;
|
|
@@ -96,62 +92,8 @@ export class WebSocketProvider {
|
|
|
96
92
|
});
|
|
97
93
|
this._yWebsocketProvider.on('sync', this._onSync);
|
|
98
94
|
this._yWebsocketProvider.on('connection-close', this._onConnectionClosed);
|
|
99
|
-
this._yWebsocketProvider.messageHandlers[MessageType.ROOM] = (encoder, decoder, provider, emitSynced, messageType) => {
|
|
100
|
-
const msgType = decoding.readVarUint(decoder);
|
|
101
|
-
const data = decoding.readVarString(decoder);
|
|
102
|
-
this._handleRoomMessage(msgType, data);
|
|
103
|
-
};
|
|
104
95
|
}
|
|
105
96
|
_onUserChanged(user) {
|
|
106
97
|
this._awareness.setLocalStateField('user', user.identity);
|
|
107
98
|
}
|
|
108
|
-
_handleRoomMessage(type, data) {
|
|
109
|
-
switch (type) {
|
|
110
|
-
case RoomMessage.FILE_CHANGED:
|
|
111
|
-
this._handleFileChanged(data);
|
|
112
|
-
break;
|
|
113
|
-
case RoomMessage.DOC_OVERWRITTEN:
|
|
114
|
-
case RoomMessage.FILE_OVERWRITTEN:
|
|
115
|
-
if (this._dialog) {
|
|
116
|
-
this._dialog.close();
|
|
117
|
-
this._dialog = null;
|
|
118
|
-
}
|
|
119
|
-
break;
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
_handleFileChanged(data) {
|
|
123
|
-
this._dialog = new Dialog({
|
|
124
|
-
title: this._trans.__('File changed'),
|
|
125
|
-
body: this._trans.__('Do you want to overwrite the file or reload it?'),
|
|
126
|
-
buttons: [
|
|
127
|
-
Dialog.okButton({ label: 'Reload' }),
|
|
128
|
-
Dialog.warnButton({ label: 'Overwrite' })
|
|
129
|
-
],
|
|
130
|
-
hasClose: false
|
|
131
|
-
});
|
|
132
|
-
this._dialog.launch().then(resp => {
|
|
133
|
-
if (resp.button.label === 'Reload') {
|
|
134
|
-
this._sendReloadMsg(data);
|
|
135
|
-
}
|
|
136
|
-
else if (resp.button.label === 'Overwrite') {
|
|
137
|
-
this._sendOverwriteMsg(data);
|
|
138
|
-
}
|
|
139
|
-
});
|
|
140
|
-
}
|
|
141
|
-
_sendReloadMsg(data) {
|
|
142
|
-
var _a;
|
|
143
|
-
const encoder = encoding.createEncoder();
|
|
144
|
-
encoding.writeVarUint(encoder, MessageType.ROOM);
|
|
145
|
-
encoding.writeVarUint(encoder, RoomMessage.RELOAD);
|
|
146
|
-
encoding.writeVarString(encoder, data);
|
|
147
|
-
(_a = this._yWebsocketProvider) === null || _a === void 0 ? void 0 : _a.ws.send(encoding.toUint8Array(encoder));
|
|
148
|
-
}
|
|
149
|
-
_sendOverwriteMsg(data) {
|
|
150
|
-
var _a;
|
|
151
|
-
const encoder = encoding.createEncoder();
|
|
152
|
-
encoding.writeVarUint(encoder, MessageType.ROOM);
|
|
153
|
-
encoding.writeVarUint(encoder, RoomMessage.OVERWRITE);
|
|
154
|
-
encoding.writeVarString(encoder, data);
|
|
155
|
-
(_a = this._yWebsocketProvider) === null || _a === void 0 ? void 0 : _a.ws.send(encoding.toUint8Array(encoder));
|
|
156
|
-
}
|
|
157
99
|
}
|