@seafile/comment-editor 0.0.1-alpha.4 → 0.0.1-alpha.5
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/dist/basic-sdk/assets/css/layout.css +1 -45
- package/dist/basic-sdk/comment/utils.js +39 -0
- package/dist/basic-sdk/editor/comment-editor.css +138 -0
- package/dist/basic-sdk/{comment/components → editor}/comment-editor.js +27 -20
- package/dist/basic-sdk/hooks/use-comment.js +8 -169
- package/dist/basic-sdk/index.js +3 -10
- package/dist/index.js +0 -12
- package/dist/pages/seafile-comment-editor.js +15 -8
- package/package.json +1 -1
- package/dist/assets/css/plugin-editor.css +0 -7
- package/dist/assets/css/simple-viewer.css +0 -6
- package/dist/basic-sdk/comment/components/comment-all-participants/index.css +0 -83
- package/dist/basic-sdk/comment/components/comment-all-participants/index.js +0 -67
- package/dist/basic-sdk/comment/components/comment-all-participants/participant-avatar.js +0 -43
- package/dist/basic-sdk/comment/components/comment-delete-popover.js +0 -80
- package/dist/basic-sdk/comment/components/comment-item-collapse-wrapper.js +0 -160
- package/dist/basic-sdk/comment/components/comment-item-content.js +0 -154
- package/dist/basic-sdk/comment/components/comment-item-reply.js +0 -124
- package/dist/basic-sdk/comment/components/comment-item-resolved-reply.js +0 -38
- package/dist/basic-sdk/comment/components/comment-item-wrapper.js +0 -364
- package/dist/basic-sdk/comment/components/comment-list.css +0 -422
- package/dist/basic-sdk/comment/components/comment-list.js +0 -216
- package/dist/basic-sdk/comment/components/comment-participants-editor/index.css +0 -132
- package/dist/basic-sdk/comment/components/comment-participants-editor/index.js +0 -69
- package/dist/basic-sdk/comment/components/comment-participants-editor/searched-collaborators.js +0 -62
- package/dist/basic-sdk/comment/components/comment-participants-editor/selected-participants.js +0 -48
- package/dist/basic-sdk/comment/components/editor-comment.js +0 -183
- package/dist/basic-sdk/comment/components/elements-comment-count/element-comment-count.js +0 -64
- package/dist/basic-sdk/comment/components/elements-comment-count/index.css +0 -29
- package/dist/basic-sdk/comment/components/elements-comment-count/index.js +0 -49
- package/dist/basic-sdk/comment/components/global-comment/global-comment-body-header.js +0 -88
- package/dist/basic-sdk/comment/components/global-comment/global-comment-header.js +0 -90
- package/dist/basic-sdk/comment/components/global-comment/index.css +0 -328
- package/dist/basic-sdk/comment/components/global-comment/index.js +0 -217
- package/dist/basic-sdk/comment/components/index.js +0 -21
- package/dist/basic-sdk/comment/components/style.css +0 -40
- package/dist/basic-sdk/comment/helper.js +0 -184
- package/dist/basic-sdk/comment/hooks/comment-hooks/use-comment-context.js +0 -20
- package/dist/basic-sdk/comment/hooks/comment-hooks/use-comment-list.js +0 -45
- package/dist/basic-sdk/comment/hooks/comment-hooks/use-comment-mount.js +0 -57
- package/dist/basic-sdk/comment/hooks/notification-hooks/index.js +0 -25
- package/dist/basic-sdk/comment/hooks/notification-hooks/use-notification-context.js +0 -20
- package/dist/basic-sdk/comment/hooks/notification-hooks/use-notification-mount.js +0 -70
- package/dist/basic-sdk/comment/hooks/use-participants.js +0 -26
- package/dist/basic-sdk/comment/index.js +0 -21
- package/dist/basic-sdk/comment/reducer/comment-reducer.js +0 -353
- package/dist/basic-sdk/comment/reducer/notification-reducer.js +0 -89
- package/dist/basic-sdk/comment/utils/get-event-transfer.js +0 -77
- package/dist/basic-sdk/comment/utils/index.js +0 -281
- package/dist/basic-sdk/comment/utils/notification-utils.js +0 -62
- package/dist/basic-sdk/socket/helpers.js +0 -299
- package/dist/basic-sdk/socket/index.js +0 -20
- package/dist/basic-sdk/socket/socket-client.js +0 -211
- package/dist/basic-sdk/socket/socket-manager.js +0 -386
- package/dist/basic-sdk/socket/with-socket-io.js +0 -73
- /package/dist/basic-sdk/comment/{constants/index.js → constants.js} +0 -0
|
@@ -1,211 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.default = void 0;
|
|
8
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/defineProperty"));
|
|
9
|
-
var _socket = _interopRequireDefault(require("socket.io-client"));
|
|
10
|
-
var _debug = require("../utils/debug");
|
|
11
|
-
var _socketManager = _interopRequireDefault(require("./socket-manager"));
|
|
12
|
-
class SocketClient {
|
|
13
|
-
constructor(config) {
|
|
14
|
-
var _this = this;
|
|
15
|
-
(0, _defineProperty2.default)(this, "getParams", function () {
|
|
16
|
-
let params = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
17
|
-
const {
|
|
18
|
-
docUuid,
|
|
19
|
-
user
|
|
20
|
-
} = _this.config;
|
|
21
|
-
return {
|
|
22
|
-
doc_uuid: docUuid,
|
|
23
|
-
user,
|
|
24
|
-
...params
|
|
25
|
-
};
|
|
26
|
-
});
|
|
27
|
-
(0, _defineProperty2.default)(this, "onConnected", () => {
|
|
28
|
-
// join room
|
|
29
|
-
this.socket.emit('join-room', result => {
|
|
30
|
-
const socketManager = _socketManager.default.getInstance();
|
|
31
|
-
if (result.success) {
|
|
32
|
-
// sync operations or document
|
|
33
|
-
if (this.isReconnect) {
|
|
34
|
-
this.isReconnect = false;
|
|
35
|
-
// The reconnect of socketManager needs to be triggered after entering the room again
|
|
36
|
-
socketManager.onReconnect(result);
|
|
37
|
-
}
|
|
38
|
-
socketManager.dispatchConnectState('onConnected', result);
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
// Disconnect the server in the client side. There will be no reconnection.
|
|
43
|
-
this.socket.disconnect();
|
|
44
|
-
socketManager.dispatchConnectState('connect-error', result);
|
|
45
|
-
});
|
|
46
|
-
});
|
|
47
|
-
(0, _defineProperty2.default)(this, "onReconnect", data => {
|
|
48
|
-
(0, _debug.clientDebug)('reconnect.');
|
|
49
|
-
this.isReconnect = true;
|
|
50
|
-
const socketManager = _socketManager.default.getInstance();
|
|
51
|
-
socketManager.dispatchConnectState('reconnect');
|
|
52
|
-
});
|
|
53
|
-
(0, _defineProperty2.default)(this, "onReconnectAttempt", attemptNumber => {
|
|
54
|
-
(0, _debug.clientDebug)('reconnect_attempt. %s', attemptNumber);
|
|
55
|
-
const socketManager = _socketManager.default.getInstance();
|
|
56
|
-
socketManager.dispatchConnectState('reconnect_attempt', attemptNumber);
|
|
57
|
-
});
|
|
58
|
-
(0, _defineProperty2.default)(this, "onReconnectError", () => {
|
|
59
|
-
(0, _debug.clientDebug)('reconnect_error.');
|
|
60
|
-
const socketManager = _socketManager.default.getInstance();
|
|
61
|
-
socketManager.dispatchConnectState('reconnect_error');
|
|
62
|
-
});
|
|
63
|
-
(0, _defineProperty2.default)(this, "onDisconnected", data => {
|
|
64
|
-
(0, _debug.clientDebug)('disconnect message: %s', data);
|
|
65
|
-
const socketManager = _socketManager.default.getInstance();
|
|
66
|
-
socketManager.dispatchConnectState('disconnect');
|
|
67
|
-
});
|
|
68
|
-
(0, _defineProperty2.default)(this, "onConnectError", e => {
|
|
69
|
-
(0, _debug.clientDebug)('connect_error.');
|
|
70
|
-
const socketManager = _socketManager.default.getInstance();
|
|
71
|
-
socketManager.dispatchConnectState('connect_error');
|
|
72
|
-
});
|
|
73
|
-
(0, _defineProperty2.default)(this, "sendOperations", (operations, version, selection, callback) => {
|
|
74
|
-
(0, _debug.clientDebug)('send operations: %O', operations);
|
|
75
|
-
this.socket.emit('update-document', this.getParams({
|
|
76
|
-
operations,
|
|
77
|
-
version,
|
|
78
|
-
selection
|
|
79
|
-
}), result => {
|
|
80
|
-
callback && callback(result);
|
|
81
|
-
});
|
|
82
|
-
});
|
|
83
|
-
(0, _defineProperty2.default)(this, "onJoinRoom", userInfo => {
|
|
84
|
-
(0, _debug.serverDebug)('%s joined room success.', userInfo.username);
|
|
85
|
-
const socketManager = _socketManager.default.getInstance();
|
|
86
|
-
socketManager.dispatchConnectState('join-room', userInfo);
|
|
87
|
-
});
|
|
88
|
-
(0, _defineProperty2.default)(this, "onLeaveRoom", username => {
|
|
89
|
-
(0, _debug.serverDebug)('%s leaved room success.', username);
|
|
90
|
-
const socketManager = _socketManager.default.getInstance();
|
|
91
|
-
socketManager.dispatchConnectState('leave-room', username);
|
|
92
|
-
});
|
|
93
|
-
/**
|
|
94
|
-
* receive remote broadcast operations
|
|
95
|
-
* @param {*} params {operations, version}
|
|
96
|
-
*/
|
|
97
|
-
(0, _defineProperty2.default)(this, "onReceiveRemoteOperations", params => {
|
|
98
|
-
(0, _debug.serverDebug)('receive operations: %O', params);
|
|
99
|
-
const socketManager = _socketManager.default.getInstance();
|
|
100
|
-
socketManager.onReceiveRemoteOperations(params);
|
|
101
|
-
});
|
|
102
|
-
(0, _defineProperty2.default)(this, "getRecentOperations", () => {
|
|
103
|
-
const {
|
|
104
|
-
docUuid
|
|
105
|
-
} = this.config;
|
|
106
|
-
const socketManager = _socketManager.default.getInstance();
|
|
107
|
-
const clientVersion = socketManager.getDocumentVersion();
|
|
108
|
-
this.socket.emit('sync-document', {
|
|
109
|
-
doc_uuid: docUuid,
|
|
110
|
-
version: clientVersion
|
|
111
|
-
}, result => {
|
|
112
|
-
if (result.success) {
|
|
113
|
-
socketManager.onGetRecentOperations(result);
|
|
114
|
-
}
|
|
115
|
-
});
|
|
116
|
-
});
|
|
117
|
-
(0, _defineProperty2.default)(this, "sendCursorLocation", location => {
|
|
118
|
-
const {
|
|
119
|
-
cursorData: cursor_data
|
|
120
|
-
} = this.config;
|
|
121
|
-
this.socket.emit('update-cursor', this.getParams({
|
|
122
|
-
location,
|
|
123
|
-
cursor_data
|
|
124
|
-
}));
|
|
125
|
-
});
|
|
126
|
-
(0, _defineProperty2.default)(this, "receiveCursorLocation", params => {
|
|
127
|
-
const socketManager = _socketManager.default.getInstance();
|
|
128
|
-
socketManager.receiveCursorLocation(params);
|
|
129
|
-
});
|
|
130
|
-
(0, _defineProperty2.default)(this, "disconnectWithServer", () => {
|
|
131
|
-
this.socket.disconnect();
|
|
132
|
-
});
|
|
133
|
-
(0, _defineProperty2.default)(this, "receivePublishDocument", () => {
|
|
134
|
-
const socketManager = _socketManager.default.getInstance();
|
|
135
|
-
socketManager.receivePublishDocument();
|
|
136
|
-
});
|
|
137
|
-
(0, _defineProperty2.default)(this, "receivePublishDocumentError", () => {
|
|
138
|
-
const socketManager = _socketManager.default.getInstance();
|
|
139
|
-
socketManager.receivePublishDocumentError();
|
|
140
|
-
});
|
|
141
|
-
(0, _defineProperty2.default)(this, "receiveDocumentReplaced", () => {
|
|
142
|
-
const socketManager = _socketManager.default.getInstance();
|
|
143
|
-
socketManager.receiveDocumentReplaced();
|
|
144
|
-
});
|
|
145
|
-
(0, _defineProperty2.default)(this, "receiveDocumentReplacedError", () => {
|
|
146
|
-
const socketManager = _socketManager.default.getInstance();
|
|
147
|
-
socketManager.receiveDocumentReplacedError();
|
|
148
|
-
});
|
|
149
|
-
(0, _defineProperty2.default)(this, "receiveRemoveDocument", () => {
|
|
150
|
-
const socketManager = _socketManager.default.getInstance();
|
|
151
|
-
socketManager.receiveRemoveDocument();
|
|
152
|
-
});
|
|
153
|
-
(0, _defineProperty2.default)(this, "receiveRemoveDocumentError", () => {
|
|
154
|
-
const socketManager = _socketManager.default.getInstance();
|
|
155
|
-
socketManager.receiveRemoveDocumentError();
|
|
156
|
-
});
|
|
157
|
-
(0, _defineProperty2.default)(this, "receiveNewNotification", notification => {
|
|
158
|
-
const socketManager = _socketManager.default.getInstance();
|
|
159
|
-
socketManager.receiveNewNotification(notification);
|
|
160
|
-
});
|
|
161
|
-
(0, _defineProperty2.default)(this, "receiveParticipantAdded", uses => {
|
|
162
|
-
const socketManager = _socketManager.default.getInstance();
|
|
163
|
-
socketManager.receiveParticipantAdded(uses);
|
|
164
|
-
});
|
|
165
|
-
(0, _defineProperty2.default)(this, "receiveParticipantRemoved", email => {
|
|
166
|
-
const socketManager = _socketManager.default.getInstance();
|
|
167
|
-
socketManager.receiveParticipantRemoved(email);
|
|
168
|
-
});
|
|
169
|
-
this.config = config;
|
|
170
|
-
this.isReconnect = false;
|
|
171
|
-
this.socket = (0, _socket.default)(config.sdocServer, {
|
|
172
|
-
reconnection: true,
|
|
173
|
-
auth: {
|
|
174
|
-
token: config.accessToken
|
|
175
|
-
},
|
|
176
|
-
query: {
|
|
177
|
-
'sdoc_uuid': config.docUuid
|
|
178
|
-
}
|
|
179
|
-
});
|
|
180
|
-
this.socket.on('connect', this.onConnected);
|
|
181
|
-
this.socket.on('disconnect', this.onDisconnected);
|
|
182
|
-
this.socket.on('connect_error', this.onConnectError);
|
|
183
|
-
this.socket.on('join-room', this.onJoinRoom);
|
|
184
|
-
this.socket.on('leave-room', this.onLeaveRoom);
|
|
185
|
-
this.socket.on('update-document', this.onReceiveRemoteOperations);
|
|
186
|
-
|
|
187
|
-
// doc replaced
|
|
188
|
-
this.socket.on('doc-replaced', this.receiveDocumentReplaced);
|
|
189
|
-
this.socket.on('doc-replaced-error', this.receiveDocumentReplacedError);
|
|
190
|
-
|
|
191
|
-
// doc published
|
|
192
|
-
this.socket.on('doc-published', this.receivePublishDocument);
|
|
193
|
-
this.socket.on('doc-published-error', this.receivePublishDocumentError);
|
|
194
|
-
|
|
195
|
-
// doc removed
|
|
196
|
-
this.socket.on('doc-removed', this.receiveRemoveDocument);
|
|
197
|
-
this.socket.on('doc-removed-error', this.receiveRemoveDocumentError);
|
|
198
|
-
this.socket.on('update-cursor', this.receiveCursorLocation);
|
|
199
|
-
|
|
200
|
-
// notification
|
|
201
|
-
this.socket.on('new-notification', this.receiveNewNotification);
|
|
202
|
-
|
|
203
|
-
// participant
|
|
204
|
-
this.socket.on('participant-added', this.receiveParticipantAdded);
|
|
205
|
-
this.socket.on('participant-removed', this.receiveParticipantRemoved);
|
|
206
|
-
this.socket.io.on('reconnect', this.onReconnect);
|
|
207
|
-
this.socket.io.on('reconnect_attempt', this.onReconnectAttempt);
|
|
208
|
-
this.socket.io.on('reconnect_error', this.onReconnectError);
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
var _default = exports.default = SocketClient;
|
|
@@ -1,386 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.default = void 0;
|
|
8
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/defineProperty"));
|
|
9
|
-
var _constants = require("../constants");
|
|
10
|
-
var _helper = require("../cursor/helper");
|
|
11
|
-
var _debug = require("../utils/debug");
|
|
12
|
-
var _eventBus = _interopRequireDefault(require("../utils/event-bus"));
|
|
13
|
-
var _helpers = require("./helpers");
|
|
14
|
-
var _socketClient = _interopRequireDefault(require("./socket-client"));
|
|
15
|
-
var _SocketManager;
|
|
16
|
-
// idle --> sending --> conflict --> idle
|
|
17
|
-
// --> conflict --> idle
|
|
18
|
-
// --> disconnect --> conflict --> idle
|
|
19
|
-
// --> idle
|
|
20
|
-
const STATE = {
|
|
21
|
-
IDLE: 'idle',
|
|
22
|
-
SENDING: 'sending',
|
|
23
|
-
CONFLICT: 'conflict',
|
|
24
|
-
DISCONNECT: 'disconnect',
|
|
25
|
-
NEED_RELOAD: 'need_reload'
|
|
26
|
-
};
|
|
27
|
-
class SocketManager {
|
|
28
|
-
constructor(editor, _document, config) {
|
|
29
|
-
(0, _defineProperty2.default)(this, "getDocumentVersion", () => {
|
|
30
|
-
const {
|
|
31
|
-
version
|
|
32
|
-
} = this.document;
|
|
33
|
-
return version;
|
|
34
|
-
});
|
|
35
|
-
(0, _defineProperty2.default)(this, "updateDocumentVersion", document => {
|
|
36
|
-
this.document['version'] = document.version;
|
|
37
|
-
});
|
|
38
|
-
(0, _defineProperty2.default)(this, "receivePublishDocument", () => {
|
|
39
|
-
this.eventBus.dispatch(_constants.INTERNAL_EVENT.PUBLISH_DOCUMENT);
|
|
40
|
-
});
|
|
41
|
-
(0, _defineProperty2.default)(this, "receivePublishDocumentError", () => {
|
|
42
|
-
this.eventBus.dispatch(_constants.INTERNAL_EVENT.PUBLISH_DOCUMENT_ERROR);
|
|
43
|
-
});
|
|
44
|
-
(0, _defineProperty2.default)(this, "receiveRemoveDocument", () => {
|
|
45
|
-
this.eventBus.dispatch(_constants.INTERNAL_EVENT.REMOVE_DOCUMENT);
|
|
46
|
-
});
|
|
47
|
-
(0, _defineProperty2.default)(this, "receiveRemoveDocumentError", () => {
|
|
48
|
-
this.eventBus.dispatch(_constants.INTERNAL_EVENT.REMOVE_DOCUMENT_ERROR);
|
|
49
|
-
});
|
|
50
|
-
(0, _defineProperty2.default)(this, "receiveDocumentReplaced", () => {
|
|
51
|
-
this.eventBus.dispatch(_constants.INTERNAL_EVENT.DOCUMENT_REPLACED);
|
|
52
|
-
});
|
|
53
|
-
(0, _defineProperty2.default)(this, "receiveDocumentReplacedError", () => {
|
|
54
|
-
this.eventBus.dispatch(_constants.INTERNAL_EVENT.DOCUMENT_REPLACED_ERROR);
|
|
55
|
-
});
|
|
56
|
-
(0, _defineProperty2.default)(this, "receiveNewNotification", notification => {
|
|
57
|
-
this.eventBus.dispatch(_constants.INTERNAL_EVENT.NEW_NOTIFICATION, notification);
|
|
58
|
-
});
|
|
59
|
-
(0, _defineProperty2.default)(this, "onReceiveLocalOperations", operations => {
|
|
60
|
-
if (this.editor.readonly) return;
|
|
61
|
-
this.pendingOperationList.push(operations);
|
|
62
|
-
const lastOpBeginTime = new Date().getTime();
|
|
63
|
-
this.pendingOperationBeginTimeList.push(lastOpBeginTime);
|
|
64
|
-
const firstOpBeginTime = this.pendingOperationBeginTimeList[0];
|
|
65
|
-
const isExceedExecuteTime = (lastOpBeginTime - firstOpBeginTime) / 1000 > 30 ? true : false;
|
|
66
|
-
if (isExceedExecuteTime || this.pendingOperationList.length > 50) {
|
|
67
|
-
this.dispatchConnectState('pending_operations_exceed_limit');
|
|
68
|
-
}
|
|
69
|
-
this.sendOperations();
|
|
70
|
-
});
|
|
71
|
-
(0, _defineProperty2.default)(this, "sendOperations", () => {
|
|
72
|
-
if (this.editor.readonly) return;
|
|
73
|
-
if (this.state !== STATE.IDLE) return;
|
|
74
|
-
(0, _debug.stateDebug)(`State changed: ${this.state} -> ${STATE.SENDING}`);
|
|
75
|
-
this.state = STATE.SENDING;
|
|
76
|
-
this.sendNextOperations();
|
|
77
|
-
});
|
|
78
|
-
(0, _defineProperty2.default)(this, "sendNextOperations", () => {
|
|
79
|
-
if (this.state !== STATE.SENDING) return;
|
|
80
|
-
if (this.pendingOperationList.length === 0) {
|
|
81
|
-
(0, _debug.stateDebug)(`State Changed: ${this.state} -> ${STATE.IDLE}`);
|
|
82
|
-
this.state = STATE.IDLE;
|
|
83
|
-
return;
|
|
84
|
-
}
|
|
85
|
-
this.dispatchConnectState('is-saving');
|
|
86
|
-
const version = this.document.version;
|
|
87
|
-
const operations = this.pendingOperationList.shift();
|
|
88
|
-
const selection = this.editor.selection;
|
|
89
|
-
this._sendingOperations = operations;
|
|
90
|
-
this.socketClient.sendOperations(operations, version, selection, this.sendOperationsCallback);
|
|
91
|
-
});
|
|
92
|
-
(0, _defineProperty2.default)(this, "sendOperationsCallback", result => {
|
|
93
|
-
if (result && result.success) {
|
|
94
|
-
const {
|
|
95
|
-
version: serverVersion
|
|
96
|
-
} = result;
|
|
97
|
-
this.document['version'] = serverVersion;
|
|
98
|
-
const lastSavedAt = new Date().getTime();
|
|
99
|
-
this.dispatchConnectState('saved', lastSavedAt);
|
|
100
|
-
|
|
101
|
-
// send next operations
|
|
102
|
-
this.pendingOperationBeginTimeList.shift(); // remove current operation's begin time
|
|
103
|
-
this._sendingOperations = null;
|
|
104
|
-
this.sendNextOperations();
|
|
105
|
-
return;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
// Operations are execute failure
|
|
109
|
-
const {
|
|
110
|
-
error_type
|
|
111
|
-
} = result;
|
|
112
|
-
if (error_type === 'load_document_content_error' || error_type === 'save_operations_to_database_error' || error_type === 'token_expired') {
|
|
113
|
-
// load_document_content_error: After a short-term reconnection, the content of the document fails to load
|
|
114
|
-
// save_operation_to_database_error: Save operation to database error
|
|
115
|
-
this.dispatchConnectState(error_type);
|
|
116
|
-
|
|
117
|
-
// reset sending control
|
|
118
|
-
(0, _debug.stateDebug)(`State Changed: ${this.state} -> ${STATE.NEED_RELOAD}`);
|
|
119
|
-
this.state = STATE.NEED_RELOAD;
|
|
120
|
-
this._sendingOperations = null;
|
|
121
|
-
} else if (error_type === 'version_behind_server') {
|
|
122
|
-
// Put the failed operation into the pending list and re-execute it
|
|
123
|
-
this.pendingOperationList.unshift([...this._sendingOperations]);
|
|
124
|
-
(0, _debug.stateDebug)(`State Changed: ${this.state} -> ${STATE.CONFLICT}`);
|
|
125
|
-
this.state = STATE.CONFLICT;
|
|
126
|
-
const {
|
|
127
|
-
lose_operations
|
|
128
|
-
} = result;
|
|
129
|
-
this.resolveConflicting(lose_operations);
|
|
130
|
-
} else if (error_type === 'execute_client_operations_error') {
|
|
131
|
-
this.editor.isRemote = true;
|
|
132
|
-
const dupSendingOperations = [...this._sendingOperations];
|
|
133
|
-
(0, _helpers.revertOperationList)(this.editor, [dupSendingOperations]);
|
|
134
|
-
|
|
135
|
-
// Update the save time after revert
|
|
136
|
-
const lastSavedAt = new Date().getTime();
|
|
137
|
-
this.dispatchConnectState('saved', lastSavedAt);
|
|
138
|
-
|
|
139
|
-
// Set isRemote to false must be in Promise.resolve function, make sure the modification of isRemote is later than the onChange event
|
|
140
|
-
Promise.resolve().then(_ => {
|
|
141
|
-
this.editor.isRemote = false;
|
|
142
|
-
this.dispatchConnectState(error_type);
|
|
143
|
-
|
|
144
|
-
// send next operations
|
|
145
|
-
this._sendingOperations = null;
|
|
146
|
-
this.sendNextOperations();
|
|
147
|
-
});
|
|
148
|
-
}
|
|
149
|
-
});
|
|
150
|
-
(0, _defineProperty2.default)(this, "onReceiveRemoteOperations", params => {
|
|
151
|
-
// if this.disconnect is true, Then the message sent by the remote end cannot be received
|
|
152
|
-
if (this.state !== STATE.IDLE) return;
|
|
153
|
-
if (this.editor.readonly) return;
|
|
154
|
-
const {
|
|
155
|
-
version: serverVersion
|
|
156
|
-
} = params;
|
|
157
|
-
const {
|
|
158
|
-
version: clientVersion
|
|
159
|
-
} = this.document;
|
|
160
|
-
if (serverVersion === clientVersion + 1) {
|
|
161
|
-
// update execute remote operations flag
|
|
162
|
-
this.editor.isRemote = true;
|
|
163
|
-
const {
|
|
164
|
-
operations
|
|
165
|
-
} = params;
|
|
166
|
-
// Update content & version
|
|
167
|
-
(0, _debug.serverDebug)('execute remote operations: %O', operations);
|
|
168
|
-
try {
|
|
169
|
-
(0, _helpers.syncRemoteOperations)(this.editor, operations);
|
|
170
|
-
} catch (error) {
|
|
171
|
-
(0, _debug.stateDebug)(`State Changed: ${this.state} -> ${STATE.CONFLICT}`);
|
|
172
|
-
this.state = STATE.CONFLICT;
|
|
173
|
-
this.dispatchConnectState('sync_server_operations_error');
|
|
174
|
-
return;
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
// Update document
|
|
178
|
-
this.document.version = serverVersion;
|
|
179
|
-
this.document.children = this.editor.children;
|
|
180
|
-
Promise.resolve().then(() => {
|
|
181
|
-
this.editor.isRemote = false;
|
|
182
|
-
this.revertOperationList = [];
|
|
183
|
-
});
|
|
184
|
-
} else {
|
|
185
|
-
// isConflict
|
|
186
|
-
this.onConflictHappen();
|
|
187
|
-
}
|
|
188
|
-
});
|
|
189
|
-
(0, _defineProperty2.default)(this, "onReconnect", result => {
|
|
190
|
-
const {
|
|
191
|
-
version: serverVersion
|
|
192
|
-
} = result;
|
|
193
|
-
const clientVersion = this.getDocumentVersion();
|
|
194
|
-
// The client version is inconsistent with the server version, and the latest operations performed by the server need to be loaded
|
|
195
|
-
if (serverVersion !== clientVersion) {
|
|
196
|
-
this.onConflictHappen();
|
|
197
|
-
return;
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
// The version consistency indicates that there is no conflict and no processing is required
|
|
201
|
-
(0, _debug.stateDebug)(`State Changed: ${this.state} -> ${STATE.IDLE}`);
|
|
202
|
-
this.state = STATE.IDLE;
|
|
203
|
-
if (this.pendingOperationList.length > 0) {
|
|
204
|
-
(0, _debug.clientDebug)('After reconnection, manually trigger the execution of ops.');
|
|
205
|
-
(0, _debug.stateDebug)(`State Changed: ${this.state} -> ${STATE.SENDING}`);
|
|
206
|
-
this.state = STATE.SENDING;
|
|
207
|
-
this.sendNextOperations();
|
|
208
|
-
}
|
|
209
|
-
});
|
|
210
|
-
(0, _defineProperty2.default)(this, "onConflictHappen", () => {
|
|
211
|
-
(0, _debug.stateDebug)(`State Changed: ${this.state} -> ${STATE.CONFLICT}`);
|
|
212
|
-
this.state = STATE.CONFLICT;
|
|
213
|
-
this.socketClient.getRecentOperations();
|
|
214
|
-
});
|
|
215
|
-
(0, _defineProperty2.default)(this, "onGetRecentOperations", result => {
|
|
216
|
-
if (this.editor.readonly) return;
|
|
217
|
-
const {
|
|
218
|
-
mode,
|
|
219
|
-
content
|
|
220
|
-
} = result;
|
|
221
|
-
(0, _debug.conflictDebug)('Start conflict resolution');
|
|
222
|
-
// sync document
|
|
223
|
-
if (mode === 'document') {
|
|
224
|
-
const {
|
|
225
|
-
version,
|
|
226
|
-
children
|
|
227
|
-
} = content;
|
|
228
|
-
// 1. update document
|
|
229
|
-
(0, _debug.conflictDebug)('Update local document to remote document');
|
|
230
|
-
this.document.children = children;
|
|
231
|
-
this.document.version = version;
|
|
232
|
-
this.editor.children = children;
|
|
233
|
-
this.editor.isRemote = true;
|
|
234
|
-
this.editor.onChange();
|
|
235
|
-
(0, _debug.stateDebug)(`State Changed: ${this.state} -> ${STATE.IDLE}`);
|
|
236
|
-
this.editor.isRemote = false;
|
|
237
|
-
this.state = STATE.IDLE;
|
|
238
|
-
this._sendingOperations = null;
|
|
239
|
-
|
|
240
|
-
// 2. exec client operationList
|
|
241
|
-
const pendingOperationList = this.pendingOperationList.slice();
|
|
242
|
-
this.pendingOperationList = [];
|
|
243
|
-
|
|
244
|
-
// need resend this operations to server
|
|
245
|
-
(0, _debug.conflictDebug)('Re-execute local unsynchronized operations: %o', pendingOperationList);
|
|
246
|
-
(0, _helpers.reExecRevertOperationList)(this.editor, pendingOperationList);
|
|
247
|
-
return;
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
// mode os operations: sync operations
|
|
251
|
-
// content is [{version, operations}, {version, operations}, ...]
|
|
252
|
-
const loseOperations = content;
|
|
253
|
-
this.resolveConflicting(loseOperations);
|
|
254
|
-
});
|
|
255
|
-
(0, _defineProperty2.default)(this, "resolveConflicting", loseOperations => {
|
|
256
|
-
if (this.editor.readonly) return;
|
|
257
|
-
(0, _debug.conflictDebug)('resolve conflicts');
|
|
258
|
-
this.editor.isRemote = true;
|
|
259
|
-
if (this.pendingOperationList.length !== 0) {
|
|
260
|
-
// 1. Revert operations
|
|
261
|
-
// 1.1 record reverted operationList & clear pendingOperationList
|
|
262
|
-
this.revertOperationList = this.pendingOperationList.slice();
|
|
263
|
-
this.pendingOperationList = [];
|
|
264
|
-
|
|
265
|
-
// 1.2 Revert operationList
|
|
266
|
-
(0, _debug.conflictDebug)('revert locale operations: %O', this.revertOperationList);
|
|
267
|
-
(0, _helpers.revertOperationList)(this.editor, this.revertOperationList);
|
|
268
|
-
}
|
|
269
|
-
loseOperations = loseOperations.sort((prev, next) => prev.version - next.version);
|
|
270
|
-
(0, _debug.conflictDebug)('lose operations length: %s', loseOperations.length);
|
|
271
|
-
while (loseOperations.length > 0) {
|
|
272
|
-
const operationParams = loseOperations.shift();
|
|
273
|
-
// 2. execute operations
|
|
274
|
-
const {
|
|
275
|
-
operations,
|
|
276
|
-
version: serverVersion
|
|
277
|
-
} = operationParams;
|
|
278
|
-
// 2.1 Update content & version
|
|
279
|
-
(0, _debug.conflictDebug)('execute lose operations: %O', operations);
|
|
280
|
-
try {
|
|
281
|
-
(0, _helpers.syncRemoteOperations)(this.editor, operations);
|
|
282
|
-
} catch (error) {
|
|
283
|
-
(0, _debug.stateDebug)(`State Changed: ${this.state} -> ${STATE.CONFLICT}`);
|
|
284
|
-
this.state = STATE.CONFLICT;
|
|
285
|
-
this.dispatchConnectState('sync_server_operations_error');
|
|
286
|
-
return;
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
// 2.2 Update document
|
|
290
|
-
this.document.version = serverVersion;
|
|
291
|
-
this.document.children = this.editor.children;
|
|
292
|
-
}
|
|
293
|
-
if (this.revertOperationList.length === 0) {
|
|
294
|
-
Promise.resolve().then(() => {
|
|
295
|
-
this.editor.isRemote = false;
|
|
296
|
-
(0, _debug.stateDebug)(`State Changed: ${this.state} -> ${STATE.IDLE}`);
|
|
297
|
-
this.state = STATE.IDLE;
|
|
298
|
-
this._sendingOperations = null;
|
|
299
|
-
this.revertOperationList = [];
|
|
300
|
-
});
|
|
301
|
-
return;
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
// Set isRemote to false must be in Promise.resolve function, make sure the modification of isRemote is later than the onChange event
|
|
305
|
-
Promise.resolve().then(() => {
|
|
306
|
-
// reset execute remote operations flag
|
|
307
|
-
this.editor.isRemote = false;
|
|
308
|
-
(0, _debug.stateDebug)(`State Changed: ${this.state} -> ${STATE.IDLE}`);
|
|
309
|
-
this.state = STATE.IDLE;
|
|
310
|
-
this._sendingOperations = null;
|
|
311
|
-
|
|
312
|
-
// 3. Execute pending operations
|
|
313
|
-
// 3.1 Re-execute operations
|
|
314
|
-
(0, _debug.conflictDebug)('Editor isRemote is false: %s', this.editor.isRemote);
|
|
315
|
-
(0, _debug.conflictDebug)('Re-execute pending operations, %O', this.revertOperationList);
|
|
316
|
-
(0, _helpers.reExecRevertOperationList)(this.editor, this.revertOperationList);
|
|
317
|
-
|
|
318
|
-
// 3.2 Clear revert operationList
|
|
319
|
-
this.revertOperationList = [];
|
|
320
|
-
(0, _debug.conflictDebug)('Complete conflict resolution');
|
|
321
|
-
});
|
|
322
|
-
});
|
|
323
|
-
(0, _defineProperty2.default)(this, "sendCursorLocation", location => {
|
|
324
|
-
this.socketClient.sendCursorLocation(location);
|
|
325
|
-
});
|
|
326
|
-
(0, _defineProperty2.default)(this, "receiveCursorLocation", params => {
|
|
327
|
-
if (this.editor.readonly) return;
|
|
328
|
-
const {
|
|
329
|
-
user,
|
|
330
|
-
location,
|
|
331
|
-
cursor_data: cursorData
|
|
332
|
-
} = params;
|
|
333
|
-
(0, _helpers.syncRemoteCursorLocation)(this.editor, user, location, cursorData);
|
|
334
|
-
return;
|
|
335
|
-
});
|
|
336
|
-
(0, _defineProperty2.default)(this, "dispatchConnectState", (type, message) => {
|
|
337
|
-
if (type === 'leave-room') {
|
|
338
|
-
(0, _helper.deleteCursor)(this.editor, message);
|
|
339
|
-
this.editor.onCursor && this.editor.onCursor(this.editor.cursors);
|
|
340
|
-
}
|
|
341
|
-
if (type === 'disconnect') {
|
|
342
|
-
// current state is sending
|
|
343
|
-
if (this._sendingOperations) {
|
|
344
|
-
this.pendingOperationList.unshift(this._sendingOperations.slice());
|
|
345
|
-
this._sendingOperations = null;
|
|
346
|
-
}
|
|
347
|
-
(0, _debug.stateDebug)(`State Changed: ${this.state} -> ${STATE.DISCONNECT}`);
|
|
348
|
-
this.state = STATE.DISCONNECT;
|
|
349
|
-
}
|
|
350
|
-
this.eventBus.dispatch(type, message);
|
|
351
|
-
});
|
|
352
|
-
(0, _defineProperty2.default)(this, "closeSocketConnect", () => {
|
|
353
|
-
this.socketClient.disconnectWithServer();
|
|
354
|
-
});
|
|
355
|
-
(0, _defineProperty2.default)(this, "receiveParticipantAdded", uses => {
|
|
356
|
-
this.eventBus.dispatch(_constants.INTERNAL_EVENT.PARTICIPANT_ADDED, uses);
|
|
357
|
-
});
|
|
358
|
-
(0, _defineProperty2.default)(this, "receiveParticipantRemoved", email => {
|
|
359
|
-
this.eventBus.dispatch(_constants.INTERNAL_EVENT.PARTICIPANT_REMOVED, email);
|
|
360
|
-
});
|
|
361
|
-
this.editor = editor;
|
|
362
|
-
this.document = _document;
|
|
363
|
-
this.socketClient = new _socketClient.default(config);
|
|
364
|
-
this.pendingOperationList = []; // Two-dimensional arrays: [operations, operations, ...]
|
|
365
|
-
this.pendingOperationBeginTimeList = [];
|
|
366
|
-
this.remoteOperationsList = []; // Same with pending operations
|
|
367
|
-
this.revertOperationList = [];
|
|
368
|
-
this.eventBus = _eventBus.default.getInstance();
|
|
369
|
-
this.state = STATE.IDLE;
|
|
370
|
-
}
|
|
371
|
-
}
|
|
372
|
-
_SocketManager = SocketManager;
|
|
373
|
-
(0, _defineProperty2.default)(SocketManager, "getInstance", (editor, document, socketConfig) => {
|
|
374
|
-
if (_SocketManager.instance) {
|
|
375
|
-
return _SocketManager.instance;
|
|
376
|
-
}
|
|
377
|
-
if (!document || !socketConfig) {
|
|
378
|
-
throw new Error('SocketManager init params is invalid. Place check your code to fix it.');
|
|
379
|
-
}
|
|
380
|
-
_SocketManager.instance = new _SocketManager(editor, document, socketConfig);
|
|
381
|
-
return _SocketManager.instance;
|
|
382
|
-
});
|
|
383
|
-
(0, _defineProperty2.default)(SocketManager, "destroy", () => {
|
|
384
|
-
_SocketManager.instance = null;
|
|
385
|
-
});
|
|
386
|
-
var _default = exports.default = SocketManager;
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.default = void 0;
|
|
8
|
-
var _helper = require("../cursor/helper");
|
|
9
|
-
var _eventBus = _interopRequireDefault(require("../utils/event-bus"));
|
|
10
|
-
var _socketManager = _interopRequireDefault(require("./socket-manager"));
|
|
11
|
-
const withSocketIO = (editor, options) => {
|
|
12
|
-
const {
|
|
13
|
-
onChange
|
|
14
|
-
} = editor;
|
|
15
|
-
const newEditor = editor;
|
|
16
|
-
let socketManager = null;
|
|
17
|
-
const {
|
|
18
|
-
user
|
|
19
|
-
} = options.config;
|
|
20
|
-
newEditor.user = user;
|
|
21
|
-
newEditor.openConnection = () => {
|
|
22
|
-
const {
|
|
23
|
-
document,
|
|
24
|
-
config
|
|
25
|
-
} = options;
|
|
26
|
-
const cursorData = (0, _helper.generateCursorData)(options.config);
|
|
27
|
-
config['cursorData'] = cursorData;
|
|
28
|
-
socketManager = _socketManager.default.getInstance(newEditor, document, config);
|
|
29
|
-
};
|
|
30
|
-
newEditor.closeConnection = () => {
|
|
31
|
-
socketManager && socketManager.closeSocketConnect();
|
|
32
|
-
_socketManager.default.destroy();
|
|
33
|
-
};
|
|
34
|
-
newEditor.onChange = () => {
|
|
35
|
-
if (newEditor.readonly) return;
|
|
36
|
-
const {
|
|
37
|
-
document,
|
|
38
|
-
config
|
|
39
|
-
} = options;
|
|
40
|
-
let operations = newEditor.operations;
|
|
41
|
-
if (!newEditor.isRemote && operations.length > 0) {
|
|
42
|
-
const isAllSetSelection = operations.every(operation => operation.type === 'set_selection');
|
|
43
|
-
const socketManager = _socketManager.default.getInstance(newEditor, document, config);
|
|
44
|
-
if (!isAllSetSelection) {
|
|
45
|
-
// get update content value operations
|
|
46
|
-
const updateOperations = operations.filter(operation => operation.type !== 'set_selection');
|
|
47
|
-
socketManager.onReceiveLocalOperations(updateOperations);
|
|
48
|
-
}
|
|
49
|
-
socketManager.sendCursorLocation(editor.selection);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
// dispatch editor change event
|
|
53
|
-
const eventBus = _eventBus.default.getInstance(newEditor, document, config);
|
|
54
|
-
eventBus.dispatch('change');
|
|
55
|
-
onChange();
|
|
56
|
-
};
|
|
57
|
-
newEditor.rebaseContent = (document, originFileVersion) => {
|
|
58
|
-
const {
|
|
59
|
-
config
|
|
60
|
-
} = options;
|
|
61
|
-
const socketManager = _socketManager.default.getInstance(newEditor, document, config);
|
|
62
|
-
socketManager.sendRebaseContent(document, originFileVersion);
|
|
63
|
-
};
|
|
64
|
-
newEditor.updateDocumentVersion = document => {
|
|
65
|
-
const {
|
|
66
|
-
config
|
|
67
|
-
} = options;
|
|
68
|
-
const socketManager = _socketManager.default.getInstance(newEditor, document, config);
|
|
69
|
-
socketManager.updateDocumentVersion(document);
|
|
70
|
-
};
|
|
71
|
-
return newEditor;
|
|
72
|
-
};
|
|
73
|
-
var _default = exports.default = withSocketIO;
|
|
File without changes
|