@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.
Files changed (56) hide show
  1. package/dist/basic-sdk/assets/css/layout.css +1 -45
  2. package/dist/basic-sdk/comment/utils.js +39 -0
  3. package/dist/basic-sdk/editor/comment-editor.css +138 -0
  4. package/dist/basic-sdk/{comment/components → editor}/comment-editor.js +27 -20
  5. package/dist/basic-sdk/hooks/use-comment.js +8 -169
  6. package/dist/basic-sdk/index.js +3 -10
  7. package/dist/index.js +0 -12
  8. package/dist/pages/seafile-comment-editor.js +15 -8
  9. package/package.json +1 -1
  10. package/dist/assets/css/plugin-editor.css +0 -7
  11. package/dist/assets/css/simple-viewer.css +0 -6
  12. package/dist/basic-sdk/comment/components/comment-all-participants/index.css +0 -83
  13. package/dist/basic-sdk/comment/components/comment-all-participants/index.js +0 -67
  14. package/dist/basic-sdk/comment/components/comment-all-participants/participant-avatar.js +0 -43
  15. package/dist/basic-sdk/comment/components/comment-delete-popover.js +0 -80
  16. package/dist/basic-sdk/comment/components/comment-item-collapse-wrapper.js +0 -160
  17. package/dist/basic-sdk/comment/components/comment-item-content.js +0 -154
  18. package/dist/basic-sdk/comment/components/comment-item-reply.js +0 -124
  19. package/dist/basic-sdk/comment/components/comment-item-resolved-reply.js +0 -38
  20. package/dist/basic-sdk/comment/components/comment-item-wrapper.js +0 -364
  21. package/dist/basic-sdk/comment/components/comment-list.css +0 -422
  22. package/dist/basic-sdk/comment/components/comment-list.js +0 -216
  23. package/dist/basic-sdk/comment/components/comment-participants-editor/index.css +0 -132
  24. package/dist/basic-sdk/comment/components/comment-participants-editor/index.js +0 -69
  25. package/dist/basic-sdk/comment/components/comment-participants-editor/searched-collaborators.js +0 -62
  26. package/dist/basic-sdk/comment/components/comment-participants-editor/selected-participants.js +0 -48
  27. package/dist/basic-sdk/comment/components/editor-comment.js +0 -183
  28. package/dist/basic-sdk/comment/components/elements-comment-count/element-comment-count.js +0 -64
  29. package/dist/basic-sdk/comment/components/elements-comment-count/index.css +0 -29
  30. package/dist/basic-sdk/comment/components/elements-comment-count/index.js +0 -49
  31. package/dist/basic-sdk/comment/components/global-comment/global-comment-body-header.js +0 -88
  32. package/dist/basic-sdk/comment/components/global-comment/global-comment-header.js +0 -90
  33. package/dist/basic-sdk/comment/components/global-comment/index.css +0 -328
  34. package/dist/basic-sdk/comment/components/global-comment/index.js +0 -217
  35. package/dist/basic-sdk/comment/components/index.js +0 -21
  36. package/dist/basic-sdk/comment/components/style.css +0 -40
  37. package/dist/basic-sdk/comment/helper.js +0 -184
  38. package/dist/basic-sdk/comment/hooks/comment-hooks/use-comment-context.js +0 -20
  39. package/dist/basic-sdk/comment/hooks/comment-hooks/use-comment-list.js +0 -45
  40. package/dist/basic-sdk/comment/hooks/comment-hooks/use-comment-mount.js +0 -57
  41. package/dist/basic-sdk/comment/hooks/notification-hooks/index.js +0 -25
  42. package/dist/basic-sdk/comment/hooks/notification-hooks/use-notification-context.js +0 -20
  43. package/dist/basic-sdk/comment/hooks/notification-hooks/use-notification-mount.js +0 -70
  44. package/dist/basic-sdk/comment/hooks/use-participants.js +0 -26
  45. package/dist/basic-sdk/comment/index.js +0 -21
  46. package/dist/basic-sdk/comment/reducer/comment-reducer.js +0 -353
  47. package/dist/basic-sdk/comment/reducer/notification-reducer.js +0 -89
  48. package/dist/basic-sdk/comment/utils/get-event-transfer.js +0 -77
  49. package/dist/basic-sdk/comment/utils/index.js +0 -281
  50. package/dist/basic-sdk/comment/utils/notification-utils.js +0 -62
  51. package/dist/basic-sdk/socket/helpers.js +0 -299
  52. package/dist/basic-sdk/socket/index.js +0 -20
  53. package/dist/basic-sdk/socket/socket-client.js +0 -211
  54. package/dist/basic-sdk/socket/socket-manager.js +0 -386
  55. package/dist/basic-sdk/socket/with-socket-io.js +0 -73
  56. /package/dist/basic-sdk/comment/{constants/index.js → constants.js} +0 -0
@@ -1,281 +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.convertComment = exports.checkMentionOperation = exports.CommentUtilities = void 0;
8
- Object.defineProperty(exports, "createNotify", {
9
- enumerable: true,
10
- get: function () {
11
- return _notificationUtils.createNotify;
12
- }
13
- });
14
- exports.focusToCommentElement = void 0;
15
- Object.defineProperty(exports, "generatorNotificationKey", {
16
- enumerable: true,
17
- get: function () {
18
- return _notificationUtils.generatorNotificationKey;
19
- }
20
- });
21
- exports.searchCollaborators = exports.getEventClassName = exports.getCommentElementById = void 0;
22
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/defineProperty"));
23
- var _slate = require("@seafile/slate");
24
- var _slateReact = require("@seafile/slate-react");
25
- var _constants = require("../../constants");
26
- var _constants2 = require("../../extension/constants");
27
- var _core = require("../../extension/core");
28
- var _helper = require("../../extension/plugins/mention/helper");
29
- var _getEventTransfer = _interopRequireDefault(require("./get-event-transfer"));
30
- var _notificationUtils = require("./notification-utils");
31
- const searchCollaborators = (collaborators, searchValue, editor) => {
32
- const validSearchValue = searchValue ? searchValue.trim().toLowerCase() : '';
33
- const validCollaborators = Array.isArray(collaborators) && collaborators.length > 0 ? collaborators : [];
34
- if (!validSearchValue) return validCollaborators;
35
-
36
- // The current character is '@' and the previous character is a null character
37
- const beforeStr = (0, _helper.getPreCharacters)(editor);
38
- const isEmptyStr = beforeStr.slice(-2, -1).trim().length === 0;
39
- if (beforeStr.slice(-1) === '@' && isEmptyStr) {
40
- return validCollaborators;
41
- }
42
- return validCollaborators.filter(collaborator => {
43
- const {
44
- name,
45
- name_pinyin = ''
46
- } = collaborator;
47
- if (name.toString().toLowerCase().indexOf(validSearchValue) > -1) return true;
48
- if (!name_pinyin) return false;
49
- const validNamePinyin = name_pinyin.toString().toLowerCase();
50
- const validSearchPinyinValue = validSearchValue.replace(/ |'/g, '');
51
-
52
- // complete: For example, seatable can be retrieved when searching for sea.
53
- if (validNamePinyin.indexOf(validSearchPinyinValue) > -1) return true;
54
- if (validNamePinyin.replace(/'/g, '').indexOf(validSearchPinyinValue) > -1) return true;
55
- const validNamePinyinList = validNamePinyin.split('\'');
56
- // acronym: For example, sea table can be retrieved when searching for st.
57
- const namePinyinAcronym = validNamePinyinList.map(item => item && item.trim() ? item.trim().slice(0, 1) : '');
58
- if (namePinyinAcronym.join('').indexOf(validSearchPinyinValue) > -1) return true;
59
- return false;
60
- });
61
- };
62
-
63
- // Mailto, file, tel, callto, sms, cid, xmpp, etc. are not support
64
- // const ALLOWED_URL_REG = /((http|https):\/\/[-A-Za-z0-9+&@#/%?=~_|!:,.;]+[-A-Za-z0-9+&@#/%=~_|])/g;
65
- // export const textToHtml = (text) => {
66
- // if (!text) return '';
67
- // return text.replace(ALLOWED_URL_REG, '<a href="$1" target="_blank" class=' + COMMENT_URL_CLASSNAME + '>$1</a>');
68
- // };
69
- exports.searchCollaborators = searchCollaborators;
70
- const convertComment = value => {
71
- return value.replaceAll('<', '&lt;').replaceAll('>', '&gt;');
72
- };
73
- exports.convertComment = convertComment;
74
- const checkMentionOperation = event => {
75
- const {
76
- keyCode
77
- } = event;
78
- const {
79
- Escape,
80
- LeftArrow,
81
- RightArrow
82
- } = _constants.KeyCodes;
83
- if (keyCode === Escape || keyCode === LeftArrow || keyCode === RightArrow) return false;
84
- return true;
85
- };
86
- exports.checkMentionOperation = checkMentionOperation;
87
- class CommentUtilities {
88
- constructor() {
89
- (0, _defineProperty2.default)(this, "onInsertElement", _ref => {
90
- let {
91
- commentRef,
92
- selection,
93
- range,
94
- content,
95
- nodeType
96
- } = _ref;
97
- if (range) {
98
- selection.removeAllRanges();
99
- selection.addRange(range);
100
- }
101
- return this.createHtmlElement({
102
- commentRef,
103
- selection,
104
- range,
105
- content,
106
- nodeType
107
- });
108
- });
109
- (0, _defineProperty2.default)(this, "getHtmlElement", (nodeType, content) => {
110
- switch (nodeType) {
111
- case 'image':
112
- {
113
- let parentElement = document.createElement('div');
114
- parentElement.className = 'image-container';
115
- parentElement.contentEditable = 'false';
116
- let imageContainer = document.createElement('img');
117
- imageContainer.src = content;
118
- imageContainer.height = 60;
119
- parentElement.appendChild(imageContainer);
120
- return parentElement.outerHTML;
121
- }
122
- default:
123
- {
124
- return '';
125
- }
126
- }
127
- });
128
- (0, _defineProperty2.default)(this, "createHtmlElement", _ref2 => {
129
- let {
130
- commentRef,
131
- selection,
132
- range,
133
- content,
134
- nodeType
135
- } = _ref2;
136
- let spanNode1;
137
- let spanNode2;
138
- let imageContainer;
139
- if (nodeType === 'image') {
140
- spanNode1 = document.createElement('div');
141
- spanNode1.className = 'image-container';
142
- spanNode1.contentEditable = 'false';
143
- imageContainer = document.createElement('img');
144
- imageContainer.src = content;
145
- imageContainer.height = 60;
146
- spanNode1.appendChild(imageContainer);
147
- spanNode2 = document.createElement('span');
148
- spanNode2.innerHTML = ' ';
149
- }
150
- if (nodeType === 'collaborator') {
151
- spanNode1 = document.createElement('span');
152
- spanNode2 = document.createElement('span');
153
- spanNode1.className = 'at-text';
154
- spanNode1.innerHTML = `@${content.name}`;
155
- spanNode2.innerHTML = '&nbsp;';
156
- }
157
- let frag = document.createDocumentFragment();
158
- frag.appendChild(spanNode1);
159
- const lastNode = frag.appendChild(spanNode2);
160
- if (range) {
161
- range.insertNode(frag);
162
- } else {
163
- commentRef.current.appendChild(frag);
164
- range = selection.getRangeAt(0);
165
- }
166
- if (lastNode) {
167
- range = range.cloneRange();
168
- range.setStartAfter(lastNode);
169
- range.collapse(true);
170
- selection.removeAllRanges();
171
- selection.addRange(range);
172
- }
173
- return range;
174
- });
175
- (0, _defineProperty2.default)(this, "onSelectParticipant", _ref3 => {
176
- let {
177
- selection,
178
- range,
179
- participant,
180
- callBack,
181
- commentRef
182
- } = _ref3;
183
- if (range) {
184
- // delete '@xxx';
185
- selection.removeAllRanges();
186
- selection.addRange(range);
187
- const textNode = range.startContainer;
188
- const atIndex = this.getAtIndexWithAnchorPosition(range.startOffset, textNode.data);
189
- if (atIndex > -1) {
190
- range.setStart(textNode, atIndex);
191
- range.setEnd(textNode, range.endOffset);
192
- range.deleteContents();
193
- }
194
- }
195
- let newRange = this.createHtmlElement({
196
- selection,
197
- range,
198
- content: participant,
199
- nodeType: 'collaborator',
200
- commentRef
201
- });
202
- if (callBack) {
203
- callBack();
204
- }
205
- if (commentRef.current) {
206
- commentRef.current.focus();
207
- }
208
- return newRange;
209
- });
210
- /**
211
- * get the index of '@' from anchor position.
212
- * @param {*} anchorPosition '@text|anchor position|'
213
- * @param {*} text '@abc'
214
- * @returns index
215
- * e.g. '@abc|anchor position|' // 0
216
- * '@123 @|anchor position| @abc' // 5
217
- */
218
- (0, _defineProperty2.default)(this, "getAtIndexWithAnchorPosition", (anchorPosition, text) => {
219
- let atIndex = -1;
220
- for (let i = anchorPosition - 1; i > -1; i--) {
221
- if (text[i] === '@') {
222
- atIndex = i;
223
- break;
224
- }
225
- }
226
- return atIndex;
227
- });
228
- (0, _defineProperty2.default)(this, "onPaste", (event, callBack) => {
229
- event.stopPropagation();
230
- let cliperData = (0, _getEventTransfer.default)(event);
231
- if (cliperData.files) {
232
- let file = cliperData.files[0];
233
- let isImage = /image/i.test(file.type);
234
- if (isImage) {
235
- event.preventDefault();
236
- if (callBack) {
237
- callBack(cliperData.files);
238
- }
239
- }
240
- } else {
241
- event.preventDefault();
242
- let text = cliperData.text;
243
- if (document.queryCommandSupported('insertText')) {
244
- document.execCommand('insertText', false, text);
245
- } else {
246
- document.execCommand('paste', false, text);
247
- }
248
- }
249
- });
250
- }
251
- }
252
- exports.CommentUtilities = CommentUtilities;
253
- const focusToCommentElement = (editor, element) => {
254
- const path = (0, _core.findPath)(editor, element);
255
- const endOfFirstNode = _slate.Editor.end(editor, path);
256
- const startOfFirstNode = _slate.Editor.start(editor, path);
257
- const range = {
258
- anchor: [_constants2.ELEMENT_TYPE.LIST_ITEM, _constants2.ELEMENT_TYPE.ORDERED_LIST, _constants2.ELEMENT_TYPE.UNORDERED_LIST].includes(element.type) ? startOfFirstNode : endOfFirstNode,
259
- focus: endOfFirstNode
260
- };
261
- (0, _core.focusEditor)(editor, range);
262
- };
263
- exports.focusToCommentElement = focusToCommentElement;
264
- const getCommentElementById = (elementId, editor) => {
265
- let element = null;
266
- const dom = document.querySelectorAll(`[data-id="${elementId}"]`)[0];
267
- if (dom) {
268
- const slateNode = _slateReact.ReactEditor.toSlateNode(editor, dom);
269
- if (slateNode) {
270
- element = slateNode;
271
- }
272
- }
273
- return element;
274
- };
275
- exports.getCommentElementById = getCommentElementById;
276
- const getEventClassName = e => {
277
- // svg mouseEvent event.target.className is an object
278
- if (!e || !e.target) return '';
279
- return e.target.getAttribute('class') || '';
280
- };
281
- exports.getEventClassName = getEventClassName;
@@ -1,62 +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.generatorNotificationKey = exports.createNotify = void 0;
8
- var _dayjs = _interopRequireDefault(require("dayjs"));
9
- var _relativeTime = _interopRequireDefault(require("dayjs/plugin/relativeTime"));
10
- var _context = _interopRequireDefault(require("../../context"));
11
- _dayjs.default.extend(_relativeTime.default);
12
- const PERMISSION_GRANTED = 'granted';
13
- const notify = ($title, $options) => {
14
- const notification = new Notification($title, $options);
15
-
16
- // auto clear notifications
17
- const timer = setTimeout(notification.close.bind(notification), 5000);
18
- notification.onshow = function (event) {
19
- const {
20
- mediaUrl
21
- } = _context.default.getSetting('mediaUrl');
22
- let newAudioElement = document.createElement('audio');
23
- newAudioElement.setAttribute('src', `${mediaUrl}audio/classic.mp3`);
24
- newAudioElement.setAttribute('autoplay', 'autoplay');
25
- newAudioElement.setAttribute('id', 'seatable-audio');
26
- let audioElement = document.getElementById('seatable-audio');
27
- if (audioElement) {
28
- document.body.removeChild(audioElement);
29
- }
30
- document.body.appendChild(newAudioElement);
31
- };
32
- notification.onclose = function () {
33
- clearTimeout(timer);
34
- };
35
- notification.onclick = function () {
36
- notification.close();
37
- };
38
- };
39
- const createNotify = (title, options) => {
40
- // Let's check if the browser supports notifications
41
- if (!('Notification' in window)) {
42
- return false;
43
- }
44
- if (Notification.permission === PERMISSION_GRANTED) {
45
- notify(title, options);
46
- } else {
47
- Notification.requestPermission(res => {
48
- if (res === PERMISSION_GRANTED) {
49
- notify(title, options);
50
- }
51
- });
52
- }
53
- };
54
- exports.createNotify = createNotify;
55
- const generatorNotificationKey = function (commentId) {
56
- let replyId = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
57
- const validCommentId = commentId + '';
58
- const validReplyId = replyId + '';
59
- if (!validReplyId) return `sdoc_notification_${validCommentId}`;
60
- return `sdoc_notification_${validCommentId}_${validReplyId}`;
61
- };
62
- exports.generatorNotificationKey = generatorNotificationKey;
@@ -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"));