@seafile/sdoc-editor 0.5.5 → 0.5.7
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/assets/css/layout.css +1 -1
- package/dist/basic-sdk/assets/css/sdoc-comment-editor-plugin.css +7 -0
- package/dist/basic-sdk/comment/components/comment-editor.js +1 -0
- package/dist/basic-sdk/comment/components/comment-list.css +7 -2
- package/dist/basic-sdk/editor/comment-article.js +8 -3
- package/dist/basic-sdk/editor/sdoc-comment-editor.js +3 -1
- package/dist/basic-sdk/extension/core/utils/index.js +3 -2
- package/dist/basic-sdk/extension/plugins/blockquote/plugin.js +3 -3
- package/dist/basic-sdk/extension/plugins/callout/helper.js +5 -2
- package/dist/basic-sdk/extension/plugins/paragraph/index.css +4 -0
- package/dist/basic-sdk/extension/plugins/paragraph/render-elem.js +11 -5
- package/dist/basic-sdk/extension/render/render-comment-editor-element.js +83 -0
- package/dist/basic-sdk/layout/editor-container.js +1 -0
- package/dist/basic-sdk/utils/diff.js +13 -0
- package/dist/components/doc-operations/revision-operations/changes-count/index.js +19 -9
- package/package.json +1 -1
|
@@ -117,6 +117,7 @@ const CommentEditor = _ref => {
|
|
|
117
117
|
className: "comment-editor-user-name"
|
|
118
118
|
}, userInfo.name)), /*#__PURE__*/React.createElement(SdocCommentEditor, {
|
|
119
119
|
editor: editor,
|
|
120
|
+
type: type,
|
|
120
121
|
document: document
|
|
121
122
|
}), /*#__PURE__*/React.createElement("div", {
|
|
122
123
|
className: "comment-operations"
|
|
@@ -85,6 +85,11 @@
|
|
|
85
85
|
word-wrap: break-word;
|
|
86
86
|
}
|
|
87
87
|
|
|
88
|
+
.comment-item .comment-content ol,
|
|
89
|
+
.comment-item .comment-content ul {
|
|
90
|
+
padding-left: 1em;
|
|
91
|
+
}
|
|
92
|
+
|
|
88
93
|
.sdoc-comment-list-container .comment-header .comment-author__avatar {
|
|
89
94
|
display: flex;
|
|
90
95
|
align-items: center;
|
|
@@ -212,8 +217,8 @@
|
|
|
212
217
|
.comment-editor-wrapper .sdoc-comment-editor-wrapper .article.sdoc-comment-editor {
|
|
213
218
|
width: 365px;
|
|
214
219
|
padding: 0 5px;
|
|
215
|
-
min-height:
|
|
216
|
-
max-height:
|
|
220
|
+
min-height: 130px;
|
|
221
|
+
max-height: 130px;
|
|
217
222
|
box-shadow: none;
|
|
218
223
|
overflow-y: auto;
|
|
219
224
|
overflow-x: hidden;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
1
2
|
import React, { useCallback, useMemo } from 'react';
|
|
2
3
|
import { Editable, ReactEditor, Slate } from '@seafile/slate-react';
|
|
3
4
|
import { Editor, Node, Range } from '@seafile/slate';
|
|
4
|
-
import { renderLeaf
|
|
5
|
+
import { renderLeaf } from '../extension';
|
|
5
6
|
import { getAboveBlockNode, getNextNode, getPrevNode, isSelectionAtBlockEnd, isSelectionAtBlockStart } from '../extension/core';
|
|
6
7
|
import EventProxy from '../utils/event-handler';
|
|
7
8
|
import { useCursors } from '../cursor/use-cursors';
|
|
@@ -11,11 +12,13 @@ import { getCursorPosition, getDomHeight, getDomMarginTop } from '../utils/dom-u
|
|
|
11
12
|
import EventBus from '../utils/event-bus';
|
|
12
13
|
import { useScrollContext } from '../hooks/use-scroll-context';
|
|
13
14
|
import { IMAGE } from '../extension/constants';
|
|
15
|
+
import RenderCommentEditorCustomRenderElement from '../extension/render/render-comment-editor-element';
|
|
14
16
|
const CommentArticle = _ref => {
|
|
15
17
|
let {
|
|
16
18
|
editor,
|
|
17
19
|
slateValue,
|
|
18
|
-
updateSlateValue
|
|
20
|
+
updateSlateValue,
|
|
21
|
+
type
|
|
19
22
|
} = _ref;
|
|
20
23
|
const {
|
|
21
24
|
cursors
|
|
@@ -160,7 +163,9 @@ const CommentArticle = _ref => {
|
|
|
160
163
|
}, /*#__PURE__*/React.createElement(Editable, {
|
|
161
164
|
scrollSelectionIntoView: handleScrollIntoView,
|
|
162
165
|
cursors: cursors,
|
|
163
|
-
renderElement:
|
|
166
|
+
renderElement: props => RenderCommentEditorCustomRenderElement(_objectSpread(_objectSpread({}, props), {}, {
|
|
167
|
+
commentType: type
|
|
168
|
+
})),
|
|
164
169
|
renderLeaf: renderLeaf,
|
|
165
170
|
onKeyDown: onKeyDown,
|
|
166
171
|
onMouseDown: onMouseDown,
|
|
@@ -19,7 +19,8 @@ const SdocCommentEditor = forwardRef((_ref, ref) => {
|
|
|
19
19
|
let {
|
|
20
20
|
editor: propsEditor,
|
|
21
21
|
document,
|
|
22
|
-
isReloading
|
|
22
|
+
isReloading,
|
|
23
|
+
type
|
|
23
24
|
} = _ref;
|
|
24
25
|
const [slateValue, setSlateValue] = useState(document.children);
|
|
25
26
|
const validEditor = propsEditor || useMemo(() => {
|
|
@@ -98,6 +99,7 @@ const SdocCommentEditor = forwardRef((_ref, ref) => {
|
|
|
98
99
|
}, /*#__PURE__*/React.createElement("div", {
|
|
99
100
|
className: "article sdoc-comment-editor"
|
|
100
101
|
}, /*#__PURE__*/React.createElement(CommentArticle, {
|
|
102
|
+
type: type,
|
|
101
103
|
editor: validEditor,
|
|
102
104
|
slateValue: slateValue,
|
|
103
105
|
updateSlateValue: setSlateValue
|
|
@@ -41,7 +41,8 @@ export const generateEmptyElement = function (type) {
|
|
|
41
41
|
};
|
|
42
42
|
export function Placeholder(props) {
|
|
43
43
|
const {
|
|
44
|
-
title
|
|
44
|
+
title,
|
|
45
|
+
top = 5
|
|
45
46
|
} = props;
|
|
46
47
|
const {
|
|
47
48
|
t
|
|
@@ -49,7 +50,7 @@ export function Placeholder(props) {
|
|
|
49
50
|
return /*#__PURE__*/React.createElement("span", {
|
|
50
51
|
style: {
|
|
51
52
|
position: 'absolute',
|
|
52
|
-
top:
|
|
53
|
+
top: "".concat(top, "px"),
|
|
53
54
|
color: 'rgba(191,191,191,1)',
|
|
54
55
|
pointerEvents: 'none',
|
|
55
56
|
width: '100%',
|
|
@@ -67,13 +67,13 @@ const withBlockquote = editor => {
|
|
|
67
67
|
if (currentLineIndex === 0 && isBlockAboveEmpty(newEditor)) {
|
|
68
68
|
const emptyParagraph = generateEmptyElement(PARAGRAPH);
|
|
69
69
|
Transforms.removeNodes(editor, {
|
|
70
|
-
at:
|
|
70
|
+
at: blockQuoteEntry[1]
|
|
71
71
|
});
|
|
72
72
|
Transforms.insertNodes(newEditor, emptyParagraph, {
|
|
73
73
|
at: blockQuoteEntry[1]
|
|
74
74
|
});
|
|
75
|
-
const
|
|
76
|
-
focusEditor(newEditor,
|
|
75
|
+
const focusPoint = Editor.end(newEditor, blockQuoteEntry[1]);
|
|
76
|
+
focusEditor(newEditor, focusPoint);
|
|
77
77
|
return;
|
|
78
78
|
}
|
|
79
79
|
// Merge with previous line when Select at the beginning of the line
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Editor, Node, Path, Transforms } from '@seafile/slate';
|
|
2
|
-
import { CALL_OUT } from '../../constants/element-type';
|
|
2
|
+
import { CALL_OUT, PARAGRAPH } from '../../constants/element-type';
|
|
3
3
|
import { focusEditor, generateEmptyElement, getSelectedElems, isRangeAcrossBlocks } from '../../core';
|
|
4
4
|
import { CALLOUT_ALLOWED_INSIDE_TYPES, CALLOUT_COLOR_MAP } from './constant';
|
|
5
5
|
export const isMenuActive = editor => {
|
|
@@ -110,7 +110,10 @@ export const getCalloutEntry = function (editor) {
|
|
|
110
110
|
export const isCalloutContentEmpty = calloutEntry => {
|
|
111
111
|
const [calloutNode] = calloutEntry;
|
|
112
112
|
const contentString = Node.string(calloutNode);
|
|
113
|
-
|
|
113
|
+
const calloutChildren = calloutNode.children;
|
|
114
|
+
const isSingleParagraph = calloutChildren.length === 1 && calloutChildren[0].type === PARAGRAPH;
|
|
115
|
+
const isEmptyContent = contentString.length === 0;
|
|
116
|
+
return isSingleParagraph && isEmptyContent;
|
|
114
117
|
};
|
|
115
118
|
|
|
116
119
|
// Insert a new element at new line in callout after current path
|
|
@@ -4,19 +4,23 @@ import { Node } from '@seafile/slate';
|
|
|
4
4
|
import { useSlateStatic } from '@seafile/slate-react';
|
|
5
5
|
import { Placeholder } from '../../core';
|
|
6
6
|
import { isEmptyNode } from './helper';
|
|
7
|
+
import { COMMENT_EDITOR } from '../../../constants';
|
|
8
|
+
import './index.css';
|
|
7
9
|
const PLACEHOLDER = 'Please_enter_text';
|
|
8
10
|
const Paragraph = _ref => {
|
|
9
11
|
let {
|
|
10
12
|
isComposing,
|
|
11
13
|
element,
|
|
12
14
|
attributes,
|
|
13
|
-
children
|
|
15
|
+
children,
|
|
16
|
+
className,
|
|
17
|
+
placeholder = PLACEHOLDER
|
|
14
18
|
} = _ref;
|
|
15
19
|
const {
|
|
16
|
-
indent
|
|
17
|
-
placeholder = PLACEHOLDER
|
|
20
|
+
indent
|
|
18
21
|
} = element;
|
|
19
22
|
const editor = useSlateStatic();
|
|
23
|
+
const isCommentEditor = editor.editorType === COMMENT_EDITOR;
|
|
20
24
|
let isShowPlaceHolder = false;
|
|
21
25
|
if (editor.children.length === 1) {
|
|
22
26
|
const node = editor.children[0];
|
|
@@ -37,9 +41,11 @@ const Paragraph = _ref => {
|
|
|
37
41
|
}, attributes, {
|
|
38
42
|
style: _objectSpread({
|
|
39
43
|
position: isShowPlaceHolder ? 'relative' : ''
|
|
40
|
-
}, style)
|
|
44
|
+
}, style),
|
|
45
|
+
className: className
|
|
41
46
|
}), children, isShowPlaceHolder && /*#__PURE__*/React.createElement(Placeholder, {
|
|
42
|
-
title: placeholder
|
|
47
|
+
title: placeholder,
|
|
48
|
+
top: isCommentEditor ? 0 : 5
|
|
43
49
|
}));
|
|
44
50
|
};
|
|
45
51
|
export const renderParagraph = props => {
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
2
|
+
import { useReadOnly, useSlateStatic } from '@seafile/slate-react';
|
|
3
|
+
import { LINK, LIST_ITEM, ORDERED_LIST, PARAGRAPH, UNORDERED_LIST, IMAGE, IMAGE_BLOCK, MENTION, MENTION_TEMP } from '../constants';
|
|
4
|
+
import { LinkPlugin, ListPlugin, ImagePlugin, ParagraphPlugin, MentionPlugin } from '../plugins';
|
|
5
|
+
import { getParentNode } from '../core';
|
|
6
|
+
const RenderCommentEditorCustomRenderElement = props => {
|
|
7
|
+
const editor = useSlateStatic();
|
|
8
|
+
const readonly = useReadOnly();
|
|
9
|
+
const {
|
|
10
|
+
element,
|
|
11
|
+
commentType
|
|
12
|
+
} = props;
|
|
13
|
+
switch (element.type) {
|
|
14
|
+
case PARAGRAPH:
|
|
15
|
+
{
|
|
16
|
+
const parentNode = getParentNode(editor.children, element.id);
|
|
17
|
+
const _props = _objectSpread(_objectSpread({}, props), {}, {
|
|
18
|
+
className: 'sdoc-comment-editor-paragraph'
|
|
19
|
+
});
|
|
20
|
+
if (parentNode && parentNode.type === LIST_ITEM) {
|
|
21
|
+
const [renderParagraph] = ParagraphPlugin.renderElements;
|
|
22
|
+
return renderParagraph(_props);
|
|
23
|
+
}
|
|
24
|
+
const placeholder = commentType === 'comment' ? 'Enter_a_comment' : 'Enter_a_reply';
|
|
25
|
+
const [renderParagraph] = ParagraphPlugin.renderElements;
|
|
26
|
+
return renderParagraph(_objectSpread(_objectSpread({}, _props), {}, {
|
|
27
|
+
placeholder
|
|
28
|
+
}));
|
|
29
|
+
}
|
|
30
|
+
case LINK:
|
|
31
|
+
{
|
|
32
|
+
const [renderLink] = LinkPlugin.renderElements;
|
|
33
|
+
return renderLink(props, editor, readonly);
|
|
34
|
+
}
|
|
35
|
+
case ORDERED_LIST:
|
|
36
|
+
case UNORDERED_LIST:
|
|
37
|
+
{
|
|
38
|
+
const [renderList] = ListPlugin.renderElements;
|
|
39
|
+
return renderList(props, editor);
|
|
40
|
+
}
|
|
41
|
+
case LIST_ITEM:
|
|
42
|
+
{
|
|
43
|
+
const [, renderListItem] = ListPlugin.renderElements;
|
|
44
|
+
return renderListItem(props, editor);
|
|
45
|
+
}
|
|
46
|
+
case IMAGE:
|
|
47
|
+
{
|
|
48
|
+
var _editor$element_comme;
|
|
49
|
+
const parentNode = getParentNode(editor.children, element.id);
|
|
50
|
+
const comments = ((_editor$element_comme = editor.element_comments_map) === null || _editor$element_comme === void 0 ? void 0 : _editor$element_comme[parentNode.id]) || [];
|
|
51
|
+
const unresolvedComments = comments && comments.filter(item => !item.resolved);
|
|
52
|
+
let leaf = {};
|
|
53
|
+
if (unresolvedComments && unresolvedComments.length > 0) {
|
|
54
|
+
leaf['computed_background_color'] = 'rgba(129, 237, 247, 0.5)';
|
|
55
|
+
}
|
|
56
|
+
const [renderImage] = ImagePlugin.renderElements;
|
|
57
|
+
return renderImage(_objectSpread(_objectSpread({}, props), {}, {
|
|
58
|
+
leaf
|
|
59
|
+
}), editor);
|
|
60
|
+
}
|
|
61
|
+
case IMAGE_BLOCK:
|
|
62
|
+
{
|
|
63
|
+
const [, renderImageBlock] = ImagePlugin.renderElements;
|
|
64
|
+
return renderImageBlock(_objectSpread({}, props), editor);
|
|
65
|
+
}
|
|
66
|
+
case MENTION:
|
|
67
|
+
{
|
|
68
|
+
const [renderMention] = MentionPlugin.renderElements;
|
|
69
|
+
return renderMention(props, editor);
|
|
70
|
+
}
|
|
71
|
+
case MENTION_TEMP:
|
|
72
|
+
{
|
|
73
|
+
const [, renderMentionTemporaryInput] = MentionPlugin.renderElements;
|
|
74
|
+
return renderMentionTemporaryInput(props, editor);
|
|
75
|
+
}
|
|
76
|
+
default:
|
|
77
|
+
{
|
|
78
|
+
const [renderParagraph] = ParagraphPlugin.renderElements;
|
|
79
|
+
return renderParagraph(props);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
export default RenderCommentEditorCustomRenderElement;
|
|
@@ -4,6 +4,7 @@ import { isMobile } from '../../utils';
|
|
|
4
4
|
import '../assets/css/default.css';
|
|
5
5
|
import '../assets/css/layout.css';
|
|
6
6
|
import '../assets/css/sdoc-editor-plugins.css';
|
|
7
|
+
import '../assets/css/sdoc-comment-editor-plugin.css';
|
|
7
8
|
import '../assets/css/dropdown-menu.css';
|
|
8
9
|
const EditorContainer = _ref => {
|
|
9
10
|
let {
|
|
@@ -17,6 +17,19 @@ const generatorDiffTextElement = function (textElement, diffType) {
|
|
|
17
17
|
[diffType]: true
|
|
18
18
|
}, style);
|
|
19
19
|
};
|
|
20
|
+
export const getTopLevelChanges = changes => {
|
|
21
|
+
const topLevelChanges = [];
|
|
22
|
+
changes.forEach(item => {
|
|
23
|
+
let dom = document.querySelectorAll("[data-id=".concat(item, "]"))[0];
|
|
24
|
+
while (((_dom = dom) === null || _dom === void 0 ? void 0 : (_dom$dataset = _dom.dataset) === null || _dom$dataset === void 0 ? void 0 : _dom$dataset.root) !== 'true') {
|
|
25
|
+
var _dom, _dom$dataset, _dom2;
|
|
26
|
+
if (!((_dom2 = dom) === null || _dom2 === void 0 ? void 0 : _dom2.parentNode)) break;
|
|
27
|
+
dom = dom.parentNode;
|
|
28
|
+
}
|
|
29
|
+
topLevelChanges.push(dom.dataset.id);
|
|
30
|
+
});
|
|
31
|
+
return Array.from(new Set(topLevelChanges));
|
|
32
|
+
};
|
|
20
33
|
|
|
21
34
|
// Depth facilitates each child node, adding diffType to each end node
|
|
22
35
|
const generatorDiffElement = function (element, diffType) {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import React, { useCallback, useState } from 'react';
|
|
1
|
+
import React, { useCallback, useEffect, useState } from 'react';
|
|
2
2
|
import { useTranslation } from 'react-i18next';
|
|
3
3
|
import Tooltip from '../../../tooltip';
|
|
4
|
+
import { getTopLevelChanges } from '../../../../basic-sdk/utils/diff';
|
|
4
5
|
import './index.css';
|
|
5
6
|
const ChangesCount = _ref => {
|
|
6
7
|
let {
|
|
@@ -10,9 +11,18 @@ const ChangesCount = _ref => {
|
|
|
10
11
|
t
|
|
11
12
|
} = useTranslation();
|
|
12
13
|
const [currentDiffIndex, setDiffIndex] = useState(0);
|
|
14
|
+
const [topLevelChanges, setTopLevelChanges] = useState([]);
|
|
15
|
+
useEffect(() => {
|
|
16
|
+
if (changes.length !== 0) {
|
|
17
|
+
queueMicrotask(() => {
|
|
18
|
+
const topLevelChanges = getTopLevelChanges(changes);
|
|
19
|
+
setTopLevelChanges([...topLevelChanges]);
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
}, [changes]);
|
|
13
23
|
const jumpToElement = useCallback(currentDiffIndex => {
|
|
14
24
|
setDiffIndex(currentDiffIndex);
|
|
15
|
-
const change =
|
|
25
|
+
const change = topLevelChanges[currentDiffIndex];
|
|
16
26
|
const changeElement = document.querySelectorAll("[data-id=".concat(change, "]"))[0];
|
|
17
27
|
if (changeElement) {
|
|
18
28
|
const scrollContainer = document.getElementById('sdoc-scroll-container');
|
|
@@ -22,31 +32,31 @@ const ChangesCount = _ref => {
|
|
|
22
32
|
}
|
|
23
33
|
|
|
24
34
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
25
|
-
}, [
|
|
35
|
+
}, [topLevelChanges, currentDiffIndex]);
|
|
26
36
|
const lastChange = useCallback(() => {
|
|
27
37
|
if (currentDiffIndex === 0) {
|
|
28
|
-
jumpToElement(
|
|
38
|
+
jumpToElement(topLevelChanges.length - 1);
|
|
29
39
|
return;
|
|
30
40
|
}
|
|
31
41
|
jumpToElement(currentDiffIndex - 1);
|
|
32
42
|
|
|
33
43
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
34
|
-
}, [
|
|
44
|
+
}, [topLevelChanges, currentDiffIndex]);
|
|
35
45
|
const nextChange = useCallback(() => {
|
|
36
|
-
if (currentDiffIndex ===
|
|
46
|
+
if (currentDiffIndex === topLevelChanges.length - 1) {
|
|
37
47
|
jumpToElement(0);
|
|
38
48
|
return;
|
|
39
49
|
}
|
|
40
50
|
jumpToElement(currentDiffIndex + 1);
|
|
41
51
|
|
|
42
52
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
43
|
-
}, [
|
|
44
|
-
if (!Array.isArray(
|
|
53
|
+
}, [topLevelChanges, currentDiffIndex]);
|
|
54
|
+
if (!Array.isArray(topLevelChanges) || topLevelChanges.length === 0) {
|
|
45
55
|
return /*#__PURE__*/React.createElement("div", {
|
|
46
56
|
className: "sdoc-revision-changes-container d-flex align-items-center pl-2 pr-2 ml-4"
|
|
47
57
|
}, t('No_changes'));
|
|
48
58
|
}
|
|
49
|
-
const changesCount =
|
|
59
|
+
const changesCount = topLevelChanges.length;
|
|
50
60
|
return /*#__PURE__*/React.createElement("div", {
|
|
51
61
|
className: "sdoc-revision-changes-container d-flex align-items-center ml-4"
|
|
52
62
|
}, /*#__PURE__*/React.createElement("div", {
|