@seafile/sdoc-editor 0.2.2 → 0.2.4
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/comment/comment-editor.js +58 -21
- package/dist/basic-sdk/comment/comment/comment-list.css +27 -0
- package/dist/basic-sdk/comment/comment/comment-list.js +16 -0
- package/dist/basic-sdk/comment/comment/editor-comment.js +21 -26
- package/dist/basic-sdk/constants/index.js +2 -1
- package/dist/basic-sdk/extension/commons/tooltip/index.js +4 -2
- package/dist/basic-sdk/extension/plugins/image/hover-menu/index.css +0 -18
- package/dist/basic-sdk/extension/plugins/image/hover-menu/index.js +25 -5
- package/dist/basic-sdk/extension/plugins/image/render-elem.js +16 -12
- package/dist/basic-sdk/layout/article-container.js +9 -2
- package/package.json +1 -1
- package/public/locales/en/sdoc-editor.json +3 -1
- package/public/locales/zh_CN/sdoc-editor.json +3 -1
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
import
|
|
2
|
-
import classNames from 'classnames';
|
|
3
|
-
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
1
|
+
import React, { useCallback, useEffect, useMemo, useRef } from 'react';
|
|
4
2
|
import { useTranslation } from 'react-i18next';
|
|
5
3
|
import { Button } from 'reactstrap';
|
|
4
|
+
import classNames from 'classnames';
|
|
5
|
+
import { useScrollContext } from '../../hooks/use-scroll-context';
|
|
6
|
+
import context from '../../../context';
|
|
7
|
+
import EventBus from '../../utils/event-bus';
|
|
8
|
+
import { INTERNAL_EVENT } from '../../constants';
|
|
6
9
|
var getSubmitTip = function getSubmitTip(type, content) {
|
|
7
10
|
if (content) return 'Save';
|
|
8
11
|
return type === 'comment' ? 'Comment' : 'Reply';
|
|
@@ -17,18 +20,44 @@ var CommentEditor = function CommentEditor(_ref) {
|
|
|
17
20
|
setIsEditing = _ref.setIsEditing,
|
|
18
21
|
hiddenComment = _ref.hiddenComment;
|
|
19
22
|
var commentRef = useRef();
|
|
23
|
+
var commentWrapperRef = useRef();
|
|
20
24
|
var _useTranslation = useTranslation(),
|
|
21
25
|
t = _useTranslation.t;
|
|
22
|
-
var
|
|
23
|
-
_useState2 = _slicedToArray(_useState, 2),
|
|
24
|
-
isFocus = _useState2[0],
|
|
25
|
-
setIsFocus = _useState2[1];
|
|
26
|
+
var scrollRef = useScrollContext();
|
|
26
27
|
|
|
27
|
-
// onMount
|
|
28
|
+
// onMount: comment content
|
|
28
29
|
useEffect(function () {
|
|
29
|
-
if (content)
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
if (!content) return;
|
|
31
|
+
commentRef.current.textContent = content;
|
|
32
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
33
|
+
}, []);
|
|
34
|
+
|
|
35
|
+
// onMount: set input focus
|
|
36
|
+
useEffect(function () {
|
|
37
|
+
if (type !== 'comment') return;
|
|
38
|
+
commentRef.current && commentRef.current.focus();
|
|
39
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
40
|
+
}, []);
|
|
41
|
+
|
|
42
|
+
// onMount: set scrollLeft
|
|
43
|
+
useEffect(function () {
|
|
44
|
+
if (!commentWrapperRef.current) return;
|
|
45
|
+
var _commentWrapperRef$cu = commentWrapperRef.current.getBoundingClientRect(),
|
|
46
|
+
right = _commentWrapperRef$cu.right,
|
|
47
|
+
width = _commentWrapperRef$cu.width;
|
|
48
|
+
if (right <= window.innerWidth) return;
|
|
49
|
+
if (!scrollRef.current) return;
|
|
50
|
+
scrollRef.current.scrollLeft = scrollRef.current.scrollLeft + width;
|
|
51
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
52
|
+
}, []);
|
|
53
|
+
|
|
54
|
+
// onMount: hidden comment
|
|
55
|
+
useEffect(function () {
|
|
56
|
+
var eventBus = EventBus.getInstance();
|
|
57
|
+
var unsubscribe = eventBus.subscribe(INTERNAL_EVENT.ARTICLE_CLICK, hiddenComment);
|
|
58
|
+
return function () {
|
|
59
|
+
unsubscribe();
|
|
60
|
+
};
|
|
32
61
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
33
62
|
}, []);
|
|
34
63
|
var updateValue = useCallback(function (value) {
|
|
@@ -47,7 +76,6 @@ var CommentEditor = function CommentEditor(_ref) {
|
|
|
47
76
|
}, [updateValue]);
|
|
48
77
|
var onCancel = useCallback(function (event) {
|
|
49
78
|
event.stopPropagation();
|
|
50
|
-
setIsFocus(false);
|
|
51
79
|
commentRef.current.textContent = '';
|
|
52
80
|
setIsEditing && setIsEditing(false);
|
|
53
81
|
hiddenComment && hiddenComment(false);
|
|
@@ -65,23 +93,32 @@ var CommentEditor = function CommentEditor(_ref) {
|
|
|
65
93
|
onCancel();
|
|
66
94
|
}
|
|
67
95
|
}, [onCancel, onSubmit]);
|
|
68
|
-
placeholder = t(placeholder);
|
|
69
96
|
var submitTip = useMemo(function () {
|
|
70
97
|
return getSubmitTip(type, content);
|
|
71
98
|
}, [content, type]);
|
|
99
|
+
var userInfo = context.getUserInfo();
|
|
72
100
|
return /*#__PURE__*/React.createElement("div", {
|
|
73
|
-
className: classNames('comment-editor-wrapper', className)
|
|
101
|
+
className: classNames('comment-editor-wrapper', className),
|
|
102
|
+
ref: commentWrapperRef
|
|
103
|
+
}, type === 'comment' && /*#__PURE__*/React.createElement("div", {
|
|
104
|
+
className: "comment-editor-user-info"
|
|
74
105
|
}, /*#__PURE__*/React.createElement("div", {
|
|
106
|
+
className: "comment-editor-user-img"
|
|
107
|
+
}, /*#__PURE__*/React.createElement("img", {
|
|
108
|
+
src: userInfo.avatar_url,
|
|
109
|
+
alt: "",
|
|
110
|
+
height: "100%",
|
|
111
|
+
width: "100%"
|
|
112
|
+
})), /*#__PURE__*/React.createElement("div", {
|
|
113
|
+
className: "comment-editor-user-name"
|
|
114
|
+
}, userInfo.name)), /*#__PURE__*/React.createElement("div", {
|
|
75
115
|
ref: commentRef,
|
|
76
116
|
contentEditable: "true",
|
|
77
117
|
className: "comment-editor",
|
|
78
|
-
placeholder: placeholder,
|
|
79
|
-
onKeyDown: onKeyDown
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
}
|
|
83
|
-
}), isFocus && /*#__PURE__*/React.createElement("div", {
|
|
84
|
-
className: "editor-operations"
|
|
118
|
+
placeholder: t(placeholder),
|
|
119
|
+
onKeyDown: onKeyDown
|
|
120
|
+
}), /*#__PURE__*/React.createElement("div", {
|
|
121
|
+
className: "comment-operations"
|
|
85
122
|
}, /*#__PURE__*/React.createElement(Button, {
|
|
86
123
|
className: "mr-2",
|
|
87
124
|
onClick: onCancel
|
|
@@ -191,3 +191,30 @@
|
|
|
191
191
|
.sdoc-comment-list-container .comment-editor-wrapper .comment-editor:focus {
|
|
192
192
|
border: 1px solid rgba(0, 0, 0, .12);
|
|
193
193
|
}
|
|
194
|
+
|
|
195
|
+
.sdoc-comment-list-container .comment-editor-wrapper .comment-editor-user-info {
|
|
196
|
+
display: flex;
|
|
197
|
+
align-items: center;
|
|
198
|
+
margin-bottom: 10px;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
.sdoc-comment-list-container .comment-editor-wrapper .comment-editor-user-info .comment-editor-user-img {
|
|
202
|
+
height: 30px;
|
|
203
|
+
width: 30px;
|
|
204
|
+
border-radius: 50%;
|
|
205
|
+
overflow: hidden;
|
|
206
|
+
margin-right: 8px;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
.sdoc-comment-list-container .comment-editor-wrapper .comment-editor-user-info .comment-editor-user-name {
|
|
210
|
+
flex: 1;
|
|
211
|
+
overflow: hidden;
|
|
212
|
+
text-overflow: ellipsis;
|
|
213
|
+
white-space: nowrap;
|
|
214
|
+
user-select: none;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
.sdoc-comment-list-container .comment-editor-wrapper .comment-operations {
|
|
218
|
+
display: flex;
|
|
219
|
+
justify-content: flex-end;
|
|
220
|
+
}
|
|
@@ -9,6 +9,8 @@ import { useCommentListPosition } from '../../hooks/use-selection-position';
|
|
|
9
9
|
import { useCommentContext } from '../hooks/use-comment-context';
|
|
10
10
|
import CommentEditor from './comment-editor';
|
|
11
11
|
import CommentItemWrapper from './comment-item-wrapper';
|
|
12
|
+
import EventBus from '../../utils/event-bus';
|
|
13
|
+
import { INTERNAL_EVENT } from '../../constants';
|
|
12
14
|
import './comment-list.css';
|
|
13
15
|
var CommentList = function CommentList(_ref) {
|
|
14
16
|
var comments = _ref.comments,
|
|
@@ -20,6 +22,20 @@ var CommentList = function CommentList(_ref) {
|
|
|
20
22
|
_useState2 = _slicedToArray(_useState, 2),
|
|
21
23
|
activeComment = _useState2[0],
|
|
22
24
|
setActiveComment = _useState2[1];
|
|
25
|
+
var handelArticleClick = useCallback(function (event) {
|
|
26
|
+
if (event.target.className !== 'article') return;
|
|
27
|
+
hiddenComment();
|
|
28
|
+
}, [hiddenComment]);
|
|
29
|
+
|
|
30
|
+
// onMount: hidden comment
|
|
31
|
+
useEffect(function () {
|
|
32
|
+
var eventBus = EventBus.getInstance();
|
|
33
|
+
var unsubscribe = eventBus.subscribe(INTERNAL_EVENT.ARTICLE_CLICK, handelArticleClick);
|
|
34
|
+
return function () {
|
|
35
|
+
unsubscribe();
|
|
36
|
+
};
|
|
37
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
38
|
+
}, []);
|
|
23
39
|
var onCommentClick = useCallback(function (comment) {
|
|
24
40
|
if (activeComment && activeComment.id === comment.id) return;
|
|
25
41
|
setActiveComment(comment);
|
|
@@ -19,18 +19,6 @@ var EditorComment = function EditorComment() {
|
|
|
19
19
|
var onAddCommentToggle = useCallback(function () {
|
|
20
20
|
setIsShowComments(true);
|
|
21
21
|
}, []);
|
|
22
|
-
var cursor = useCursorPosition();
|
|
23
|
-
var style = useMemo(function () {
|
|
24
|
-
var _Node$string;
|
|
25
|
-
if (selectionElement && ((_Node$string = Node.string(selectionElement)) === null || _Node$string === void 0 ? void 0 : _Node$string.length) === 0) {
|
|
26
|
-
return {
|
|
27
|
-
top: '-99999px'
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
return {
|
|
31
|
-
top: cursor.y === 0 || isShowComments ? '-99999px' : cursor.y
|
|
32
|
-
};
|
|
33
|
-
}, [cursor, isShowComments, selectionElement]);
|
|
34
22
|
|
|
35
23
|
// When selectionElement update, recalculate comment's panel state
|
|
36
24
|
var _useState3 = useState([]),
|
|
@@ -52,24 +40,31 @@ var EditorComment = function EditorComment() {
|
|
|
52
40
|
setComments([]);
|
|
53
41
|
setIsShowComments(false);
|
|
54
42
|
}, [element_comments_map, selectionElement, editor.selection]);
|
|
43
|
+
var cursor = useCursorPosition();
|
|
44
|
+
var style = useMemo(function () {
|
|
45
|
+
var _Node$string;
|
|
46
|
+
if (selectionElement && ((_Node$string = Node.string(selectionElement)) === null || _Node$string === void 0 ? void 0 : _Node$string.length) === 0) return {
|
|
47
|
+
top: '-99999px'
|
|
48
|
+
};
|
|
49
|
+
var comments = element_comments_map[selectionElement === null || selectionElement === void 0 ? void 0 : selectionElement.id];
|
|
50
|
+
var unresolvedComments = comments && comments.filter(function (item) {
|
|
51
|
+
return !item.resolved;
|
|
52
|
+
});
|
|
53
|
+
var hasComments = unresolvedComments && unresolvedComments.length > 0;
|
|
54
|
+
if (hasComments) return {
|
|
55
|
+
top: '-99999px'
|
|
56
|
+
};
|
|
57
|
+
if (cursor.y === 0 || isShowComments) return {
|
|
58
|
+
top: '-99999px'
|
|
59
|
+
};
|
|
60
|
+
return {
|
|
61
|
+
top: cursor.y
|
|
62
|
+
};
|
|
63
|
+
}, [cursor, isShowComments, selectionElement, element_comments_map]);
|
|
55
64
|
var hiddenComment = useCallback(function () {
|
|
56
65
|
setComments([]);
|
|
57
66
|
setIsShowComments(false);
|
|
58
67
|
}, []);
|
|
59
|
-
var onHiddenComment = useCallback(function (e) {
|
|
60
|
-
if (e.target.className === 'article') {
|
|
61
|
-
hiddenComment();
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
65
|
-
}, []);
|
|
66
|
-
useEffect(function () {
|
|
67
|
-
window.addEventListener('click', onHiddenComment);
|
|
68
|
-
return function () {
|
|
69
|
-
window.removeEventListener('click', onHiddenComment);
|
|
70
|
-
};
|
|
71
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
72
|
-
}, []);
|
|
73
68
|
return /*#__PURE__*/React.createElement("div", {
|
|
74
69
|
className: "sdoc-comment-container"
|
|
75
70
|
}, /*#__PURE__*/React.createElement("div", {
|
|
@@ -5,7 +5,8 @@ export var INTERNAL_EVENT = {
|
|
|
5
5
|
ON_MOUSE_ENTER_BLOCK: 'on_mouse_enter_block',
|
|
6
6
|
INSERT_ELEMENT: 'insert_element',
|
|
7
7
|
OUTLINE_STATE_CHANGED: 'outline_state_changed',
|
|
8
|
-
RELOAD_IMAGE: 'reload_image'
|
|
8
|
+
RELOAD_IMAGE: 'reload_image',
|
|
9
|
+
ARTICLE_CLICK: 'hidden_comment'
|
|
9
10
|
};
|
|
10
11
|
export var PAGE_EDIT_AREA_WIDTH = 672; // 672 = 794 - 2[borderLeft + borderRight] - 120[paddingLeft + paddingRight]
|
|
11
12
|
|
|
@@ -6,12 +6,14 @@ var Tooltip = function Tooltip(_ref) {
|
|
|
6
6
|
var target = _ref.target,
|
|
7
7
|
children = _ref.children,
|
|
8
8
|
className = _ref.className,
|
|
9
|
-
placement = _ref.placement
|
|
9
|
+
placement = _ref.placement,
|
|
10
|
+
_ref$fade = _ref.fade,
|
|
11
|
+
fade = _ref$fade === void 0 ? false : _ref$fade;
|
|
10
12
|
var popperClassName = classnames('sdoc-tooltip', className);
|
|
11
13
|
return /*#__PURE__*/React.createElement(UncontrolledTooltip, {
|
|
12
14
|
popperClassName: popperClassName,
|
|
13
15
|
target: target,
|
|
14
|
-
fade:
|
|
16
|
+
fade: fade,
|
|
15
17
|
placement: placement || 'bottom',
|
|
16
18
|
delay: 0
|
|
17
19
|
}, children);
|
|
@@ -49,24 +49,6 @@
|
|
|
49
49
|
background: #f1f1f1;
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
.sdoc-image-hover-menu-container .hover-menu-container .op-tooltip:hover::after {
|
|
53
|
-
position: absolute;
|
|
54
|
-
color: #212529;
|
|
55
|
-
content: attr(op-item-tooltip);
|
|
56
|
-
top: -40px;
|
|
57
|
-
left: -20px;
|
|
58
|
-
width: 70px;
|
|
59
|
-
height: 30px;
|
|
60
|
-
display: flex;
|
|
61
|
-
justify-content: center;
|
|
62
|
-
align-items: center;
|
|
63
|
-
background-color: #fff;
|
|
64
|
-
border-radius: 3px;
|
|
65
|
-
border: 1px solid #e8e8e8;
|
|
66
|
-
font-size: 12px;
|
|
67
|
-
box-shadow: 0 0 5px #ccc;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
52
|
.sdoc-image-hover-menu-container .hover-menu-container .icon-font {
|
|
71
53
|
font-size: 12px;
|
|
72
54
|
color: #999999;
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
2
2
|
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
3
|
-
import React, { useCallback, useState } from 'react';
|
|
3
|
+
import React, { useCallback, useEffect, useState } from 'react';
|
|
4
4
|
import { Transforms } from '@seafile/slate';
|
|
5
5
|
import { ReactEditor } from '@seafile/slate-react';
|
|
6
6
|
import { withTranslation } from 'react-i18next';
|
|
7
7
|
import classnames from 'classnames';
|
|
8
8
|
import { ElementPopover } from '../../../commons';
|
|
9
|
+
import Tooltip from '../../../commons/tooltip';
|
|
9
10
|
import ImagePreviewer from '../dialogs/image-previewer';
|
|
10
11
|
import { getImageURL } from '../helpers';
|
|
11
12
|
import { IMAGE_DISPLAY_TYPE, IMAGE_BORDER_TYPE } from '../constants';
|
|
@@ -18,9 +19,11 @@ var ImageHoverMenu = function ImageHoverMenu(_ref) {
|
|
|
18
19
|
onHideImageHoverMenu = _ref.onHideImageHoverMenu,
|
|
19
20
|
t = _ref.t;
|
|
20
21
|
var data = element.data,
|
|
21
|
-
display_type = element.display_type,
|
|
22
|
+
_element$display_type = element.display_type,
|
|
23
|
+
display_type = _element$display_type === void 0 ? IMAGE_DISPLAY_TYPE[0] : _element$display_type,
|
|
22
24
|
align = element.align,
|
|
23
|
-
border_type = element.border_type
|
|
25
|
+
_element$border_type = element.border_type,
|
|
26
|
+
border_type = _element$border_type === void 0 ? IMAGE_BORDER_TYPE[0].type : _element$border_type;
|
|
24
27
|
var _useState = useState({
|
|
25
28
|
displayPopover: false,
|
|
26
29
|
alignPopover: false,
|
|
@@ -33,6 +36,13 @@ var ImageHoverMenu = function ImageHoverMenu(_ref) {
|
|
|
33
36
|
_useState4 = _slicedToArray(_useState3, 2),
|
|
34
37
|
isShowImagePreview = _useState4[0],
|
|
35
38
|
setIsShowImagePreview = _useState4[1];
|
|
39
|
+
var _useState5 = useState(false),
|
|
40
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
|
41
|
+
isShowTooltip = _useState6[0],
|
|
42
|
+
setIsShowTooltip = _useState6[1];
|
|
43
|
+
useEffect(function () {
|
|
44
|
+
setIsShowTooltip(true);
|
|
45
|
+
}, []);
|
|
36
46
|
var onShowProver = useCallback(function (event, showProverKey) {
|
|
37
47
|
event.stopPropagation();
|
|
38
48
|
var newPopoverState = popoverState;
|
|
@@ -90,6 +100,7 @@ var ImageHoverMenu = function ImageHoverMenu(_ref) {
|
|
|
90
100
|
}), /*#__PURE__*/React.createElement("i", {
|
|
91
101
|
className: "sdocfont sdoc-drop-down icon-font"
|
|
92
102
|
})), /*#__PURE__*/React.createElement("span", {
|
|
103
|
+
id: "sdoc_image_border",
|
|
93
104
|
role: "button",
|
|
94
105
|
className: classnames('op-item', 'ml-1', {
|
|
95
106
|
'active': popoverState.borderPopover
|
|
@@ -101,9 +112,14 @@ var ImageHoverMenu = function ImageHoverMenu(_ref) {
|
|
|
101
112
|
className: "sdocfont sdoc-image icon-font mr-1"
|
|
102
113
|
}), /*#__PURE__*/React.createElement("i", {
|
|
103
114
|
className: "sdocfont sdoc-drop-down icon-font"
|
|
104
|
-
})
|
|
115
|
+
}), isShowTooltip && /*#__PURE__*/React.createElement(Tooltip, {
|
|
116
|
+
target: "sdoc_image_border",
|
|
117
|
+
placement: "top",
|
|
118
|
+
fade: true
|
|
119
|
+
}, t('Image_border')))), /*#__PURE__*/React.createElement("span", {
|
|
105
120
|
className: "op-group-item"
|
|
106
121
|
}, /*#__PURE__*/React.createElement("span", {
|
|
122
|
+
id: "sdoc_image_full_screen_mode",
|
|
107
123
|
role: "button",
|
|
108
124
|
className: "op-item",
|
|
109
125
|
onClick: function onClick(e) {
|
|
@@ -112,7 +128,11 @@ var ImageHoverMenu = function ImageHoverMenu(_ref) {
|
|
|
112
128
|
}
|
|
113
129
|
}, /*#__PURE__*/React.createElement("i", {
|
|
114
130
|
className: "sdocfont sdoc-fullscreen icon-font"
|
|
115
|
-
})
|
|
131
|
+
}), isShowTooltip && /*#__PURE__*/React.createElement(Tooltip, {
|
|
132
|
+
target: "sdoc_image_full_screen_mode",
|
|
133
|
+
placement: "top",
|
|
134
|
+
fade: true
|
|
135
|
+
}, t('Full_screen_mode'))))), popoverState.displayPopover && /*#__PURE__*/React.createElement("div", {
|
|
116
136
|
className: "sdoc-image-popover sdoc-dropdown-menu"
|
|
117
137
|
}, IMAGE_DISPLAY_TYPE.map(function (item) {
|
|
118
138
|
return /*#__PURE__*/React.createElement("div", {
|
|
@@ -40,8 +40,8 @@ var Image = function Image(_ref) {
|
|
|
40
40
|
var scrollRef = useScrollContext();
|
|
41
41
|
var _useState = useState(null),
|
|
42
42
|
_useState2 = _slicedToArray(_useState, 2),
|
|
43
|
-
|
|
44
|
-
|
|
43
|
+
movingWidth = _useState2[0],
|
|
44
|
+
setMovingWidth = _useState2[1];
|
|
45
45
|
var _useState3 = useState(false),
|
|
46
46
|
_useState4 = _slicedToArray(_useState3, 2),
|
|
47
47
|
isResizing = _useState4[0],
|
|
@@ -75,7 +75,8 @@ var Image = function Image(_ref) {
|
|
|
75
75
|
var changeX = event.clientX - ((_resizerRef$current = resizerRef.current) === null || _resizerRef$current === void 0 ? void 0 : _resizerRef$current.getBoundingClientRect().left) - 5;
|
|
76
76
|
var imageWidth = imageRef.current.width + changeX;
|
|
77
77
|
if (imageWidth < 20) return;
|
|
78
|
-
|
|
78
|
+
imageRef.current.width = imageWidth;
|
|
79
|
+
setMovingWidth(imageWidth);
|
|
79
80
|
}, []);
|
|
80
81
|
var onResizeEnd = useCallback(function (event) {
|
|
81
82
|
event.preventDefault();
|
|
@@ -88,12 +89,12 @@ var Image = function Image(_ref) {
|
|
|
88
89
|
'event': onResizeEnd
|
|
89
90
|
}]);
|
|
90
91
|
var newData = _objectSpread(_objectSpread({}, element.data), {}, {
|
|
91
|
-
width: width
|
|
92
|
+
width: imageRef.current.width
|
|
92
93
|
});
|
|
93
94
|
updateImage(editor, newData);
|
|
94
95
|
setIsResizing(false);
|
|
95
96
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
96
|
-
}, [editor, element.data
|
|
97
|
+
}, [editor, element.data]);
|
|
97
98
|
var onResizeStart = useCallback(function (event) {
|
|
98
99
|
event.preventDefault();
|
|
99
100
|
event.stopPropagation();
|
|
@@ -108,17 +109,19 @@ var Image = function Image(_ref) {
|
|
|
108
109
|
}, [onMouseMove, onResizeEnd, registerEvent]);
|
|
109
110
|
var getImageStyle = useCallback(function () {
|
|
110
111
|
var imageWidth = element.data.width || '';
|
|
111
|
-
if (
|
|
112
|
+
if (movingWidth) imageWidth = movingWidth;
|
|
112
113
|
return {
|
|
113
114
|
width: imageWidth
|
|
114
115
|
};
|
|
115
|
-
}, [element.data,
|
|
116
|
+
}, [element.data, movingWidth]);
|
|
116
117
|
var onScroll = useCallback(function () {
|
|
117
118
|
setPosition(imageRef.current);
|
|
118
119
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
119
120
|
}, []);
|
|
120
121
|
var onHideImageHoverMenu = useCallback(function (e) {
|
|
121
|
-
|
|
122
|
+
var _imagePreviewer$;
|
|
123
|
+
var imagePreviewer = document.getElementsByClassName('sf-editor-image-previewer');
|
|
124
|
+
if (e.target === imageRef.current || ((_imagePreviewer$ = imagePreviewer[0]) === null || _imagePreviewer$ === void 0 ? void 0 : _imagePreviewer$.contains(e.target))) return;
|
|
122
125
|
setIsShowImageHoverMenu(false);
|
|
123
126
|
}, []);
|
|
124
127
|
useEffect(function () {
|
|
@@ -152,9 +155,10 @@ var Image = function Image(_ref) {
|
|
|
152
155
|
if (elem) {
|
|
153
156
|
var _elem$getBoundingClie = elem.getBoundingClientRect(),
|
|
154
157
|
top = _elem$getBoundingClie.top,
|
|
155
|
-
left = _elem$getBoundingClie.left
|
|
158
|
+
left = _elem$getBoundingClie.left,
|
|
159
|
+
width = _elem$getBoundingClie.width;
|
|
156
160
|
var menuTop = top - 42;
|
|
157
|
-
var menuLeft = left -
|
|
161
|
+
var menuLeft = left - 222 / 2 + width / 2; // left = left distance - (menu width / 2) + (image with / 2)
|
|
158
162
|
setMenuPosition({
|
|
159
163
|
top: menuTop,
|
|
160
164
|
left: menuLeft
|
|
@@ -168,7 +172,7 @@ var Image = function Image(_ref) {
|
|
|
168
172
|
}, [setPosition]);
|
|
169
173
|
var reloadImage = useCallback(function () {
|
|
170
174
|
if (imageRef) {
|
|
171
|
-
imageRef.current = getImageURL(data.src);
|
|
175
|
+
imageRef.current['src'] = getImageURL(data.src);
|
|
172
176
|
}
|
|
173
177
|
}, [data.src]);
|
|
174
178
|
var onImageLoadError = useCallback(function () {
|
|
@@ -213,7 +217,7 @@ var Image = function Image(_ref) {
|
|
|
213
217
|
}), isResizing && /*#__PURE__*/React.createElement("span", {
|
|
214
218
|
className: "image-size",
|
|
215
219
|
contentEditable: false
|
|
216
|
-
}, /*#__PURE__*/React.createElement("span", null, t('Width'), ':', parseInt(
|
|
220
|
+
}, /*#__PURE__*/React.createElement("span", null, t('Width'), ':', parseInt(movingWidth || imageRef.current.clientWidth)), /*#__PURE__*/React.createElement("span", null, "\xA0\xA0"), /*#__PURE__*/React.createElement("span", null, t('Height'), ':', imageRef.current.clientHeight))), children), isShowImageHoverMenu && !readOnly && /*#__PURE__*/React.createElement(ImageHoverMenu, {
|
|
217
221
|
editor: editor,
|
|
218
222
|
menuPosition: menuPosition,
|
|
219
223
|
element: element,
|
|
@@ -31,6 +31,11 @@ export default function ArticleContainer(_ref) {
|
|
|
31
31
|
setContainerStyle({});
|
|
32
32
|
}
|
|
33
33
|
}, [scrollRef]);
|
|
34
|
+
var handelArticleClick = useCallback(function (event) {
|
|
35
|
+
if (!articleRef.current.contains(event.target)) return;
|
|
36
|
+
var eventBus = EventBus.getInstance();
|
|
37
|
+
eventBus.dispatch(INTERNAL_EVENT.ARTICLE_CLICK, event);
|
|
38
|
+
}, []);
|
|
34
39
|
useEffect(function () {
|
|
35
40
|
var eventBus = EventBus.getInstance();
|
|
36
41
|
var unsubscribeOutline = eventBus.subscribe(INTERNAL_EVENT.OUTLINE_STATE_CHANGED, handleWindowResize);
|
|
@@ -49,9 +54,11 @@ export default function ArticleContainer(_ref) {
|
|
|
49
54
|
style: containerStyle
|
|
50
55
|
}, React.Children.count(children) === 1 && /*#__PURE__*/React.createElement("div", {
|
|
51
56
|
className: "article",
|
|
52
|
-
ref: articleRef
|
|
57
|
+
ref: articleRef,
|
|
58
|
+
onClick: handelArticleClick
|
|
53
59
|
}, children), React.Children.count(children) > 1 && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
|
|
54
60
|
className: "article",
|
|
55
|
-
ref: articleRef
|
|
61
|
+
ref: articleRef,
|
|
62
|
+
onClick: handelArticleClick
|
|
56
63
|
}, children[0]), _toConsumableArray(children.slice(1))));
|
|
57
64
|
}
|
package/package.json
CHANGED