@seafile/sdoc-editor 0.5.62 → 0.5.63
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/comment/components/elements-comment-count/element-comment-count.js +14 -2
- package/dist/basic-sdk/utils/dom-utils.js +1 -1
- package/dist/basic-sdk/views/sdoc-viewer.js +1 -1
- package/dist/pages/sdoc-wiki-viewer.js +8 -2
- package/dist/slate-convert/md-to-slate/transform.js +10 -6
- package/dist/slate-convert/slate-to-md/transform.js +35 -37
- package/package.json +1 -1
- /package/dist/basic-sdk/assets/css/{simple-viewer.css → sdoc-viewer.css} +0 -0
|
@@ -19,12 +19,24 @@ const ElementCommentCount = _ref => {
|
|
|
19
19
|
eventStopPropagation(event);
|
|
20
20
|
focusToCommentElement(editor, element);
|
|
21
21
|
}, [editor, element]);
|
|
22
|
-
|
|
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,
|
|
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
|
|
@@ -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/
|
|
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
|
-
|
|
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 =
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
27
|
-
|
|
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
|
-
|
|
56
|
-
|
|
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
|
File without changes
|