@seafile/sdoc-editor 0.5.36 → 0.5.38

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.
@@ -11,8 +11,9 @@ import { generateEmptyElement } from '../../extension/core';
11
11
  import { PARAGRAPH } from '../../extension/constants';
12
12
  import slateToMdString from '../../../slate-convert/slate-to-md';
13
13
  import mdStringToSlate from '../../../slate-convert/md-to-slate';
14
- import { COMMENT_EDITOR, COMMENT_EDITOR_EDIT_AREA_WIDTH } from '../../constants';
14
+ import { COMMENT_EDITOR, COMMENT_EDITOR_EDIT_AREA_WIDTH, INTERNAL_EVENT } from '../../constants';
15
15
  import { KeyCodes } from '../../../constants';
16
+ import EventBus from '../../utils/event-bus';
16
17
  const getSubmitTip = (type, content) => {
17
18
  if (content) return 'Save';
18
19
  return type === 'comment' ? 'Comment' : 'Reply';
@@ -87,6 +88,13 @@ const CommentEditor = _ref => {
87
88
  })];
88
89
  Transforms.select(editor, Editor.start(editor, []));
89
90
  }, [editor, updateValue, addParticipants, userInfo.username, placeholder]);
91
+ useEffect(() => {
92
+ const eventBus = EventBus.getInstance();
93
+ const unsubscribePostComment = eventBus.subscribe(INTERNAL_EVENT.COMMENT_EDITOR_POST_COMMENT, onSubmit);
94
+ return () => {
95
+ unsubscribePostComment();
96
+ };
97
+ }, [onSubmit]);
90
98
  const onCancel = useCallback(event => {
91
99
  event.stopPropagation();
92
100
  const {
@@ -144,6 +152,6 @@ const CommentEditor = _ref => {
144
152
  }));
145
153
  };
146
154
  CommentEditor.defaultProps = {
147
- placeholder: 'Enter_a_comment'
155
+ placeholder: 'Enter_comment_Enter_for_new_line_shift_enter_to_send'
148
156
  };
149
157
  export default CommentEditor;
@@ -233,7 +233,7 @@ const CommentItemWrapper = _ref => {
233
233
  'sdoc-resolved': comment.resolved,
234
234
  'd-flex flex-column pt-0': element
235
235
  });
236
- const tip = comment.resolved ? 'Reopen_discussion' : 'Enter_a_reply';
236
+ const tip = comment.resolved ? 'Reopen_discussion' : 'Enter_reply_Enter_for_new_line_Shift_Enter_to_send';
237
237
  return /*#__PURE__*/React.createElement("div", {
238
238
  id: "comment-item-wrapper_".concat(comment.id),
239
239
  className: className,
@@ -152,7 +152,7 @@
152
152
 
153
153
  .sdoc-comment-drawer .sdoc-doc-comment-editor-container .comment-ui-container.active {
154
154
  margin-bottom: 0;
155
- padding: 16px;
155
+ padding: 16px 10px;
156
156
  left: 0;
157
157
  }
158
158
 
@@ -23,7 +23,8 @@ export const INTERNAL_EVENT = {
23
23
  TABLE_COLUMN_START_DRAG: 'table_column_start_drag',
24
24
  TABLE_SHOW_DRAG_HANDLER: 'table_show_drag_handler',
25
25
  TABLE_HIDE_DRAG_HANDLER: 'table_show_drag_handler',
26
- ON_PRINT: 'on_print'
26
+ ON_PRINT: 'on_print',
27
+ COMMENT_EDITOR_POST_COMMENT: 'comment_editor_post_comment'
27
28
  };
28
29
  export const REVISION_DIFF_KEY = 'diff';
29
30
  export const REVISION_DIFF_VALUE = '1';
@@ -2,15 +2,16 @@ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
2
  import React, { useCallback, useMemo } from 'react';
3
3
  import { Editable, ReactEditor, Slate } from '@seafile/slate-react';
4
4
  import { Editor, Node, Range } from '@seafile/slate';
5
+ import isHotkey from 'is-hotkey';
5
6
  import scrollIntoView from 'scroll-into-view-if-needed';
6
7
  import { renderLeaf } from '../extension';
7
- import EventProxy from '../utils/event-handler';
8
8
  import { useCursors } from '../cursor/use-cursors';
9
9
  import { INTERNAL_EVENT } from '../constants';
10
10
  import { usePipDecorate } from '../decorates';
11
11
  import EventBus from '../utils/event-bus';
12
12
  import { IMAGE } from '../extension/constants';
13
13
  import RenderCommentEditorCustomRenderElement from '../extension/render/render-comment-editor-element';
14
+ import EventProxy from '../utils/event-handler';
14
15
  const CommentArticle = _ref => {
15
16
  let {
16
17
  editor,
@@ -57,6 +58,15 @@ const CommentArticle = _ref => {
57
58
  //
58
59
  }
59
60
  }, []);
61
+ const onKeyDown = useCallback(event => {
62
+ if (isHotkey('shift+enter', event)) {
63
+ event.preventDefault();
64
+ const eventBus = EventBus.getInstance();
65
+ eventBus.dispatch(INTERNAL_EVENT.COMMENT_EDITOR_POST_COMMENT, event);
66
+ return;
67
+ }
68
+ eventProxy.onKeyDown(event);
69
+ }, [eventProxy]);
60
70
  return /*#__PURE__*/React.createElement(Slate, {
61
71
  editor: editor,
62
72
  value: slateValue,
@@ -74,7 +84,8 @@ const CommentArticle = _ref => {
74
84
  onCopy: eventProxy.onCopy,
75
85
  onCompositionStart: eventProxy.onCompositionStart,
76
86
  onCompositionUpdate: eventProxy.onCompositionUpdate,
77
- onCompositionEnd: eventProxy.onCompositionEnd
87
+ onCompositionEnd: eventProxy.onCompositionEnd,
88
+ onKeyDown: onKeyDown
78
89
  }));
79
90
  };
80
91
  export default CommentArticle;
@@ -115,6 +115,11 @@ const SdocEditor = forwardRef((_ref, ref) => {
115
115
 
116
116
  // eslint-disable-next-line react-hooks/exhaustive-deps
117
117
  }), [document, validEditor, slateValue]);
118
+ const onValueChange = value => {
119
+ const eventBus = EventBus.getInstance();
120
+ eventBus.dispatch(INTERNAL_EVENT.UPDATE_SEARCH_REPLACE_HIGHLIGHT, value);
121
+ setSlateValue(value);
122
+ };
118
123
  const isFreezed = context.getSetting('isFreezed');
119
124
  if (isReloading) {
120
125
  return /*#__PURE__*/React.createElement("div", {
@@ -129,7 +134,8 @@ const SdocEditor = forwardRef((_ref, ref) => {
129
134
  docValue: slateValue,
130
135
  readonly: true,
131
136
  showOutline: false,
132
- editor: validEditor
137
+ editor: validEditor,
138
+ showComment: false
133
139
  }, /*#__PURE__*/React.createElement(ReadOnlyArticle, {
134
140
  editor: validEditor,
135
141
  slateValue: slateValue
@@ -146,18 +152,14 @@ const SdocEditor = forwardRef((_ref, ref) => {
146
152
  docValue: slateValue,
147
153
  showOutline: true,
148
154
  readonly: isFreezed,
149
- editor: validEditor
155
+ editor: validEditor,
156
+ showComment: true
150
157
  }, /*#__PURE__*/React.createElement(ReadOnlyArticle, {
151
158
  editor: validEditor,
152
159
  slateValue: slateValue,
153
160
  isShowComment: true
154
161
  })))));
155
162
  }
156
- const onValueChange = value => {
157
- const eventBus = EventBus.getInstance();
158
- eventBus.dispatch(INTERNAL_EVENT.UPDATE_SEARCH_REPLACE_HIGHLIGHT, value);
159
- setSlateValue(value);
160
- };
161
163
  return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(EditorContainer, {
162
164
  editor: validEditor
163
165
  }, /*#__PURE__*/React.createElement(CollaboratorsProvider, null, /*#__PURE__*/React.createElement(ColorProvider, null, /*#__PURE__*/React.createElement(HeaderToolbar, {
@@ -165,7 +167,8 @@ const SdocEditor = forwardRef((_ref, ref) => {
165
167
  }), /*#__PURE__*/React.createElement(EditorContent, {
166
168
  docValue: slateValue,
167
169
  showOutline: true,
168
- editor: validEditor
170
+ editor: validEditor,
171
+ showComment: true
169
172
  }, /*#__PURE__*/React.createElement(EditableArticle, {
170
173
  editor: validEditor,
171
174
  slateValue: slateValue,
@@ -1,8 +1,9 @@
1
1
  import { Editor, Path, Range, Transforms } from '@seafile/slate';
2
- import { ORDERED_LIST, PARAGRAPH } from '../../../constants';
2
+ import { INSERT_POSITION, ORDERED_LIST, PARAGRAPH } from '../../../constants';
3
3
  import { getBeforeText, setListType } from '../helpers';
4
4
  import { focusEditor, getLastChild, getPreviousPath } from '../../../core';
5
5
  import { generateEmptyListItem } from '../model';
6
+ import { toggleList } from '../transforms';
6
7
 
7
8
  /**
8
9
  * @param {Editor} editor
@@ -29,6 +30,17 @@ export const handleShortcut = (editor, text) => {
29
30
  // If the match fails or the match is not at the beginning of the line, it is not a shortcut
30
31
  if (!matchResult || matchResult.index !== 0) return false;
31
32
  const previousNodePath = getPreviousPath(aboveNodePath);
33
+
34
+ // No previous node means that the current paragraph is the first paragraph in the container
35
+ if (!previousNodePath) {
36
+ if (matchedText !== '1.') return false;
37
+ // Delete shortcut key text
38
+ Transforms.delete(editor, {
39
+ at: range
40
+ });
41
+ toggleList(editor, ORDERED_LIST);
42
+ return true;
43
+ }
32
44
  const [previousNode, previousPath] = Editor.node(editor, previousNodePath);
33
45
  // If the previous node is not an ordered list and is not start with `1.`,it is not a shortcut
34
46
  if (previousNode.type !== ORDERED_LIST && matchedText !== '1.') return false;
@@ -21,7 +21,7 @@ const RenderCommentEditorCustomRenderElement = props => {
21
21
  const [renderParagraph] = ParagraphPlugin.renderElements;
22
22
  return renderParagraph(_props);
23
23
  }
24
- const placeholder = commentType === 'comment' ? 'Enter_a_comment' : 'Enter_a_reply';
24
+ const placeholder = commentType === 'comment' ? 'Enter_comment_Enter_for_new_line_shift_enter_to_send' : 'Enter_reply_Enter_for_new_line_Shift_Enter_to_send';
25
25
  const [renderParagraph] = ParagraphPlugin.renderElements;
26
26
  return renderParagraph(_objectSpread(_objectSpread({}, _props), {}, {
27
27
  placeholder
@@ -88,11 +88,11 @@ export const getDomTopHeight = (dom, slateNode) => {
88
88
  const rect = dom.getBoundingClientRect();
89
89
  let offsetY = 0;
90
90
  const paddingTop = parseFloat(window.getComputedStyle(dom).getPropertyValue('padding-top'));
91
- const lightHight = parseFloat(window.getComputedStyle(dom).getPropertyValue('line-height'));
91
+ const lineHeight = parseFloat(window.getComputedStyle(dom).getPropertyValue('line-height'));
92
+ const disToolBarHeight = 12; // side toolbar icon is 12 px
92
93
  if (ADD_POSITION_OFFSET_TYPE.includes(slateNode.type)) {
93
- offsetY = lightHight / 2 + paddingTop - 12; // side toolbar icon is 12 px
94
+ offsetY = lineHeight / 2 + paddingTop - disToolBarHeight / 2;
94
95
  }
95
-
96
96
  const HEADER_HEIGHT = 56 + 44;
97
97
  return rect.y - HEADER_HEIGHT + offsetY;
98
98
  };
@@ -11,7 +11,8 @@ const EditorContent = _ref => {
11
11
  showOutline,
12
12
  children,
13
13
  docValue,
14
- editor
14
+ editor,
15
+ showComment
15
16
  } = _ref;
16
17
  const scrollRef = useRef(null);
17
18
  const [scrollLeft, setScrollLeft] = useState(0);
@@ -25,6 +26,25 @@ const EditorContent = _ref => {
25
26
  'readonly': readonly,
26
27
  'no-outline': !showOutline
27
28
  });
29
+ if (!showComment) {
30
+ return /*#__PURE__*/React.createElement("div", {
31
+ className: "sdoc-content-wrapper"
32
+ }, /*#__PURE__*/React.createElement("div", {
33
+ ref: scrollRef,
34
+ className: "sdoc-scroll-container",
35
+ onScroll: onWrapperScroll,
36
+ id: "sdoc-scroll-container"
37
+ }, /*#__PURE__*/React.createElement(ScrollContext.Provider, {
38
+ value: {
39
+ scrollRef
40
+ }
41
+ }, /*#__PURE__*/React.createElement("div", {
42
+ className: className
43
+ }, showOutline && /*#__PURE__*/React.createElement(SDocOutline, {
44
+ scrollLeft: scrollLeft,
45
+ doc: docValue
46
+ }), children))));
47
+ }
28
48
  return /*#__PURE__*/React.createElement("div", {
29
49
  className: "sdoc-content-wrapper"
30
50
  }, /*#__PURE__*/React.createElement(CommentProvider, {
@@ -50,6 +70,7 @@ const EditorContent = _ref => {
50
70
  };
51
71
  EditorContent.defaultProps = {
52
72
  readonly: false,
53
- showOutline: true
73
+ showOutline: true,
74
+ showComment: false
54
75
  };
55
76
  export default EditorContent;
@@ -48,9 +48,10 @@ const PublishedRevisionDiffViewer = _ref => {
48
48
  children: isShowChanges && (diff === null || diff === void 0 ? void 0 : diff.value) || revisionContent.children
49
49
  };
50
50
  return /*#__PURE__*/React.createElement(SDocViewer, {
51
+ document: document,
51
52
  showToolbar: true,
52
53
  showOutline: true,
53
- document: document
54
+ showComment: false
54
55
  });
55
56
  };
56
57
  export default PublishedRevisionDiffViewer;
@@ -3,6 +3,7 @@ import context from '../../context';
3
3
  import { getDiff } from '../utils/diff';
4
4
  import SDocViewer from './sdoc-viewer';
5
5
  import Loading from '../../components/loading';
6
+ import { CollaboratorsProvider } from '../../hooks';
6
7
  import '../../assets/css/diff-viewer.css';
7
8
  const RevisionDiffViewer = _ref => {
8
9
  let {
@@ -39,13 +40,14 @@ const RevisionDiffViewer = _ref => {
39
40
  if (isLoading) {
40
41
  return /*#__PURE__*/React.createElement(Loading, null);
41
42
  }
42
- return /*#__PURE__*/React.createElement(SDocViewer, {
43
- showToolbar: true,
44
- showOutline: true,
43
+ return /*#__PURE__*/React.createElement(CollaboratorsProvider, null, /*#__PURE__*/React.createElement(SDocViewer, {
45
44
  editor: editor,
46
45
  document: {
47
46
  children: diff.value
48
- }
49
- });
47
+ },
48
+ showToolbar: true,
49
+ showOutline: true,
50
+ showComment: true
51
+ }));
50
52
  };
51
53
  export default RevisionDiffViewer;
@@ -17,11 +17,12 @@ const DiffViewer = _ref => {
17
17
  // eslint-disable-next-line react-hooks/exhaustive-deps
18
18
  }, []);
19
19
  return /*#__PURE__*/React.createElement(SDocViewer, {
20
- showToolbar: false,
21
- showOutline: false,
22
20
  document: {
23
21
  children: diff.value
24
- }
22
+ },
23
+ showToolbar: false,
24
+ showOutline: false,
25
+ showComment: false
25
26
  });
26
27
  };
27
28
  export default DiffViewer;
@@ -5,32 +5,33 @@ import { generateDefaultDocContent } from '../../utils';
5
5
  import { EditorContainer, EditorContent } from '../layout';
6
6
  import ReadOnlyArticle from './readonly-article';
7
7
  import { ColorProvider } from '../hooks/use-color-context';
8
- import { CollaboratorsProvider } from '../../hooks';
9
8
  import '../assets/css/simple-viewer.css';
10
9
  const SDocViewer = _ref => {
11
10
  let {
12
11
  editor,
13
12
  document,
14
13
  showToolbar,
15
- showOutline
14
+ showOutline,
15
+ showComment
16
16
  } = _ref;
17
17
  const validEditor = editor || withNodeId(createDefaultEditor());
18
18
  const slateValue = (document || generateDefaultDocContent()).children;
19
19
  return /*#__PURE__*/React.createElement(EditorContainer, {
20
20
  editor: validEditor,
21
21
  readonly: true
22
- }, /*#__PURE__*/React.createElement(CollaboratorsProvider, null, /*#__PURE__*/React.createElement(ColorProvider, null, showToolbar && /*#__PURE__*/React.createElement(HeaderToolbar, {
22
+ }, /*#__PURE__*/React.createElement(ColorProvider, null, showToolbar && /*#__PURE__*/React.createElement(HeaderToolbar, {
23
23
  editor: validEditor,
24
24
  readonly: true
25
25
  }), /*#__PURE__*/React.createElement(EditorContent, {
26
26
  docValue: slateValue,
27
27
  readonly: true,
28
28
  showOutline: showOutline,
29
- editor: validEditor
29
+ editor: validEditor,
30
+ showComment: showComment
30
31
  }, /*#__PURE__*/React.createElement(ReadOnlyArticle, {
31
32
  editor: validEditor,
32
33
  slateValue: slateValue
33
- })))));
34
+ }))));
34
35
  };
35
36
  SDocViewer.defaultProps = {
36
37
  showToolbar: false,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seafile/sdoc-editor",
3
- "version": "0.5.36",
3
+ "version": "0.5.38",
4
4
  "private": false,
5
5
  "description": "This is a sdoc editor",
6
6
  "main": "dist/index.js",
@@ -274,8 +274,8 @@
274
274
  "Delete_reply": "Delete reply",
275
275
  "Are_you_sure_to_delete_this_comment": "Are you sure to delete this comment?",
276
276
  "Are_you_sure_to_delete_this_reply": "Are you sure to delete this reply?",
277
- "Enter_a_comment": "Enter a comment",
278
- "Enter_a_reply": "Enter a reply",
277
+ "Enter_comment_Enter_for_new_line_shift_enter_to_send": "Enter a comment",
278
+ "Enter_reply_Enter_for_new_line_Shift_Enter_to_send": "Enter a reply",
279
279
  "Reopen_discussion": "Adding a reply will reopen this discussion",
280
280
  "Confirm": "Potvrdit",
281
281
  "View_changes": "View changes",
@@ -274,8 +274,8 @@
274
274
  "Delete_reply": "Delete reply",
275
275
  "Are_you_sure_to_delete_this_comment": "Are you sure to delete this comment?",
276
276
  "Are_you_sure_to_delete_this_reply": "Are you sure to delete this reply?",
277
- "Enter_a_comment": "Enter a comment",
278
- "Enter_a_reply": "Enter a reply",
277
+ "Enter_comment_Enter_for_new_line_shift_enter_to_send": "Enter a comment",
278
+ "Enter_reply_Enter_for_new_line_Shift_Enter_to_send": "Enter a reply",
279
279
  "Reopen_discussion": "Adding a reply will reopen this discussion",
280
280
  "Confirm": "Bestätigen",
281
281
  "View_changes": "View changes",
@@ -274,8 +274,8 @@
274
274
  "Delete_reply": "Delete reply",
275
275
  "Are_you_sure_to_delete_this_comment": "Are you sure to delete this comment?",
276
276
  "Are_you_sure_to_delete_this_reply": "Are you sure to delete this reply?",
277
- "Enter_a_comment": "Enter a comment",
278
- "Enter_a_reply": "Enter a reply",
277
+ "Enter_comment_Enter_for_new_line_shift_enter_to_send": "Enter comment, Enter for new line, Shift + Enter to send",
278
+ "Enter_reply_Enter_for_new_line_Shift_Enter_to_send": "Enter reply, Enter for new line, Shift + Enter to send",
279
279
  "Reopen_discussion": "Adding a reply will reopen this discussion",
280
280
  "Confirm": "Confirm",
281
281
  "View_changes": "View changes",
@@ -274,8 +274,8 @@
274
274
  "Delete_reply": "Delete reply",
275
275
  "Are_you_sure_to_delete_this_comment": "Are you sure to delete this comment?",
276
276
  "Are_you_sure_to_delete_this_reply": "Are you sure to delete this reply?",
277
- "Enter_a_comment": "Enter a comment",
278
- "Enter_a_reply": "Enter a reply",
277
+ "Enter_comment_Enter_for_new_line_shift_enter_to_send": "Enter a comment",
278
+ "Enter_reply_Enter_for_new_line_Shift_Enter_to_send": "Enter a reply",
279
279
  "Reopen_discussion": "Adding a reply will reopen this discussion",
280
280
  "Confirm": "Confirmar",
281
281
  "View_changes": "View changes",
@@ -274,8 +274,8 @@
274
274
  "Delete_reply": "Supprimer la réponse",
275
275
  "Are_you_sure_to_delete_this_comment": "Êtes-vous sûr de vouloir supprimer ce commentaire ?",
276
276
  "Are_you_sure_to_delete_this_reply": "Êtes-vous sûr de vouloir supprimer cette réponse ?",
277
- "Enter_a_comment": "Saisir un commentaire",
278
- "Enter_a_reply": "Saisir une réponse",
277
+ "Enter_comment_Enter_for_new_line_shift_enter_to_send": "Saisir un commentaire",
278
+ "Enter_reply_Enter_for_new_line_Shift_Enter_to_send": "Saisir une réponse",
279
279
  "Reopen_discussion": "L'ajout d'une réponse rouvrira la discussion.",
280
280
  "Confirm": "Confirmer",
281
281
  "View_changes": "Afficher les modifications",
@@ -274,8 +274,8 @@
274
274
  "Delete_reply": "Delete reply",
275
275
  "Are_you_sure_to_delete_this_comment": "Are you sure to delete this comment?",
276
276
  "Are_you_sure_to_delete_this_reply": "Are you sure to delete this reply?",
277
- "Enter_a_comment": "Enter a comment",
278
- "Enter_a_reply": "Enter a reply",
277
+ "Enter_comment_Enter_for_new_line_shift_enter_to_send": "Enter a comment",
278
+ "Enter_reply_Enter_for_new_line_Shift_Enter_to_send": "Enter a reply",
279
279
  "Reopen_discussion": "Adding a reply will reopen this discussion",
280
280
  "Confirm": "Confirm",
281
281
  "View_changes": "View changes",
@@ -274,8 +274,8 @@
274
274
  "Delete_reply": "Удалить ответ",
275
275
  "Are_you_sure_to_delete_this_comment": "Вы уверены, что удалите этот комментарий?",
276
276
  "Are_you_sure_to_delete_this_reply": "Вы уверены, что удалите этот ответ?",
277
- "Enter_a_comment": "Введите комментарий",
278
- "Enter_a_reply": "Введите ответ",
277
+ "Enter_comment_Enter_for_new_line_shift_enter_to_send": "Введите комментарий",
278
+ "Enter_reply_Enter_for_new_line_Shift_Enter_to_send": "Введите ответ",
279
279
  "Reopen_discussion": "Добавление ответа приведёт к возобновлению обсуждения.",
280
280
  "Confirm": "Подтвердить",
281
281
  "View_changes": "Просмотр изменений",
@@ -274,8 +274,8 @@
274
274
  "Delete_reply": "删除回复",
275
275
  "Are_you_sure_to_delete_this_comment": "你确定要删除这个评论吗?",
276
276
  "Are_you_sure_to_delete_this_reply": "你确定要删除这个回复吗?",
277
- "Enter_a_comment": "输入评论",
278
- "Enter_a_reply": "输入回复",
277
+ "Enter_comment_Enter_for_new_line_shift_enter_to_send": "输入评论,Enter 换行,Shift + Enter 发送",
278
+ "Enter_reply_Enter_for_new_line_Shift_Enter_to_send": "输入回复,Enter 换行,Shift + Enter 发送",
279
279
  "Reopen_discussion": "添加回复会重新提出该讨论",
280
280
  "Confirm": "确认",
281
281
  "View_changes": "查看改动",