@seafile/comment-editor 0.0.1-alpha.3 → 0.0.1-alpha.30
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/context.js +8 -14
- package/dist/basic-sdk/editor/comment-editor.css +138 -0
- package/dist/basic-sdk/{comment/components → editor}/comment-editor.js +41 -43
- package/dist/basic-sdk/extension/plugins/image/helpers.js +1 -1
- package/dist/basic-sdk/extension/plugins/image/use-copy-image.js +1 -1
- package/dist/basic-sdk/extension/plugins/image/use-upload-image.js +1 -1
- package/dist/basic-sdk/extension/toolbar/comment-editor-toolbar/index.js +7 -3
- package/dist/basic-sdk/hooks/use-comment.js +19 -182
- package/dist/basic-sdk/index.js +3 -10
- package/dist/index.js +0 -12
- package/dist/pages/seafile-comment-editor.js +37 -13
- 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/layout/comment-layout/index.css +0 -15
- package/dist/basic-sdk/layout/comment-layout/index.js +0 -87
- package/dist/basic-sdk/layout/comment-layout/resize-width/index.css +0 -38
- package/dist/basic-sdk/layout/comment-layout/resize-width/index.js +0 -132
- package/dist/basic-sdk/layout/editor-container.js +0 -32
- package/dist/basic-sdk/layout/index.js +0 -13
- 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,299 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
|
|
4
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
5
|
-
Object.defineProperty(exports, "__esModule", {
|
|
6
|
-
value: true
|
|
7
|
-
});
|
|
8
|
-
exports.validateOperation = exports.syncRemoteOperations = exports.syncRemoteCursorLocation = exports.revertOperationList = exports.reExecRevertOperationList = exports.getRevertOperationList = exports.getNodePathById = void 0;
|
|
9
|
-
var _slate = require("@seafile/slate");
|
|
10
|
-
var _deepCopy = _interopRequireDefault(require("deep-copy"));
|
|
11
|
-
var _helper = require("../cursor/helper");
|
|
12
|
-
var _core = require("../extension/core");
|
|
13
|
-
var OPERATION = _interopRequireWildcard(require("../node-id/constants"));
|
|
14
|
-
const getNodePathById = function (rootNode, nodeId) {
|
|
15
|
-
let path = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
|
|
16
|
-
if (rootNode.id === nodeId) return path;
|
|
17
|
-
const {
|
|
18
|
-
children = []
|
|
19
|
-
} = rootNode;
|
|
20
|
-
for (let i = 0; i < children.length; i++) {
|
|
21
|
-
const child = children[i];
|
|
22
|
-
path.push(i);
|
|
23
|
-
const nodePath = getNodePathById(child, nodeId, path);
|
|
24
|
-
if (nodePath) return nodePath;
|
|
25
|
-
path.pop();
|
|
26
|
-
}
|
|
27
|
-
return null;
|
|
28
|
-
};
|
|
29
|
-
exports.getNodePathById = getNodePathById;
|
|
30
|
-
const validateOperation = (editor, operation) => {
|
|
31
|
-
let isValid = false;
|
|
32
|
-
let newOperation = (0, _deepCopy.default)(operation);
|
|
33
|
-
const {
|
|
34
|
-
type
|
|
35
|
-
} = newOperation;
|
|
36
|
-
switch (type) {
|
|
37
|
-
case OPERATION.INSERT_TEXT:
|
|
38
|
-
case OPERATION.REMOVE_TEXT:
|
|
39
|
-
{
|
|
40
|
-
const {
|
|
41
|
-
node_id,
|
|
42
|
-
path
|
|
43
|
-
} = newOperation;
|
|
44
|
-
const node = (0, _core.getNode)(editor, path);
|
|
45
|
-
// node is exist and node path is not changed
|
|
46
|
-
if (node && node.id === node_id) {
|
|
47
|
-
isValid = true;
|
|
48
|
-
break;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
// node is exist but node path is changed
|
|
52
|
-
const nodePath = getNodePathById(editor, node_id);
|
|
53
|
-
if (nodePath) {
|
|
54
|
-
isValid = true;
|
|
55
|
-
newOperation.path = nodePath;
|
|
56
|
-
break;
|
|
57
|
-
}
|
|
58
|
-
// node is not exist
|
|
59
|
-
isValid = false;
|
|
60
|
-
break;
|
|
61
|
-
}
|
|
62
|
-
case OPERATION.INSERT_NODE:
|
|
63
|
-
{
|
|
64
|
-
let {
|
|
65
|
-
parent_node_id,
|
|
66
|
-
path
|
|
67
|
-
} = newOperation;
|
|
68
|
-
const parentNodePath = getNodePathById(editor, parent_node_id);
|
|
69
|
-
if (!parentNodePath) {
|
|
70
|
-
isValid = false;
|
|
71
|
-
break;
|
|
72
|
-
}
|
|
73
|
-
const parentPath = path.slice(0, path.length - 1);
|
|
74
|
-
if (parentPath.join() === parentNodePath.join()) {
|
|
75
|
-
isValid = true;
|
|
76
|
-
break;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
// reset insert node path
|
|
80
|
-
const parentNode = (0, _core.getNode)(editor, path);
|
|
81
|
-
if (parentNode) {
|
|
82
|
-
const childLength = parentNode.children.length;
|
|
83
|
-
const index = Math.min(path[path.length - 1], childLength);
|
|
84
|
-
newOperation.path = parentNodePath.concat([index]);
|
|
85
|
-
isValid = true;
|
|
86
|
-
}
|
|
87
|
-
break;
|
|
88
|
-
}
|
|
89
|
-
case OPERATION.REMOVE_NODE:
|
|
90
|
-
{
|
|
91
|
-
const {
|
|
92
|
-
node_id,
|
|
93
|
-
path
|
|
94
|
-
} = newOperation;
|
|
95
|
-
const node = (0, _core.getNode)(editor, path);
|
|
96
|
-
// node is exist and node path is not changed
|
|
97
|
-
if (node && node.id === node_id) {
|
|
98
|
-
isValid = true;
|
|
99
|
-
break;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
// node is exist but node path is changed
|
|
103
|
-
const nodePath = getNodePathById(editor, node_id);
|
|
104
|
-
if (nodePath) {
|
|
105
|
-
isValid = true;
|
|
106
|
-
newOperation.path = nodePath;
|
|
107
|
-
break;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
// node is not exist
|
|
111
|
-
isValid = false;
|
|
112
|
-
break;
|
|
113
|
-
}
|
|
114
|
-
case OPERATION.MERGE_NODE:
|
|
115
|
-
{
|
|
116
|
-
// merge next node into prev node
|
|
117
|
-
const {
|
|
118
|
-
node_id,
|
|
119
|
-
path
|
|
120
|
-
} = newOperation;
|
|
121
|
-
const node = (0, _core.getNode)(editor, path);
|
|
122
|
-
// node is exist and node path is not changed
|
|
123
|
-
if (node && node.id === node_id) {
|
|
124
|
-
isValid = true;
|
|
125
|
-
break;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
// node is exist but node path is changed
|
|
129
|
-
const nodePath = getNodePathById(editor, node_id);
|
|
130
|
-
if (nodePath) {
|
|
131
|
-
isValid = true;
|
|
132
|
-
newOperation.path = nodePath;
|
|
133
|
-
break;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
// node is not exist
|
|
137
|
-
isValid = false;
|
|
138
|
-
break;
|
|
139
|
-
}
|
|
140
|
-
case OPERATION.SPLIT_NODE:
|
|
141
|
-
{
|
|
142
|
-
const {
|
|
143
|
-
node_id,
|
|
144
|
-
path
|
|
145
|
-
} = newOperation;
|
|
146
|
-
const node = (0, _core.getNode)(editor, path);
|
|
147
|
-
// node is exist and node path is not changed
|
|
148
|
-
if (node && node.id === node_id) {
|
|
149
|
-
isValid = true;
|
|
150
|
-
break;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
// node is exist but node path is changed
|
|
154
|
-
const nodePath = getNodePathById(editor, node_id);
|
|
155
|
-
if (nodePath) {
|
|
156
|
-
isValid = true;
|
|
157
|
-
newOperation.path = nodePath;
|
|
158
|
-
break;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
// node is not exist
|
|
162
|
-
isValid = false;
|
|
163
|
-
break;
|
|
164
|
-
}
|
|
165
|
-
case OPERATION.SET_NODE:
|
|
166
|
-
{
|
|
167
|
-
const {
|
|
168
|
-
node_id,
|
|
169
|
-
path,
|
|
170
|
-
properties
|
|
171
|
-
} = newOperation;
|
|
172
|
-
const node = (0, _core.getNode)(editor, path);
|
|
173
|
-
// node is exist and node path is not changed
|
|
174
|
-
if (node && node.id === node_id) {
|
|
175
|
-
isValid = true;
|
|
176
|
-
newOperation.properties = {
|
|
177
|
-
...properties,
|
|
178
|
-
type: node.type
|
|
179
|
-
};
|
|
180
|
-
break;
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
// node is exist but node path is changed
|
|
184
|
-
const nodePath = getNodePathById(editor, node_id);
|
|
185
|
-
if (nodePath) {
|
|
186
|
-
isValid = true;
|
|
187
|
-
const node = (0, _core.getNode)(editor, nodePath);
|
|
188
|
-
newOperation.properties = {
|
|
189
|
-
...properties,
|
|
190
|
-
type: node.type
|
|
191
|
-
};
|
|
192
|
-
newOperation.path = nodePath;
|
|
193
|
-
break;
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
// node is not exist
|
|
197
|
-
isValid = false;
|
|
198
|
-
break;
|
|
199
|
-
}
|
|
200
|
-
case OPERATION.MOVE_NODE:
|
|
201
|
-
{
|
|
202
|
-
const {
|
|
203
|
-
node_id,
|
|
204
|
-
path
|
|
205
|
-
} = newOperation;
|
|
206
|
-
const node = (0, _core.getNode)(editor, path);
|
|
207
|
-
// node is exist and node path is not changed
|
|
208
|
-
if (node && node.id === node_id) {
|
|
209
|
-
isValid = true;
|
|
210
|
-
break;
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
// TODO: newPath can not calculate by nodePath
|
|
214
|
-
// node is exist but node path is changed
|
|
215
|
-
// const nodePath = getNodePathById(editor, node_id);
|
|
216
|
-
// if (nodePath) {}
|
|
217
|
-
|
|
218
|
-
// node is not exist
|
|
219
|
-
isValid = false;
|
|
220
|
-
break;
|
|
221
|
-
}
|
|
222
|
-
default:
|
|
223
|
-
{
|
|
224
|
-
// set_selection
|
|
225
|
-
break;
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
if (isValid) return newOperation;
|
|
229
|
-
return isValid;
|
|
230
|
-
};
|
|
231
|
-
exports.validateOperation = validateOperation;
|
|
232
|
-
const getRevertOperationList = operationList => {
|
|
233
|
-
if (operationList.length === 0) return [];
|
|
234
|
-
|
|
235
|
-
// Generate a duplicate operationList, The original value cannot be modified here
|
|
236
|
-
let revertOperationList = (0, _deepCopy.default)(operationList);
|
|
237
|
-
revertOperationList = revertOperationList.reverse();
|
|
238
|
-
return revertOperationList.map(operations => {
|
|
239
|
-
const ops = operations.reverse();
|
|
240
|
-
return ops.map(item => _slate.Operation.inverse(item));
|
|
241
|
-
});
|
|
242
|
-
};
|
|
243
|
-
exports.getRevertOperationList = getRevertOperationList;
|
|
244
|
-
const revertOperationList = (editor, operationList) => {
|
|
245
|
-
if (operationList.length === 0) return [];
|
|
246
|
-
const revertOperationList = getRevertOperationList(operationList);
|
|
247
|
-
|
|
248
|
-
// Cancel locale execute operations
|
|
249
|
-
for (let i = 0; i < revertOperationList.length; i++) {
|
|
250
|
-
const operations = revertOperationList[i];
|
|
251
|
-
_slate.Editor.withoutNormalizing(editor, () => {
|
|
252
|
-
for (let j = 0; j < operations.length; j++) {
|
|
253
|
-
const op = operations[j];
|
|
254
|
-
editor.apply(op);
|
|
255
|
-
}
|
|
256
|
-
});
|
|
257
|
-
}
|
|
258
|
-
};
|
|
259
|
-
exports.revertOperationList = revertOperationList;
|
|
260
|
-
const reExecRevertOperationList = (editor, revertOperationList) => {
|
|
261
|
-
if (revertOperationList.length === 0) return;
|
|
262
|
-
|
|
263
|
-
// Re-execute revert operations
|
|
264
|
-
for (let i = 0; i < revertOperationList.length; i++) {
|
|
265
|
-
const operations = revertOperationList[i];
|
|
266
|
-
_slate.Editor.withoutNormalizing(editor, () => {
|
|
267
|
-
for (let j = 0; j < operations.length; j++) {
|
|
268
|
-
const op = validateOperation(editor, operations[j]);
|
|
269
|
-
if (op) {
|
|
270
|
-
editor.apply(op);
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
});
|
|
274
|
-
}
|
|
275
|
-
};
|
|
276
|
-
exports.reExecRevertOperationList = reExecRevertOperationList;
|
|
277
|
-
const syncRemoteOperations = (editor, remoteOperations) => {
|
|
278
|
-
if (remoteOperations.length === 0) return;
|
|
279
|
-
_slate.Editor.withoutNormalizing(editor, () => {
|
|
280
|
-
for (let i = 0; i < remoteOperations.length; i++) {
|
|
281
|
-
const op = remoteOperations[i];
|
|
282
|
-
if (op.type === 'set_selection') {
|
|
283
|
-
continue;
|
|
284
|
-
}
|
|
285
|
-
editor.apply(op);
|
|
286
|
-
}
|
|
287
|
-
});
|
|
288
|
-
};
|
|
289
|
-
exports.syncRemoteOperations = syncRemoteOperations;
|
|
290
|
-
const syncRemoteCursorLocation = (editor, user, location, cursorData) => {
|
|
291
|
-
const currentUser = editor.user;
|
|
292
|
-
if (user && user.username !== currentUser.username) {
|
|
293
|
-
(0, _helper.setCursor)(editor, user, location, cursorData);
|
|
294
|
-
|
|
295
|
-
// sync cursor position
|
|
296
|
-
editor.onCursor && editor.onCursor(editor.cursors);
|
|
297
|
-
}
|
|
298
|
-
};
|
|
299
|
-
exports.syncRemoteCursorLocation = syncRemoteCursorLocation;
|
|
@@ -1,20 +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
|
-
Object.defineProperty(exports, "SocketManager", {
|
|
8
|
-
enumerable: true,
|
|
9
|
-
get: function () {
|
|
10
|
-
return _socketManager.default;
|
|
11
|
-
}
|
|
12
|
-
});
|
|
13
|
-
Object.defineProperty(exports, "withSocketIO", {
|
|
14
|
-
enumerable: true,
|
|
15
|
-
get: function () {
|
|
16
|
-
return _withSocketIo.default;
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
var _socketManager = _interopRequireDefault(require("./socket-manager"));
|
|
20
|
-
var _withSocketIo = _interopRequireDefault(require("./with-socket-io"));
|
|
@@ -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;
|