@seafile/sdoc-editor 0.5.62 → 0.5.64

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.
@@ -3,6 +3,7 @@ import React, { useCallback, useEffect, useRef, useState } from 'react';
3
3
  import dayjs from 'dayjs';
4
4
  import classNames from 'classnames';
5
5
  import { Node } from '@seafile/slate';
6
+ import { ReactEditor } from '@seafile/slate-react';
6
7
  import context from '../../../context';
7
8
  import { useCommentContext } from '../hooks/comment-hooks/use-comment-context';
8
9
  import CommentItemContent from './comment-item-content';
@@ -19,12 +20,14 @@ const CommentItemWrapper = _ref => {
19
20
  comment,
20
21
  onCommentClick,
21
22
  updateScrollPosition,
22
- hiddenComment
23
+ hiddenComment,
24
+ editor
23
25
  } = _ref;
24
26
  const listRef = useRef(null);
25
27
  const {
26
28
  dispatch
27
29
  } = useCommentContext();
30
+ const scrollRef = useRef(document.querySelector('.sdoc-scroll-container'));
28
31
  const commentOpToolsId = "commentOpTools_".concat(comment.id);
29
32
  const deleteComment = useCallback(async commentId => {
30
33
  await context.deleteComment(commentId);
@@ -234,12 +237,22 @@ const CommentItemWrapper = _ref => {
234
237
  'd-flex flex-column pt-0': element
235
238
  });
236
239
  const tip = comment.resolved ? 'Reopen_discussion' : 'Enter_reply_Enter_for_new_line_Shift_Enter_to_send';
240
+ const handleScrollToArticle = useCallback(e => {
241
+ e.stopPropagation();
242
+ const dom = ReactEditor.toDOMNode(editor, element);
243
+ const headerHeight = 56 + 37;
244
+ scrollRef.current.scrollTo({
245
+ top: dom.offsetTop - headerHeight,
246
+ behavior: 'smooth'
247
+ });
248
+ }, [editor, element, scrollRef]);
237
249
  return /*#__PURE__*/React.createElement("div", {
238
250
  id: "comment-item-wrapper_".concat(comment.id),
239
251
  className: className,
240
252
  onClick: onItemClick
241
253
  }, element && /*#__PURE__*/React.createElement("div", {
242
- className: "comment-item-selected-text-container"
254
+ className: "comment-item-selected-text-container",
255
+ onClick: handleScrollToArticle
243
256
  }, /*#__PURE__*/React.createElement("i", {
244
257
  className: "sdocfont sdoc-comment-quote mr-2"
245
258
  }), /*#__PURE__*/React.createElement("div", {
@@ -19,12 +19,24 @@ const ElementCommentCount = _ref => {
19
19
  eventStopPropagation(event);
20
20
  focusToCommentElement(editor, element);
21
21
  }, [editor, element]);
22
- useEffect(() => {
22
+ const updatePosition = useCallback(() => {
23
23
  if (!element) return;
24
24
  const scrollTop = scrollRef.current.scrollTop || 0;
25
25
  const newTop = getElementCommentCountTop(editor, element, scrollTop);
26
26
  setTop(newTop);
27
- }, [editor, elementId, element, isElementSelected, scrollRef]);
27
+ }, [editor, element, scrollRef]);
28
+ useEffect(() => {
29
+ updatePosition();
30
+
31
+ // eslint-disable-next-line react-hooks/exhaustive-deps
32
+ }, []);
33
+ useEffect(() => {
34
+ const scrollDom = scrollRef.current;
35
+ scrollDom.addEventListener('scroll', updatePosition);
36
+ return () => {
37
+ scrollDom.removeEventListener('scroll', updatePosition);
38
+ };
39
+ }, [editor, elementId, element, scrollRef, isElementSelected, updatePosition]);
28
40
  if (!element) return null;
29
41
  let style = {
30
42
  top
@@ -231,7 +231,8 @@ const GlobalComment = _ref => {
231
231
  onCommentClick: comment => onCommentClick(comment, element),
232
232
  hiddenComment: hiddenComment,
233
233
  updateScrollPosition: updateScrollPosition,
234
- isClickCommentPanelBody: isClickCommentPanelBody
234
+ isClickCommentPanelBody: isClickCommentPanelBody,
235
+ editor: editor
235
236
  });
236
237
  }))), showEditor && /*#__PURE__*/React.createElement(GlobalCommentEditor, {
237
238
  isScrollDisplayed: isScrollDisplayed,
@@ -49,7 +49,7 @@ export const getCursorPosition = function () {
49
49
 
50
50
  /**
51
51
  * Get the height of the header of the editor
52
- * @param {Editor} editor
52
+ * @param {Editor} editor
53
53
  * @returns {Number} height of the header
54
54
  */
55
55
  export const getHeaderHeight = editor => {
@@ -5,7 +5,7 @@ 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 '../assets/css/simple-viewer.css';
8
+ import '../assets/css/sdoc-viewer.css';
9
9
  const SDocViewer = _ref => {
10
10
  let {
11
11
  editor,
@@ -1,4 +1,4 @@
1
- import React, { useMemo } from 'react';
1
+ import React, { useEffect, useMemo } from 'react';
2
2
  import { withTranslation } from 'react-i18next';
3
3
  import context from '../context';
4
4
  import ErrorBoundary from './error-boundary';
@@ -35,7 +35,13 @@ const SdocWikiViewer = _ref => {
35
35
  return newEditor;
36
36
 
37
37
  // eslint-disable-next-line react-hooks/exhaustive-deps
38
- }, []);
38
+ }, [docUuid]);
39
+ useEffect(() => {
40
+ validEditor.openConnection();
41
+ return () => {
42
+ validEditor.closeConnection();
43
+ };
44
+ }, [validEditor]);
39
45
  return /*#__PURE__*/React.createElement(ErrorBoundary, null, /*#__PURE__*/React.createElement(SDocEditor, {
40
46
  showComment: false,
41
47
  document: document,
@@ -40,7 +40,7 @@ const applyMarkForInlineItem = function (result, item) {
40
40
  }
41
41
  const linkChildren = [{
42
42
  id: slugid.nice(),
43
- text: child.value
43
+ text: child.value || ''
44
44
  }];
45
45
  const link = {
46
46
  id: slugid.nice(),
@@ -84,7 +84,9 @@ const applyMarkForInlineItem = function (result, item) {
84
84
  textNode['id'] = slugid.nice();
85
85
  }
86
86
  if (type === 'text') {
87
- textNode['text'] = value || '';
87
+ // https://symbl.cc/en/200B/
88
+ const formatValue = value && value !== '​' ? value : '';
89
+ textNode['text'] = formatValue;
88
90
  result.push(textNode);
89
91
  return;
90
92
  }
@@ -181,6 +183,8 @@ export const transformListItem = node => {
181
183
  return transformBlockquote(child);
182
184
  } else if (child.type === 'list') {
183
185
  return transformList(child);
186
+ } else if (child.type === 'heading') {
187
+ return transformParagraph(child);
184
188
  } else if (child.type === 'html') {
185
189
  // patch
186
190
  return transformBlockHtml(child);
@@ -244,18 +248,17 @@ export const transformTableCell = (cell, align) => {
244
248
  return {
245
249
  id: slugid.nice(),
246
250
  type: TABLE_CELL,
247
- align: align || null,
248
251
  children: transformNodeWithInlineChildren(cell)
249
252
  };
250
253
  };
251
- export const transformTableRow = (row, align) => {
254
+ export const transformTableRow = row => {
252
255
  const {
253
256
  children: cells
254
257
  } = row;
255
258
  return {
256
259
  id: slugid.nice(),
257
260
  type: TABLE_ROW,
258
- children: cells.map(cell => transformTableCell(cell, align))
261
+ children: cells.map(cell => transformTableCell(cell))
259
262
  };
260
263
  };
261
264
  export const transformTable = node => {
@@ -266,7 +269,8 @@ export const transformTable = node => {
266
269
  return {
267
270
  id: slugid.nice(),
268
271
  type: TABLE,
269
- children: rows.map((row, index) => transformTableRow(row, align[index]))
272
+ align: align,
273
+ children: rows.map((row, index) => transformTableRow(row))
270
274
  };
271
275
  };
272
276
  export const transformCodeLine = text => {
@@ -1,9 +1,10 @@
1
1
  import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
+ import { Node } from '@seafile/slate';
2
3
  import isLastCharPunctuation from '../../utils/is-punctuation-mark';
3
- const generateDefaultText = () => {
4
+ const generateDefaultText = value => {
4
5
  return {
5
6
  type: 'text',
6
- value: ''
7
+ value: value || ''
7
8
  };
8
9
  };
9
10
  const transformTextNode = textNode => {
@@ -23,24 +24,13 @@ const transformTextNode = textNode => {
23
24
  if (textNode['bold']) {
24
25
  mdNode['value'] = mdNode.value ? mdNode.value.trim() : '';
25
26
  if (isLastCharPunctuation(mdNode.value)) {
26
- const value = mdNode.value;
27
- const mdNode1 = _objectSpread(_objectSpread({}, mdNode), {}, {
28
- value: value.substring(0, value.length - 1)
29
- });
30
- const mdNode2 = {
31
- type: 'text',
32
- value: value.substring(value.length - 1)
33
- };
34
- mdNode = [{
35
- type: 'strong',
36
- children: [mdNode1]
37
- }, mdNode2];
38
- } else {
39
- mdNode = {
40
- type: 'strong',
41
- children: [mdNode]
42
- };
27
+ // https://symbl.cc/en/200B/
28
+ mdNode['value'] = mdNode.value + '​';
43
29
  }
30
+ mdNode = {
31
+ type: 'strong',
32
+ children: [mdNode]
33
+ };
44
34
  }
45
35
 
46
36
  // italic = true, add emphasis parent
@@ -52,24 +42,13 @@ const transformTextNode = textNode => {
52
42
  } else if (textNode['italic']) {
53
43
  mdNode['value'] = mdNode.value ? mdNode.value.trim() : '';
54
44
  if (isLastCharPunctuation(mdNode.value)) {
55
- const value = mdNode.value;
56
- const mdNode1 = _objectSpread(_objectSpread({}, mdNode), {}, {
57
- value: value.substring(0, value.length - 1)
58
- });
59
- const mdNode2 = {
60
- type: 'text',
61
- value: value.substring(value.length - 1)
62
- };
63
- mdNode = [{
64
- type: 'emphasis',
65
- children: [mdNode1]
66
- }, mdNode2];
67
- } else {
68
- mdNode = {
69
- type: 'emphasis',
70
- children: [mdNode]
71
- };
45
+ // https://symbl.cc/en/200B/
46
+ mdNode['value'] = mdNode.value + '​';
72
47
  }
48
+ mdNode = {
49
+ type: 'emphasis',
50
+ children: [mdNode]
51
+ };
73
52
  }
74
53
  return mdNode;
75
54
  };
@@ -160,6 +139,25 @@ const transformHeader = node => {
160
139
  };
161
140
  };
162
141
  const transformParagraph = node => {
142
+ const {
143
+ children
144
+ } = node;
145
+ if (!Array.isArray(children) || children.length === 0) {
146
+ return {
147
+ type: 'paragraph',
148
+ children: transformNodeWithInlineChildren(node)
149
+ };
150
+ }
151
+ const voidNodeTypes = ['image', 'column', 'formula'];
152
+ const hasBlock = children.some(item => voidNodeTypes.includes(item.type));
153
+ if (!hasBlock && Node.string(node).length === 0) {
154
+ return {
155
+ type: 'paragraph',
156
+ children: [
157
+ // https://symbl.cc/en/200B/
158
+ generateDefaultText('​')]
159
+ };
160
+ }
163
161
  return {
164
162
  type: 'paragraph',
165
163
  children: transformNodeWithInlineChildren(node)
@@ -187,7 +185,7 @@ const transformCheckList = node => {
187
185
  children: [{
188
186
  type: 'listItem',
189
187
  spread: false,
190
- checked: node.checked,
188
+ checked: node.checked ? true : false,
191
189
  children: [transformParagraph(node)]
192
190
  }]
193
191
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seafile/sdoc-editor",
3
- "version": "0.5.62",
3
+ "version": "0.5.64",
4
4
  "private": false,
5
5
  "description": "This is a sdoc editor",
6
6
  "main": "dist/index.js",
@@ -141,7 +141,7 @@
141
141
  "react-hot-loader": "4.13.1",
142
142
  "react-i18next": "12.1.4",
143
143
  "react-mentions": "4.4.7",
144
- "release-it": "16.2.1",
144
+ "release-it": "17.3.0",
145
145
  "resolve": "1.12.0",
146
146
  "resolve-url-loader": "5.0.0",
147
147
  "sass-loader": "13.3.2",