@seafile/sdoc-editor 0.1.104 → 0.1.106-beta
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 -5
- package/dist/basic-sdk/assets/css/simple-viewer.css +13 -0
- package/dist/basic-sdk/comment/comment/comment-editor.js +57 -21
- package/dist/basic-sdk/comment/comment/comment-item-content.js +4 -3
- package/dist/basic-sdk/comment/comment/comment-item-reply.js +6 -4
- package/dist/basic-sdk/comment/comment/comment-item-wrapper.js +9 -5
- package/dist/basic-sdk/comment/comment/comment-list.css +10 -3
- package/dist/basic-sdk/comment/comment/comment-list.js +2 -3
- package/dist/basic-sdk/editor.js +22 -40
- package/dist/basic-sdk/extension/plugins/code-block/render-elem.js +10 -8
- package/dist/basic-sdk/layout/article-container.js +49 -0
- package/dist/basic-sdk/views/viewer.js +10 -15
- package/dist/pages/simple-editor.js +21 -24
- package/dist/utils/index.js +1 -0
- package/package.json +1 -1
- package/public/locales/en/sdoc-editor.json +2 -0
- package/public/locales/zh-CN/sdoc-editor.json +2 -0
|
@@ -26,10 +26,6 @@
|
|
|
26
26
|
position: relative;
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
.sdoc-editor-container .sdoc-editor-content.readonly {
|
|
30
|
-
height: 100%;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
29
|
.sdoc-editor-container .sdoc-absolute-wrapper {
|
|
34
30
|
position: absolute;
|
|
35
31
|
left: 0;
|
|
@@ -40,7 +36,7 @@
|
|
|
40
36
|
width: 100%;
|
|
41
37
|
}
|
|
42
38
|
|
|
43
|
-
.sdoc-editor-container .sdoc-
|
|
39
|
+
.sdoc-editor-container .sdoc-scroll-container {
|
|
44
40
|
position: absolute;
|
|
45
41
|
left: 0;
|
|
46
42
|
right: 0;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
.sdoc-editor-container .sdoc-editor-content.readonly {
|
|
2
|
+
height: 100%;
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
.sdoc-editor-container.mobile .sdoc-editor-content.readonly .sdoc-article-container {
|
|
6
|
+
padding: 0;
|
|
7
|
+
width: auto;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
.sdoc-editor-container.mobile .sdoc-editor-content.readonly .article {
|
|
11
|
+
width: 100% !important;
|
|
12
|
+
padding: 1rem;
|
|
13
|
+
}
|
|
@@ -1,20 +1,33 @@
|
|
|
1
1
|
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
2
|
-
import
|
|
2
|
+
import classNames from 'classnames';
|
|
3
|
+
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
3
4
|
import { withTranslation } from 'react-i18next';
|
|
5
|
+
import { Button } from 'reactstrap';
|
|
6
|
+
var getSubmitTip = function getSubmitTip(type, content) {
|
|
7
|
+
if (content) return 'Save';
|
|
8
|
+
return type === 'comment' ? 'Comment' : 'Reply';
|
|
9
|
+
};
|
|
4
10
|
var CommentEditor = function CommentEditor(_ref) {
|
|
5
|
-
var
|
|
11
|
+
var type = _ref.type,
|
|
12
|
+
className = _ref.className,
|
|
13
|
+
content = _ref.content,
|
|
6
14
|
placeholder = _ref.placeholder,
|
|
7
15
|
insertContent = _ref.insertContent,
|
|
8
16
|
updateContent = _ref.updateContent,
|
|
9
17
|
setIsEditing = _ref.setIsEditing,
|
|
10
18
|
t = _ref.t;
|
|
11
|
-
var
|
|
12
|
-
var _useState = useState(
|
|
19
|
+
var commentRef = useRef();
|
|
20
|
+
var _useState = useState(false),
|
|
13
21
|
_useState2 = _slicedToArray(_useState, 2),
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
22
|
+
isFocus = _useState2[0],
|
|
23
|
+
setIsFocus = _useState2[1];
|
|
24
|
+
|
|
25
|
+
// onMount
|
|
26
|
+
useEffect(function () {
|
|
27
|
+
if (content) {
|
|
28
|
+
commentRef.current.innerHTML = content;
|
|
29
|
+
}
|
|
30
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
18
31
|
}, []);
|
|
19
32
|
var updateValue = useCallback(function (value) {
|
|
20
33
|
if (!value || value.trim() === '') return;
|
|
@@ -24,30 +37,53 @@ var CommentEditor = function CommentEditor(_ref) {
|
|
|
24
37
|
}
|
|
25
38
|
updateContent(value);
|
|
26
39
|
}, [content, insertContent, updateContent]);
|
|
27
|
-
var
|
|
40
|
+
var onSubmit = useCallback(function (event) {
|
|
41
|
+
event && event.stopPropagation();
|
|
42
|
+
var value = commentRef.current.innerHTML;
|
|
28
43
|
updateValue(value);
|
|
29
|
-
|
|
30
|
-
}, [updateValue
|
|
44
|
+
commentRef.current.innerHTML = '';
|
|
45
|
+
}, [updateValue]);
|
|
46
|
+
var onCancel = useCallback(function (event) {
|
|
47
|
+
event.stopPropagation();
|
|
48
|
+
setIsFocus(false);
|
|
49
|
+
commentRef.current.innerHTML = '';
|
|
50
|
+
setIsEditing && setIsEditing(false);
|
|
51
|
+
}, [setIsEditing]);
|
|
31
52
|
var onKeyDown = useCallback(function (event) {
|
|
32
53
|
// enter
|
|
33
54
|
if (event.keyCode === 13) {
|
|
34
|
-
|
|
55
|
+
event.preventDefault();
|
|
56
|
+
onSubmit();
|
|
35
57
|
}
|
|
36
58
|
if (event.keyCode === 27) {
|
|
37
|
-
|
|
38
|
-
|
|
59
|
+
event.preventDefault();
|
|
60
|
+
onCancel();
|
|
39
61
|
}
|
|
40
|
-
}, [
|
|
62
|
+
}, [onCancel, onSubmit]);
|
|
41
63
|
placeholder = t(placeholder);
|
|
42
|
-
|
|
43
|
-
|
|
64
|
+
var submitTip = useMemo(function () {
|
|
65
|
+
return getSubmitTip(type, content);
|
|
66
|
+
}, [content, type]);
|
|
67
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
68
|
+
className: classNames('comment-editor-wrapper', className)
|
|
69
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
70
|
+
ref: commentRef,
|
|
71
|
+
contentEditable: "true",
|
|
44
72
|
className: "comment-editor",
|
|
45
|
-
value: value,
|
|
46
73
|
placeholder: placeholder,
|
|
47
|
-
onChange: onChange,
|
|
48
74
|
onKeyDown: onKeyDown,
|
|
49
|
-
|
|
50
|
-
|
|
75
|
+
onFocus: function onFocus() {
|
|
76
|
+
return setIsFocus(true);
|
|
77
|
+
}
|
|
78
|
+
}), isFocus && /*#__PURE__*/React.createElement("div", {
|
|
79
|
+
className: "editor-operations"
|
|
80
|
+
}, /*#__PURE__*/React.createElement(Button, {
|
|
81
|
+
className: "mr-2",
|
|
82
|
+
onClick: onCancel
|
|
83
|
+
}, t('Cancel')), /*#__PURE__*/React.createElement(Button, {
|
|
84
|
+
color: "primary",
|
|
85
|
+
onClick: onSubmit
|
|
86
|
+
}, t(submitTip))));
|
|
51
87
|
};
|
|
52
88
|
CommentEditor.defaultProps = {
|
|
53
89
|
placeholder: 'Enter_a_comment'
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
2
2
|
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
3
|
-
import React, { useCallback, useMemo,
|
|
3
|
+
import React, { useCallback, useMemo, useState } from 'react';
|
|
4
4
|
import { withTranslation } from 'react-i18next';
|
|
5
5
|
import { Dropdown, DropdownItem, DropdownMenu, DropdownToggle, UncontrolledTooltip } from 'reactstrap';
|
|
6
6
|
import dayjs from 'dayjs';
|
|
@@ -121,10 +121,11 @@ var CommentItem = function CommentItem(_ref) {
|
|
|
121
121
|
onClick: resubmit
|
|
122
122
|
}, t('Resubmit')))))), /*#__PURE__*/React.createElement("div", {
|
|
123
123
|
className: "comment-content"
|
|
124
|
-
}, isEditing && /*#__PURE__*/React.createElement(CommentEditor, {
|
|
124
|
+
}, !isEditing && /*#__PURE__*/React.createElement(React.Fragment, null, comment.comment)), isEditing && /*#__PURE__*/React.createElement(CommentEditor, {
|
|
125
|
+
className: 'pb-3',
|
|
125
126
|
content: comment.comment,
|
|
126
127
|
updateContent: updateContent,
|
|
127
128
|
setIsEditing: setIsEditing
|
|
128
|
-
})
|
|
129
|
+
}));
|
|
129
130
|
};
|
|
130
131
|
export default withTranslation('sdoc-editor')(CommentItem);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
2
|
-
import React, { useCallback,
|
|
2
|
+
import React, { useCallback, useState } from 'react';
|
|
3
3
|
import { withTranslation } from 'react-i18next';
|
|
4
|
-
import { Dropdown, DropdownItem, DropdownMenu, DropdownToggle
|
|
4
|
+
import { Dropdown, DropdownItem, DropdownMenu, DropdownToggle } from 'reactstrap';
|
|
5
5
|
import dayjs from 'dayjs';
|
|
6
6
|
import context from '../../../context';
|
|
7
7
|
import CommentEditor from './comment-editor';
|
|
@@ -86,11 +86,13 @@ var CommentItemReply = function CommentItemReply(_ref) {
|
|
|
86
86
|
onClick: onDeleteToggle
|
|
87
87
|
}, t('Delete')))))), /*#__PURE__*/React.createElement("div", {
|
|
88
88
|
className: "comment-content"
|
|
89
|
-
}, isEditing && /*#__PURE__*/React.createElement(CommentEditor, {
|
|
89
|
+
}, !isEditing && /*#__PURE__*/React.createElement(React.Fragment, null, reply.reply)), isEditing && /*#__PURE__*/React.createElement(CommentEditor, {
|
|
90
|
+
className: 'pb-3',
|
|
91
|
+
type: "reply",
|
|
90
92
|
content: reply.reply,
|
|
91
93
|
updateContent: updateContent,
|
|
92
94
|
setIsEditing: setIsEditing
|
|
93
|
-
}),
|
|
95
|
+
}), isShowDeleteDialog && isActive && /*#__PURE__*/React.createElement(CommentDeleteShadow, {
|
|
94
96
|
type: "reply",
|
|
95
97
|
deleteConfirm: _deleteReply,
|
|
96
98
|
setIsShowDeleteModal: setIsShowDeleteDialog
|
|
@@ -198,7 +198,11 @@ export default function CommentItemWrapper(_ref) {
|
|
|
198
198
|
});
|
|
199
199
|
case 18:
|
|
200
200
|
setTimeout(function () {
|
|
201
|
-
|
|
201
|
+
var options = {
|
|
202
|
+
top: 10000,
|
|
203
|
+
behavior: 'smooth'
|
|
204
|
+
};
|
|
205
|
+
listRef.current.scrollTo(options);
|
|
202
206
|
}, 0);
|
|
203
207
|
case 19:
|
|
204
208
|
case "end":
|
|
@@ -352,12 +356,12 @@ export default function CommentItemWrapper(_ref) {
|
|
|
352
356
|
key: reply.id,
|
|
353
357
|
reply: reply
|
|
354
358
|
});
|
|
355
|
-
})), isActive && /*#__PURE__*/React.createElement(
|
|
356
|
-
className: "
|
|
357
|
-
|
|
359
|
+
})), isActive && /*#__PURE__*/React.createElement(CommentEditor, {
|
|
360
|
+
className: "mt-4",
|
|
361
|
+
type: "reply",
|
|
358
362
|
placeholder: tip,
|
|
359
363
|
insertContent: insertContent
|
|
360
|
-
})
|
|
364
|
+
}), isShowDeleteDialog && isActive && /*#__PURE__*/React.createElement(CommentDeleteShadow, {
|
|
361
365
|
type: 'comment',
|
|
362
366
|
deleteConfirm: _deleteComment,
|
|
363
367
|
setIsShowDeleteModal: setIsShowDeleteDialog
|
|
@@ -63,6 +63,8 @@
|
|
|
63
63
|
padding-bottom: 10px;
|
|
64
64
|
margin-top: 10px;
|
|
65
65
|
margin-left: 30px;
|
|
66
|
+
width: 222px;
|
|
67
|
+
word-break: break-all;
|
|
66
68
|
}
|
|
67
69
|
|
|
68
70
|
.sdoc-comment-list-container .comment-header .comment-author__avatar {
|
|
@@ -158,18 +160,23 @@
|
|
|
158
160
|
|
|
159
161
|
.sdoc-comment-list-container .comment-editor-wrapper {
|
|
160
162
|
display: flex;
|
|
161
|
-
|
|
163
|
+
flex-direction: column;
|
|
162
164
|
justify-content: center;
|
|
163
165
|
padding: 0 16px;
|
|
166
|
+
cursor: text;
|
|
164
167
|
}
|
|
165
168
|
|
|
166
169
|
.sdoc-comment-list-container .comment-editor-wrapper .comment-editor {
|
|
167
|
-
|
|
168
|
-
|
|
170
|
+
margin-bottom: 10px;
|
|
171
|
+
min-height: 40px;
|
|
172
|
+
max-height: 120px;
|
|
173
|
+
min-width: 240px;
|
|
174
|
+
overflow: auto;
|
|
169
175
|
background: #fff;
|
|
170
176
|
border: 1px solid rgba(0, 0, 0, .12);
|
|
171
177
|
border-radius: 4px;
|
|
172
178
|
padding: 8px;
|
|
179
|
+
word-break: break-all;
|
|
173
180
|
}
|
|
174
181
|
|
|
175
182
|
.sdoc-comment-list-container .comment-editor-wrapper .comment-editor:focus-visible {
|
|
@@ -107,11 +107,10 @@ var CommentList = function CommentList(_ref) {
|
|
|
107
107
|
return /*#__PURE__*/React.createElement(CommentItemWrapper, props);
|
|
108
108
|
})), comments.length === 0 && /*#__PURE__*/React.createElement("div", {
|
|
109
109
|
className: "comment-ui-container active"
|
|
110
|
-
}, /*#__PURE__*/React.createElement("div", {
|
|
111
|
-
className: "comment-editor-wrapper"
|
|
112
110
|
}, /*#__PURE__*/React.createElement(CommentEditor, {
|
|
111
|
+
type: "comment",
|
|
113
112
|
insertContent: insertContent,
|
|
114
113
|
selectionElement: selectionElement
|
|
115
|
-
})))
|
|
114
|
+
})));
|
|
116
115
|
};
|
|
117
116
|
export default CommentList;
|
package/dist/basic-sdk/editor.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
2
|
-
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
2
|
+
import React, { useCallback, useEffect, useMemo, useRef, useState, forwardRef, useImperativeHandle, Fragment } from 'react';
|
|
3
3
|
import { Editable, ReactEditor, Slate } from '@seafile/slate-react';
|
|
4
4
|
import defaultEditor, { renderLeaf, renderElement, Toolbar, ContextToolbar } from './extension';
|
|
5
5
|
import { focusEditor, getAboveBlockNode, getNextNode, getPrevNode, isSelectionAtBlockEnd, isSelectionAtBlockStart } from './extension/core';
|
|
@@ -17,10 +17,11 @@ import { usePipDecorate } from './decorates';
|
|
|
17
17
|
import { getCursorPosition, getDomHeight, getDomMarginTop } from './utils/dom-utils';
|
|
18
18
|
import EventBus from './utils/event-bus';
|
|
19
19
|
import { ColorProvider } from './hooks/use-color-context';
|
|
20
|
+
import ArticleContainer from './layout/article-container';
|
|
20
21
|
import './assets/css/layout.css';
|
|
21
22
|
import './assets/css/sdoc-editor-plugins.css';
|
|
22
23
|
import './assets/css/dropdown-menu.css';
|
|
23
|
-
var SDocEditor = function
|
|
24
|
+
var SDocEditor = forwardRef(function (_ref, ref) {
|
|
24
25
|
var document = _ref.document,
|
|
25
26
|
config = _ref.config;
|
|
26
27
|
// init editor
|
|
@@ -42,7 +43,6 @@ var SDocEditor = function SDocEditor(_ref) {
|
|
|
42
43
|
var _useCursors = useCursors(editor),
|
|
43
44
|
cursors = _useCursors.cursors;
|
|
44
45
|
var scrollRef = useRef(null);
|
|
45
|
-
var articleRef = useRef(null);
|
|
46
46
|
var decorate = usePipDecorate(editor);
|
|
47
47
|
|
|
48
48
|
// init eventHandler
|
|
@@ -51,6 +51,16 @@ var SDocEditor = function SDocEditor(_ref) {
|
|
|
51
51
|
return new EventProxy(editor);
|
|
52
52
|
}, []);
|
|
53
53
|
|
|
54
|
+
// The parent component can call the method of this component through ref
|
|
55
|
+
useImperativeHandle(ref, function () {
|
|
56
|
+
return {
|
|
57
|
+
// get latest value
|
|
58
|
+
getValue: function getValue() {
|
|
59
|
+
return slateValue;
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
}, [slateValue]);
|
|
63
|
+
|
|
54
64
|
// useMount: init socket connection
|
|
55
65
|
useEffect(function () {
|
|
56
66
|
editor.openConnection();
|
|
@@ -63,8 +73,6 @@ var SDocEditor = function SDocEditor(_ref) {
|
|
|
63
73
|
// useMount: focus editor
|
|
64
74
|
useEffect(function () {
|
|
65
75
|
var timer = setTimeout(function () {
|
|
66
|
-
// real width
|
|
67
|
-
editor.width = articleRef.current.children[0].clientWidth;
|
|
68
76
|
focusEditor(editor);
|
|
69
77
|
}, 300);
|
|
70
78
|
return function () {
|
|
@@ -175,32 +183,10 @@ var SDocEditor = function SDocEditor(_ref) {
|
|
|
175
183
|
|
|
176
184
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
177
185
|
}, []);
|
|
178
|
-
var _useState3 = useState(
|
|
186
|
+
var _useState3 = useState(0),
|
|
179
187
|
_useState4 = _slicedToArray(_useState3, 2),
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
var handleWindowResize = useCallback(function () {
|
|
183
|
-
var rect = scrollRef.current.getBoundingClientRect();
|
|
184
|
-
var articleRect = articleRef.current.getBoundingClientRect();
|
|
185
|
-
if ((rect.width - articleRect.width) / 2 < 280) {
|
|
186
|
-
setContainerStyle({
|
|
187
|
-
marginLeft: '280px'
|
|
188
|
-
});
|
|
189
|
-
} else {
|
|
190
|
-
setContainerStyle({});
|
|
191
|
-
}
|
|
192
|
-
}, []);
|
|
193
|
-
useEffect(function () {
|
|
194
|
-
handleWindowResize();
|
|
195
|
-
window.addEventListener('resize', handleWindowResize);
|
|
196
|
-
return function () {
|
|
197
|
-
window.removeEventListener('resize', handleWindowResize);
|
|
198
|
-
};
|
|
199
|
-
}, [handleWindowResize]);
|
|
200
|
-
var _useState5 = useState(0),
|
|
201
|
-
_useState6 = _slicedToArray(_useState5, 2),
|
|
202
|
-
scrollLeft = _useState6[0],
|
|
203
|
-
setScrollLeft = _useState6[1];
|
|
188
|
+
scrollLeft = _useState4[0],
|
|
189
|
+
setScrollLeft = _useState4[1];
|
|
204
190
|
var onWrapperScroll = useCallback(function (event) {
|
|
205
191
|
var scrollLeft = event.target.scrollLeft;
|
|
206
192
|
setScrollLeft(scrollLeft);
|
|
@@ -221,11 +207,8 @@ var SDocEditor = function SDocEditor(_ref) {
|
|
|
221
207
|
className: "sdoc-absolute-wrapper"
|
|
222
208
|
}, /*#__PURE__*/React.createElement("div", {
|
|
223
209
|
ref: scrollRef,
|
|
224
|
-
className: "sdoc-
|
|
210
|
+
className: "sdoc-scroll-container",
|
|
225
211
|
onScroll: onWrapperScroll
|
|
226
|
-
}, /*#__PURE__*/React.createElement("div", {
|
|
227
|
-
className: "sdoc-article-container",
|
|
228
|
-
style: containerStyle
|
|
229
212
|
}, /*#__PURE__*/React.createElement(ScrollContext.Provider, {
|
|
230
213
|
value: {
|
|
231
214
|
scrollRef: scrollRef
|
|
@@ -234,10 +217,9 @@ var SDocEditor = function SDocEditor(_ref) {
|
|
|
234
217
|
editor: editor,
|
|
235
218
|
value: slateValue,
|
|
236
219
|
onChange: onChange
|
|
237
|
-
}, /*#__PURE__*/React.createElement(
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
}, /*#__PURE__*/React.createElement(SetNodeToDecorations, null), /*#__PURE__*/React.createElement(Editable, {
|
|
220
|
+
}, /*#__PURE__*/React.createElement(ArticleContainer, {
|
|
221
|
+
editor: editor
|
|
222
|
+
}, /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement(ContextToolbar, null), /*#__PURE__*/React.createElement(SetNodeToDecorations, null), /*#__PURE__*/React.createElement(Editable, {
|
|
241
223
|
cursors: cursors,
|
|
242
224
|
renderElement: renderElement,
|
|
243
225
|
renderLeaf: renderLeaf,
|
|
@@ -245,6 +227,6 @@ var SDocEditor = function SDocEditor(_ref) {
|
|
|
245
227
|
onMouseDown: onMouseDown,
|
|
246
228
|
decorate: decorate,
|
|
247
229
|
onCut: eventProxy.onCut
|
|
248
|
-
})), /*#__PURE__*/React.createElement(CommentWrapper, null)))))))))));
|
|
249
|
-
};
|
|
230
|
+
})), /*#__PURE__*/React.createElement(CommentContextProvider, null, /*#__PURE__*/React.createElement(CommentWrapper, null)))))))))));
|
|
231
|
+
});
|
|
250
232
|
export default SDocEditor;
|
|
@@ -89,6 +89,7 @@ var CodeBlock = function CodeBlock(_ref) {
|
|
|
89
89
|
}, []);
|
|
90
90
|
var onScroll = useCallback(function (e) {
|
|
91
91
|
if (readOnly) return;
|
|
92
|
+
if (!showHoverMenu) return;
|
|
92
93
|
if (e.currentTarget.scrollTop) {
|
|
93
94
|
var _codeBlockRef$current2 = codeBlockRef.current.getBoundingClientRect(),
|
|
94
95
|
top = _codeBlockRef$current2.top,
|
|
@@ -101,17 +102,18 @@ var CodeBlock = function CodeBlock(_ref) {
|
|
|
101
102
|
|
|
102
103
|
setMenuPosition(newMenuPosition);
|
|
103
104
|
}
|
|
104
|
-
|
|
105
|
-
}, []);
|
|
105
|
+
}, [readOnly, showHoverMenu]);
|
|
106
106
|
useEffect(function () {
|
|
107
107
|
if (readOnly) return;
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
108
|
+
var observerRefValue = null;
|
|
109
|
+
if (scrollRef.current) {
|
|
110
|
+
scrollRef.current.addEventListener('scroll', onScroll);
|
|
111
|
+
observerRefValue = scrollRef.current;
|
|
112
112
|
}
|
|
113
|
-
|
|
114
|
-
|
|
113
|
+
return function () {
|
|
114
|
+
observerRefValue.removeEventListener('scroll', onScroll);
|
|
115
|
+
};
|
|
116
|
+
}, [onScroll, readOnly, scrollRef]);
|
|
115
117
|
var isEntering = useCallback(function (e) {
|
|
116
118
|
return !editor.operations.every(function (operation) {
|
|
117
119
|
return operation.type === 'set_selection';
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
2
|
+
import React, { useEffect, useRef, useState } from 'react';
|
|
3
|
+
import { useScrollContext } from '../hooks/use-scroll-context';
|
|
4
|
+
export default function ArticleContainer(_ref) {
|
|
5
|
+
var editor = _ref.editor,
|
|
6
|
+
readOnly = _ref.readOnly,
|
|
7
|
+
children = _ref.children;
|
|
8
|
+
var articleRef = useRef(null);
|
|
9
|
+
useEffect(function () {
|
|
10
|
+
editor.width = articleRef.current.children[0].clientWidth;
|
|
11
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
12
|
+
}, []);
|
|
13
|
+
var scrollRef = useScrollContext();
|
|
14
|
+
var _useState = useState({}),
|
|
15
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
16
|
+
containerStyle = _useState2[0],
|
|
17
|
+
setContainerStyle = _useState2[1];
|
|
18
|
+
useEffect(function () {
|
|
19
|
+
if (readOnly) return;
|
|
20
|
+
var handleWindowResize = function handleWindowResize() {
|
|
21
|
+
var rect = scrollRef.current.getBoundingClientRect();
|
|
22
|
+
var articleRect = articleRef.current.getBoundingClientRect();
|
|
23
|
+
if ((rect.width - articleRect.width) / 2 < 280) {
|
|
24
|
+
setContainerStyle({
|
|
25
|
+
marginLeft: '280px'
|
|
26
|
+
});
|
|
27
|
+
} else {
|
|
28
|
+
setContainerStyle({});
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
window.addEventListener('resize', handleWindowResize);
|
|
32
|
+
return function () {
|
|
33
|
+
window.removeEventListener('resize', handleWindowResize);
|
|
34
|
+
};
|
|
35
|
+
}, [readOnly, scrollRef]);
|
|
36
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
37
|
+
className: "sdoc-article-container",
|
|
38
|
+
style: containerStyle
|
|
39
|
+
}, React.Children.count(children) === 1 && /*#__PURE__*/React.createElement("div", {
|
|
40
|
+
className: "article",
|
|
41
|
+
ref: articleRef
|
|
42
|
+
}, children), React.Children.count(children) === 2 && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
|
|
43
|
+
className: "article",
|
|
44
|
+
ref: articleRef
|
|
45
|
+
}, children[0]), children[1]));
|
|
46
|
+
}
|
|
47
|
+
ArticleContainer.defaultProps = {
|
|
48
|
+
readOnly: false
|
|
49
|
+
};
|
|
@@ -1,36 +1,31 @@
|
|
|
1
|
-
import React, {
|
|
1
|
+
import React, { Fragment, useRef } from 'react';
|
|
2
2
|
import { Editable, Slate } from '@seafile/slate-react';
|
|
3
3
|
import defaultEditor, { renderLeaf as _renderLeaf, renderElement as _renderElement } from '../extension';
|
|
4
4
|
import withNodeId from '../node-id';
|
|
5
5
|
import { ScrollContext } from '../hooks/use-scroll-context';
|
|
6
|
-
import { generateDefaultDocContent } from '../../utils';
|
|
6
|
+
import { generateDefaultDocContent, isMobile } from '../../utils';
|
|
7
7
|
import { SetNodeToDecorations } from '../highlight-decorate/setNodeToDecorations';
|
|
8
8
|
import { usePipDecorate } from '../decorates';
|
|
9
|
+
import ArticleContainer from '../layout/article-container';
|
|
9
10
|
import '../assets/css/layout.css';
|
|
10
11
|
import '../assets/css/sdoc-editor-plugins.css';
|
|
11
12
|
import '../assets/css/dropdown-menu.css';
|
|
13
|
+
import '../assets/css/simple-viewer.css';
|
|
12
14
|
var SDocViewer = function SDocViewer(_ref) {
|
|
13
15
|
var document = _ref.document,
|
|
14
16
|
customRenderLeaf = _ref.renderLeaf,
|
|
15
17
|
customRenderElement = _ref.renderElement;
|
|
16
18
|
var editor = withNodeId(defaultEditor);
|
|
17
19
|
var slateValue = (document || generateDefaultDocContent()).children;
|
|
18
|
-
var articleRef = useRef(null);
|
|
19
20
|
var scrollRef = useRef(null);
|
|
20
21
|
var decorate = usePipDecorate(editor);
|
|
21
|
-
useEffect(function () {
|
|
22
|
-
editor.width = articleRef.current.children[0].clientWidth;
|
|
23
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
24
|
-
}, []);
|
|
25
22
|
return /*#__PURE__*/React.createElement("div", {
|
|
26
|
-
className: "sdoc-editor-container"
|
|
23
|
+
className: "sdoc-editor-container ".concat(isMobile ? 'mobile' : '')
|
|
27
24
|
}, /*#__PURE__*/React.createElement("div", {
|
|
28
25
|
className: "sdoc-editor-content readonly"
|
|
29
26
|
}, /*#__PURE__*/React.createElement("div", {
|
|
30
27
|
ref: scrollRef,
|
|
31
|
-
className: "sdoc-
|
|
32
|
-
}, /*#__PURE__*/React.createElement("div", {
|
|
33
|
-
className: "sdoc-article-container"
|
|
28
|
+
className: "sdoc-scroll-container"
|
|
34
29
|
}, /*#__PURE__*/React.createElement(ScrollContext.Provider, {
|
|
35
30
|
value: {
|
|
36
31
|
scrollRef: scrollRef
|
|
@@ -38,10 +33,10 @@ var SDocViewer = function SDocViewer(_ref) {
|
|
|
38
33
|
}, /*#__PURE__*/React.createElement(Slate, {
|
|
39
34
|
editor: editor,
|
|
40
35
|
value: slateValue
|
|
41
|
-
}, /*#__PURE__*/React.createElement(
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}, /*#__PURE__*/React.createElement(SetNodeToDecorations, null), /*#__PURE__*/React.createElement(Editable, {
|
|
36
|
+
}, /*#__PURE__*/React.createElement(ArticleContainer, {
|
|
37
|
+
editor: editor,
|
|
38
|
+
readOnly: true
|
|
39
|
+
}, /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement(SetNodeToDecorations, null), /*#__PURE__*/React.createElement(Editable, {
|
|
45
40
|
readOnly: true,
|
|
46
41
|
placeholder: "",
|
|
47
42
|
renderElement: function renderElement(props) {
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
1
2
|
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
2
|
-
import React, { useCallback, useEffect, useState } from 'react';
|
|
3
|
+
import React, { useCallback, useEffect, useRef, useState } from 'react';
|
|
3
4
|
import { withTranslation } from 'react-i18next';
|
|
5
|
+
import deepCopy from 'deep-copy';
|
|
4
6
|
import { SDocEditor } from '../basic-sdk';
|
|
5
7
|
import Loading from '../components/loading';
|
|
6
8
|
import DocInfo from '../components/doc-info';
|
|
@@ -15,6 +17,7 @@ var SimpleEditor = function SimpleEditor(_ref) {
|
|
|
15
17
|
var isStarred = _ref.isStarred,
|
|
16
18
|
isDraft = _ref.isDraft,
|
|
17
19
|
t = _ref.t;
|
|
20
|
+
var editorRef = useRef(null);
|
|
18
21
|
var _useState = useState(true),
|
|
19
22
|
_useState2 = _slicedToArray(_useState, 2),
|
|
20
23
|
isFirstLoad = _useState2[0],
|
|
@@ -77,35 +80,28 @@ var SimpleEditor = function SimpleEditor(_ref) {
|
|
|
77
80
|
var initChangesData = useCallback(function () {
|
|
78
81
|
setShowChanges(true);
|
|
79
82
|
context.getSeadocRevisionDownloadLinks().then(function (res) {
|
|
80
|
-
var
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
}).then(function (originContent) {
|
|
89
|
-
setCurrentContent(revisionContent);
|
|
90
|
-
setLastContent(originContent);
|
|
91
|
-
setErrorMessage(null);
|
|
92
|
-
setContextInit(true);
|
|
93
|
-
}).catch(function (error) {
|
|
94
|
-
setErrorMessage('Load_doc_content_error');
|
|
95
|
-
setContextInit(true);
|
|
96
|
-
});
|
|
97
|
-
}).catch(function (error) {
|
|
98
|
-
setErrorMessage('Load_doc_content_error');
|
|
99
|
-
setContextInit(true);
|
|
100
|
-
});
|
|
83
|
+
var originFileDownloadLink = res.data.origin_file_download_link;
|
|
84
|
+
return fetch(originFileDownloadLink);
|
|
85
|
+
}).then(function (res) {
|
|
86
|
+
return res.json();
|
|
87
|
+
}).then(function (originContent) {
|
|
88
|
+
setLastContent(originContent);
|
|
89
|
+
setErrorMessage(null);
|
|
90
|
+
setContextInit(true);
|
|
101
91
|
}).catch(function (error) {
|
|
102
92
|
setErrorMessage('Load_doc_content_error');
|
|
103
93
|
setContextInit(true);
|
|
104
94
|
});
|
|
105
95
|
|
|
106
96
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
107
|
-
}, []);
|
|
97
|
+
}, [document]);
|
|
108
98
|
var toggleViewChanges = useCallback(function (isShowChanges) {
|
|
99
|
+
if (isShowChanges) {
|
|
100
|
+
var newestValue = editorRef.current.getValue();
|
|
101
|
+
setCurrentContent(deepCopy(_objectSpread(_objectSpread({}, document), {}, {
|
|
102
|
+
children: newestValue
|
|
103
|
+
})));
|
|
104
|
+
}
|
|
109
105
|
setContextInit(false);
|
|
110
106
|
if (isShowChanges) {
|
|
111
107
|
initChangesData();
|
|
@@ -114,7 +110,7 @@ var SimpleEditor = function SimpleEditor(_ref) {
|
|
|
114
110
|
initDocumentData(false);
|
|
115
111
|
|
|
116
112
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
117
|
-
}, []);
|
|
113
|
+
}, [document]);
|
|
118
114
|
if (isFirstLoad && !isContextInit) {
|
|
119
115
|
return /*#__PURE__*/React.createElement(Loading, null);
|
|
120
116
|
}
|
|
@@ -140,6 +136,7 @@ var SimpleEditor = function SimpleEditor(_ref) {
|
|
|
140
136
|
}) : /*#__PURE__*/React.createElement(SDocEditor, {
|
|
141
137
|
config: context.getEditorConfig(),
|
|
142
138
|
document: document,
|
|
139
|
+
ref: editorRef,
|
|
143
140
|
isOpenSocket: context.getSetting('isOpenSocket')
|
|
144
141
|
})))));
|
|
145
142
|
};
|
package/dist/utils/index.js
CHANGED
|
@@ -44,4 +44,5 @@ export var isMac = function isMac() {
|
|
|
44
44
|
var platform = navigator.platform;
|
|
45
45
|
return platform === 'Mac68K' || platform === 'MacPPC' || platform === 'Macintosh' || platform === 'MacIntel';
|
|
46
46
|
};
|
|
47
|
+
export var isMobile = typeof window !== 'undefined' && (window.innerWidth < 768 || navigator.userAgent.toLowerCase().match(/(ipod|ipad|iphone|android|coolpad|mmp|smartphone|midp|wap|xoom|symbian|j2me|blackberry|wince)/i) != null);
|
|
47
48
|
export { DateUtils, LocalStorage };
|
package/package.json
CHANGED