@seafile/sdoc-editor 0.2.3 → 0.2.5
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/sdoc-editor-plugins.css +9 -0
- 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/check-list/render-elem.js +3 -4
- package/dist/basic-sdk/extension/plugins/image/helpers.js +19 -1
- package/dist/basic-sdk/extension/plugins/image/hover-menu/index.css +0 -18
- package/dist/basic-sdk/extension/plugins/image/hover-menu/index.js +23 -7
- package/dist/basic-sdk/extension/plugins/image/plugin.js +11 -3
- package/dist/basic-sdk/extension/plugins/image/render-elem.js +13 -11
- package/dist/basic-sdk/layout/article-container.js +9 -2
- package/package.json +1 -1
|
@@ -27,6 +27,15 @@
|
|
|
27
27
|
padding-inline-start: 24px;
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
+
/* check list */
|
|
31
|
+
.sdoc-editor-container .article .sdoc-checkbox-container .sdoc-checkbox-input-wrapper {
|
|
32
|
+
margin-right: 6px;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
.sdoc-editor-container .article .sdoc-checkbox-container .sdoc-checkbox-input-wrapper :first-child {
|
|
36
|
+
vertical-align: middle;
|
|
37
|
+
}
|
|
38
|
+
|
|
30
39
|
/* image */
|
|
31
40
|
.sdoc-editor-container .article .sdoc-image-wrapper {
|
|
32
41
|
position: relative;
|
|
@@ -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);
|
|
@@ -45,15 +45,14 @@ var CheckListItem = /*#__PURE__*/function (_React$PureComponent) {
|
|
|
45
45
|
textAlign: align
|
|
46
46
|
};
|
|
47
47
|
return /*#__PURE__*/React.createElement("div", Object.assign({
|
|
48
|
+
className: "sdoc-checkbox-container",
|
|
48
49
|
"data-id": id,
|
|
49
50
|
"data-root": "true"
|
|
50
51
|
}, attributes, {
|
|
51
52
|
style: style
|
|
52
53
|
}), /*#__PURE__*/React.createElement("span", {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
marginRight: 6
|
|
56
|
-
}
|
|
54
|
+
className: "sdoc-checkbox-input-wrapper",
|
|
55
|
+
contentEditable: false
|
|
57
56
|
}, /*#__PURE__*/React.createElement("input", {
|
|
58
57
|
type: "checkbox",
|
|
59
58
|
onChange: this.onChange,
|
|
@@ -3,7 +3,7 @@ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
|
3
3
|
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
4
4
|
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == typeof h && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(typeof e + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
|
|
5
5
|
import urlJoin from 'url-join';
|
|
6
|
-
import { Editor, Range, Transforms, Path } from '@seafile/slate';
|
|
6
|
+
import { Editor, Range, Transforms, Path, Node } from '@seafile/slate';
|
|
7
7
|
import { ReactEditor } from '@seafile/slate-react';
|
|
8
8
|
import context from '../../../../context';
|
|
9
9
|
import EventBus from '../../../utils/event-bus';
|
|
@@ -145,4 +145,22 @@ export var queryCopyMoveProgressView = function queryCopyMoveProgressView(taskId
|
|
|
145
145
|
};
|
|
146
146
|
}();
|
|
147
147
|
start();
|
|
148
|
+
};
|
|
149
|
+
export var resetCursor = function resetCursor(editor) {
|
|
150
|
+
var selection = editor.selection;
|
|
151
|
+
var currentPath = selection.focus.path;
|
|
152
|
+
var targetPath = Path.next(Path.next(currentPath));
|
|
153
|
+
|
|
154
|
+
// Set cursor after image insertion
|
|
155
|
+
queueMicrotask(function () {
|
|
156
|
+
Transforms.select(editor, targetPath);
|
|
157
|
+
});
|
|
158
|
+
};
|
|
159
|
+
export var isSingleImage = function isSingleImage(data) {
|
|
160
|
+
if (data.length !== 1) return false;
|
|
161
|
+
if (Node.string(data[0]).length !== 0) return false;
|
|
162
|
+
if (data[0].children.filter(function (item) {
|
|
163
|
+
return (item === null || item === void 0 ? void 0 : item.type) === IMAGE;
|
|
164
|
+
}).length !== 1) return false;
|
|
165
|
+
return true;
|
|
148
166
|
};
|
|
@@ -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: 100px;
|
|
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';
|
|
@@ -35,6 +36,13 @@ var ImageHoverMenu = function ImageHoverMenu(_ref) {
|
|
|
35
36
|
_useState4 = _slicedToArray(_useState3, 2),
|
|
36
37
|
isShowImagePreview = _useState4[0],
|
|
37
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
|
+
}, []);
|
|
38
46
|
var onShowProver = useCallback(function (event, showProverKey) {
|
|
39
47
|
event.stopPropagation();
|
|
40
48
|
var newPopoverState = popoverState;
|
|
@@ -92,9 +100,9 @@ var ImageHoverMenu = function ImageHoverMenu(_ref) {
|
|
|
92
100
|
}), /*#__PURE__*/React.createElement("i", {
|
|
93
101
|
className: "sdocfont sdoc-drop-down icon-font"
|
|
94
102
|
})), /*#__PURE__*/React.createElement("span", {
|
|
103
|
+
id: "sdoc_image_border",
|
|
95
104
|
role: "button",
|
|
96
|
-
|
|
97
|
-
className: classnames('op-item', 'op-tooltip', 'ml-1', {
|
|
105
|
+
className: classnames('op-item', 'ml-1', {
|
|
98
106
|
'active': popoverState.borderPopover
|
|
99
107
|
}),
|
|
100
108
|
onClick: function onClick(e) {
|
|
@@ -104,19 +112,27 @@ var ImageHoverMenu = function ImageHoverMenu(_ref) {
|
|
|
104
112
|
className: "sdocfont sdoc-image icon-font mr-1"
|
|
105
113
|
}), /*#__PURE__*/React.createElement("i", {
|
|
106
114
|
className: "sdocfont sdoc-drop-down icon-font"
|
|
107
|
-
})
|
|
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", {
|
|
108
120
|
className: "op-group-item"
|
|
109
121
|
}, /*#__PURE__*/React.createElement("span", {
|
|
122
|
+
id: "sdoc_image_full_screen_mode",
|
|
110
123
|
role: "button",
|
|
111
|
-
"op-item
|
|
112
|
-
className: "op-item op-tooltip",
|
|
124
|
+
className: "op-item",
|
|
113
125
|
onClick: function onClick(e) {
|
|
114
126
|
e.stopPropagation();
|
|
115
127
|
setIsShowImagePreview(!isShowImagePreview);
|
|
116
128
|
}
|
|
117
129
|
}, /*#__PURE__*/React.createElement("i", {
|
|
118
130
|
className: "sdocfont sdoc-fullscreen icon-font"
|
|
119
|
-
})
|
|
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", {
|
|
120
136
|
className: "sdoc-image-popover sdoc-dropdown-menu"
|
|
121
137
|
}, IMAGE_DISPLAY_TYPE.map(function (item) {
|
|
122
138
|
return /*#__PURE__*/React.createElement("div", {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
2
|
-
import { Transforms, Path, Editor, Element } from '@seafile/slate';
|
|
2
|
+
import { Transforms, Path, Editor, Element, Node } from '@seafile/slate';
|
|
3
3
|
import toaster from '../../../../components/toast';
|
|
4
4
|
import context from '../../../../context';
|
|
5
|
-
import { insertImage, hasSdocImages, getImageData, queryCopyMoveProgressView } from './helpers';
|
|
5
|
+
import { insertImage, hasSdocImages, getImageData, queryCopyMoveProgressView, resetCursor, isSingleImage } from './helpers';
|
|
6
6
|
import { focusEditor } from '../../core';
|
|
7
7
|
import { getErrorMsg } from '../../../../utils';
|
|
8
8
|
import { getSlateFragmentAttribute } from '../../../utils/document-utils';
|
|
@@ -11,7 +11,8 @@ var withImage = function withImage(editor) {
|
|
|
11
11
|
var isInline = editor.isInline,
|
|
12
12
|
isVoid = editor.isVoid,
|
|
13
13
|
insertData = editor.insertData,
|
|
14
|
-
deleteBackward = editor.deleteBackward
|
|
14
|
+
deleteBackward = editor.deleteBackward,
|
|
15
|
+
insertFragment = editor.insertFragment;
|
|
15
16
|
var newEditor = editor;
|
|
16
17
|
|
|
17
18
|
// rewrite isInline
|
|
@@ -52,11 +53,18 @@ var withImage = function withImage(editor) {
|
|
|
52
53
|
if (data.types && data.types.includes('Files') && data.files[0].type.includes(IMAGE)) {
|
|
53
54
|
context.uploadLocalImage(data.files[0]).then(function (fileUrl) {
|
|
54
55
|
insertImage(newEditor, fileUrl, editor.selection, INSERT_POSITION.CURRENT);
|
|
56
|
+
resetCursor(newEditor);
|
|
55
57
|
});
|
|
56
58
|
return;
|
|
57
59
|
}
|
|
58
60
|
insertData(data);
|
|
59
61
|
};
|
|
62
|
+
newEditor.insertFragment = function (data) {
|
|
63
|
+
if (isSingleImage(data)) {
|
|
64
|
+
resetCursor(newEditor);
|
|
65
|
+
}
|
|
66
|
+
return insertFragment(data);
|
|
67
|
+
};
|
|
60
68
|
newEditor.imageOnKeyDown = function (e) {
|
|
61
69
|
if (e.keyCode === 13) {
|
|
62
70
|
var selection = newEditor.selection;
|
|
@@ -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,18 +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) {
|
|
122
|
+
var _imagePreviewer$;
|
|
121
123
|
var imagePreviewer = document.getElementsByClassName('sf-editor-image-previewer');
|
|
122
|
-
if (e.target === imageRef.current || imagePreviewer[0]
|
|
124
|
+
if (e.target === imageRef.current || ((_imagePreviewer$ = imagePreviewer[0]) === null || _imagePreviewer$ === void 0 ? void 0 : _imagePreviewer$.contains(e.target))) return;
|
|
123
125
|
setIsShowImageHoverMenu(false);
|
|
124
126
|
}, []);
|
|
125
127
|
useEffect(function () {
|
|
@@ -154,9 +156,9 @@ var Image = function Image(_ref) {
|
|
|
154
156
|
var _elem$getBoundingClie = elem.getBoundingClientRect(),
|
|
155
157
|
top = _elem$getBoundingClie.top,
|
|
156
158
|
left = _elem$getBoundingClie.left,
|
|
157
|
-
|
|
159
|
+
width = _elem$getBoundingClie.width;
|
|
158
160
|
var menuTop = top - 42;
|
|
159
|
-
var menuLeft = left - 222 / 2 +
|
|
161
|
+
var menuLeft = left - 222 / 2 + width / 2; // left = left distance - (menu width / 2) + (image with / 2)
|
|
160
162
|
setMenuPosition({
|
|
161
163
|
top: menuTop,
|
|
162
164
|
left: menuLeft
|
|
@@ -215,7 +217,7 @@ var Image = function Image(_ref) {
|
|
|
215
217
|
}), isResizing && /*#__PURE__*/React.createElement("span", {
|
|
216
218
|
className: "image-size",
|
|
217
219
|
contentEditable: false
|
|
218
|
-
}, /*#__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, {
|
|
219
221
|
editor: editor,
|
|
220
222
|
menuPosition: menuPosition,
|
|
221
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
|
}
|