@seafile/sdoc-editor 0.4.2 → 0.4.3
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.
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import React, { useCallback, useMemo, Fragment } from 'react';
|
|
2
2
|
import { Editable, ReactEditor, Slate } from '@seafile/slate-react';
|
|
3
|
+
import { Editor } from '@seafile/slate';
|
|
3
4
|
import { renderLeaf, renderElement, ContextToolbar, SideToolbar } from '../extension';
|
|
4
5
|
import { getAboveBlockNode, getNextNode, getPrevNode, isSelectionAtBlockEnd, isSelectionAtBlockStart } from '../extension/core';
|
|
5
6
|
import EventProxy from '../utils/event-handler';
|
|
@@ -12,6 +13,7 @@ import EventBus from '../utils/event-bus';
|
|
|
12
13
|
import { ArticleContainer } from '../layout';
|
|
13
14
|
import { useScrollContext } from '../hooks/use-scroll-context';
|
|
14
15
|
import { SetNodeToDecorations } from '../highlight';
|
|
16
|
+
import { IMAGE } from '../extension/constants';
|
|
15
17
|
const EditableArticle = _ref => {
|
|
16
18
|
let {
|
|
17
19
|
isShowComment,
|
|
@@ -132,6 +134,24 @@ const EditableArticle = _ref => {
|
|
|
132
134
|
|
|
133
135
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
134
136
|
}, [scrollRef]);
|
|
137
|
+
const handleScrollIntoView = useCallback((editor, domRange) => {
|
|
138
|
+
try {
|
|
139
|
+
const {
|
|
140
|
+
selection
|
|
141
|
+
} = editor;
|
|
142
|
+
const [imageNodeEntry] = Editor.nodes(editor, {
|
|
143
|
+
match: n => n.type === IMAGE
|
|
144
|
+
});
|
|
145
|
+
if (imageNodeEntry) return;
|
|
146
|
+
const domNode = ReactEditor.toDOMNode(editor, selection.focus.path);
|
|
147
|
+
if (!domNode) return;
|
|
148
|
+
domNode.scrollIntoView({
|
|
149
|
+
block: 'nearest'
|
|
150
|
+
});
|
|
151
|
+
} catch (error) {
|
|
152
|
+
//
|
|
153
|
+
}
|
|
154
|
+
}, []);
|
|
135
155
|
return /*#__PURE__*/React.createElement(Slate, {
|
|
136
156
|
editor: editor,
|
|
137
157
|
value: slateValue,
|
|
@@ -139,6 +159,7 @@ const EditableArticle = _ref => {
|
|
|
139
159
|
}, /*#__PURE__*/React.createElement(ArticleContainer, {
|
|
140
160
|
editor: editor
|
|
141
161
|
}, /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement(ContextToolbar, null), /*#__PURE__*/React.createElement(SetNodeToDecorations, null), /*#__PURE__*/React.createElement(Editable, {
|
|
162
|
+
scrollSelectionIntoView: handleScrollIntoView,
|
|
142
163
|
cursors: cursors,
|
|
143
164
|
renderElement: renderElement,
|
|
144
165
|
renderLeaf: renderLeaf,
|
|
@@ -33,7 +33,8 @@ export const changeToCodeBlock = function (editor) {
|
|
|
33
33
|
let language = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
|
|
34
34
|
let position = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : INSERT_POSITION.CURRENT;
|
|
35
35
|
// Summarizes the strings for the selected highest-level node
|
|
36
|
-
let strArr = []
|
|
36
|
+
let strArr = [],
|
|
37
|
+
path = Editor.path(editor, editor.selection);
|
|
37
38
|
if (position === INSERT_POSITION.AFTER) {
|
|
38
39
|
strArr = [''];
|
|
39
40
|
} else {
|
|
@@ -72,7 +73,6 @@ export const changeToCodeBlock = function (editor) {
|
|
|
72
73
|
}]
|
|
73
74
|
}]
|
|
74
75
|
};
|
|
75
|
-
const path = Editor.path(editor, editor.selection);
|
|
76
76
|
if (position === INSERT_POSITION.AFTER) {
|
|
77
77
|
Transforms.insertNodes(editor, newCodeBlockNode, {
|
|
78
78
|
mode: 'highest',
|
|
@@ -19,7 +19,9 @@ const DocInfo = _ref => {
|
|
|
19
19
|
} = _ref;
|
|
20
20
|
const onInternalLinkClick = useCallback(() => {
|
|
21
21
|
const eventBus = EventBus.getInstance();
|
|
22
|
-
eventBus.dispatch(EXTERNAL_EVENT.INTERNAL_LINK_CLICK
|
|
22
|
+
eventBus.dispatch(EXTERNAL_EVENT.INTERNAL_LINK_CLICK, {
|
|
23
|
+
internalLink: window.location.href
|
|
24
|
+
});
|
|
23
25
|
}, []);
|
|
24
26
|
const toggleStar = useCallback(() => {
|
|
25
27
|
const eventBus = EventBus.getInstance();
|
|
@@ -80,7 +82,13 @@ const DocInfo = _ref => {
|
|
|
80
82
|
className: "doc-name"
|
|
81
83
|
}, oldDocName), /*#__PURE__*/React.createElement("div", {
|
|
82
84
|
className: "sdoc-revision-order"
|
|
83
|
-
}, t('Revision') + ' ' + revisionId),
|
|
85
|
+
}, t('Revision') + ' ' + revisionId), isShowInternalLink && /*#__PURE__*/React.createElement("span", {
|
|
86
|
+
className: "doc-icon"
|
|
87
|
+
}, /*#__PURE__*/React.createElement("span", {
|
|
88
|
+
className: "internal-link sdocfont sdoc-link",
|
|
89
|
+
title: t('Internal_link'),
|
|
90
|
+
onClick: onInternalLinkClick
|
|
91
|
+
})), isPublished && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
|
|
84
92
|
className: "sdoc-revision-published-tip"
|
|
85
93
|
}, t('Published')), /*#__PURE__*/React.createElement("div", {
|
|
86
94
|
className: "sdoc-revision-source-doc",
|