@seafile/comment-editor 0.0.1-alpha.32 → 0.0.1-alpha.34

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.
@@ -43,7 +43,7 @@ const CommentEditor = _ref => {
43
43
  onContentChange,
44
44
  hiddenComment,
45
45
  hiddenUserInfo,
46
- hiddenToolMenu,
46
+ toolMenus = ['text_style', _constants2.BLOCKQUOTE, _constants2.UNORDERED_LIST, _constants2.ORDERED_LIST, _constants2.LINK, _constants2.IMAGE],
47
47
  closePanel
48
48
  } = _ref;
49
49
  const commentWrapperRef = (0, _react.useRef)();
@@ -218,62 +218,10 @@ const CommentEditor = _ref => {
218
218
  }
219
219
  eventProxy.onKeyDown(event);
220
220
  }, [eventProxy, editor]);
221
+ console.log('toolMenus', toolMenus);
221
222
  return /*#__PURE__*/_react.default.createElement("div", {
222
223
  className: (0, _classnames.default)('comment-editor-wrapper', className),
223
224
  ref: commentWrapperRef
224
- }, type === 'comment' && !hiddenUserInfo && /*#__PURE__*/_react.default.createElement("div", {
225
- className: "comment-editor-user-info"
226
- }, /*#__PURE__*/_react.default.createElement("div", {
227
- className: "comment-editor-user-img"
228
- }, /*#__PURE__*/_react.default.createElement("img", {
229
- src: userInfo.avatar_url,
230
- alt: "",
231
- height: "100%",
232
- width: "100%"
233
- })), /*#__PURE__*/_react.default.createElement("div", {
234
- className: "comment-editor-user-name"
235
- }, userInfo.name)), /*#__PURE__*/_react.default.createElement("div", {
236
- className: "comment-editor-container"
237
- }, /*#__PURE__*/_react.default.createElement("div", {
238
- className: "comment-editor-content"
239
- }, /*#__PURE__*/_react.default.createElement("div", {
240
- ref: commentEditorContainerRef,
241
- className: "article comment-editor",
242
- onClick: handleFocusEditor
243
- }, /*#__PURE__*/_react.default.createElement(_useScrollContext.ScrollContext.Provider, {
244
- value: {
245
- scrollRef: commentEditorContainerRef
246
- }
247
- }, /*#__PURE__*/_react.default.createElement(_slateReact.Slate, {
248
- editor: editor,
249
- value: slateValue,
250
- onChange: setSlateValue
251
- }, /*#__PURE__*/_react.default.createElement(_slateReact.Editable, {
252
- id: "sdoc-editor",
253
- scrollSelectionIntoView: handleScrollIntoView,
254
- cursors: cursors,
255
- renderElement: props => (0, _renderCommentEditorElement.default)({
256
- ...props,
257
- commentType: type
258
- }),
259
- renderLeaf: _extension.renderLeaf,
260
- onMouseDown: onMouseDown,
261
- decorate: decorate,
262
- onCut: eventProxy.onCut,
263
- onCopy: eventProxy.onCopy,
264
- onCompositionStart: eventProxy.onCompositionStart,
265
- onCompositionUpdate: eventProxy.onCompositionUpdate,
266
- onCompositionEnd: eventProxy.onCompositionEnd,
267
- onKeyDown: onKeyDown,
268
- onBeforeInput: eventProxy.onBeforeInput
269
- })))), /*#__PURE__*/_react.default.createElement(_commentEditorToolbar.default, {
270
- editor: editor,
271
- hiddenToolMenu: hiddenToolMenu,
272
- onSubmit: onSubmit,
273
- submitBtnText: t(submitTip),
274
- onCancel: onCancel
275
- }))), !hiddenToolMenu && /*#__PURE__*/_react.default.createElement(_insertElementDialog.default, {
276
- editor: editor
277
- }));
225
+ }, /*#__PURE__*/_react.default.createElement("div", null, "123"));
278
226
  };
279
227
  var _default = exports.default = CommentEditor;
@@ -23,36 +23,36 @@ const CommentEditorToolbar = _ref => {
23
23
  onSubmit,
24
24
  submitBtnText,
25
25
  onCancel,
26
- hiddenToolMenu
26
+ toolMenus
27
27
  } = _ref;
28
28
  (0, _useSelectionUpdate.default)();
29
29
  const eventBus = _eventBus.default.getInstance();
30
30
  return /*#__PURE__*/_react.default.createElement("div", {
31
31
  className: "comment-editor-toolbar",
32
32
  style: {
33
- justifyContent: hiddenToolMenu ? 'end' : ''
33
+ justifyContent: toolMenus.length === 0 ? 'end' : ''
34
34
  }
35
- }, !hiddenToolMenu && /*#__PURE__*/_react.default.createElement(_commons.MenuGroup, {
35
+ }, toolMenus.length !== 0 && /*#__PURE__*/_react.default.createElement(_commons.MenuGroup, {
36
36
  className: "menu-group comment-editor-menu-group"
37
- }, /*#__PURE__*/_react.default.createElement(_comemntEditorMenu.default, {
37
+ }, toolMenus.includes('text_style') && /*#__PURE__*/_react.default.createElement(_comemntEditorMenu.default, {
38
38
  editor: editor,
39
39
  readonly: readonly
40
- }), /*#__PURE__*/_react.default.createElement(_menu.default, {
40
+ }), toolMenus.includes(_constants.BLOCKQUOTE) && /*#__PURE__*/_react.default.createElement(_menu.default, {
41
41
  editor: editor,
42
42
  readonly: readonly
43
- }), /*#__PURE__*/_react.default.createElement(_menu4.default, {
43
+ }), toolMenus.includes(_constants.UNORDERED_LIST) && /*#__PURE__*/_react.default.createElement(_menu4.default, {
44
44
  editor: editor,
45
45
  type: _constants.UNORDERED_LIST,
46
46
  readonly: readonly
47
- }), /*#__PURE__*/_react.default.createElement(_menu4.default, {
47
+ }), toolMenus.includes(_constants.ORDERED_LIST) && /*#__PURE__*/_react.default.createElement(_menu4.default, {
48
48
  editor: editor,
49
49
  type: _constants.ORDERED_LIST,
50
50
  readonly: readonly
51
- }), /*#__PURE__*/_react.default.createElement(_menu3.default, {
51
+ }), toolMenus.includes(_constants.LINK) && /*#__PURE__*/_react.default.createElement(_menu3.default, {
52
52
  editor: editor,
53
53
  readonly: readonly,
54
54
  eventBus: eventBus
55
- }), /*#__PURE__*/_react.default.createElement(_menu2.default, {
55
+ }), toolMenus.includes(_constants.IMAGE) && /*#__PURE__*/_react.default.createElement(_menu2.default, {
56
56
  editor: editor,
57
57
  readonly: readonly,
58
58
  eventBus: eventBus
@@ -21,7 +21,6 @@ const CommentProvider = _ref => {
21
21
  children,
22
22
  type,
23
23
  // comment or replay
24
- userInfo,
25
24
  className = '',
26
25
  pluginName = '',
27
26
  // sdoc or wiki or txt ...
@@ -0,0 +1,312 @@
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
+ // Get front Point as cursor
294
+ const {
295
+ anchor,
296
+ focus
297
+ } = location;
298
+ let newLocation = location;
299
+ if (!_slate.Point.equals(anchor, focus)) {
300
+ const frontPoint = _slate.Editor.start(editor, location);
301
+ newLocation = {
302
+ anchor: frontPoint,
303
+ focus: frontPoint
304
+ };
305
+ }
306
+ (0, _helper.setCursor)(editor, user, newLocation, cursorData);
307
+
308
+ // sync cursor position
309
+ editor.onCursor && editor.onCursor(editor.cursors);
310
+ }
311
+ };
312
+ exports.syncRemoteCursorLocation = syncRemoteCursorLocation;
@@ -14,7 +14,6 @@ const SeafileCommentEditor = _ref => {
14
14
  // Provider
15
15
  type,
16
16
  // comment or replay
17
- userInfo,
18
17
  className = '',
19
18
  pluginName = '',
20
19
  // sdoc or wiki or txt ...
@@ -26,7 +25,7 @@ const SeafileCommentEditor = _ref => {
26
25
  onContentChange,
27
26
  hiddenUserInfo,
28
27
  hiddenComment,
29
- hiddenToolMenu,
28
+ toolMenus,
30
29
  closePanel,
31
30
  collaborators,
32
31
  participants,
@@ -38,7 +37,6 @@ const SeafileCommentEditor = _ref => {
38
37
  _basicSdk.context.init(settings, api);
39
38
  return /*#__PURE__*/_react.default.createElement(_errorBoundary.default, null, /*#__PURE__*/_react.default.createElement(_basicSdk.CommentProvider, {
40
39
  type: type,
41
- userInfo: userInfo,
42
40
  className: className,
43
41
  pluginName: pluginName,
44
42
  pluginEventBus: pluginEventBus,
@@ -52,7 +50,7 @@ const SeafileCommentEditor = _ref => {
52
50
  onContentChange: onContentChange,
53
51
  hiddenUserInfo: hiddenUserInfo,
54
52
  hiddenComment: hiddenComment,
55
- hiddenToolMenu: hiddenToolMenu,
53
+ toolMenus: toolMenus,
56
54
  closePanel: closePanel,
57
55
  addParticipants: addParticipants
58
56
  })));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seafile/comment-editor",
3
- "version": "0.0.1-alpha.32",
3
+ "version": "0.0.1-alpha.34",
4
4
  "private": false,
5
5
  "description": "This is a comment editor",
6
6
  "main": "dist/index.js",