@seafile/sdoc-editor 1.0.40 → 1.0.41
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.
|
@@ -10,7 +10,7 @@ import { ORDERED_LIST, UNORDERED_LIST, PARAGRAPH, CHECK_LIST_ITEM, IMAGE, TABLE,
|
|
|
10
10
|
import { EMPTY_SELECTED_RANGE } from '../../plugins/table/constants';
|
|
11
11
|
import { unwrapCallout, wrapCallout } from '../../plugins/callout/helper';
|
|
12
12
|
import { convertToCheck } from '../../plugins/check-list/helpers';
|
|
13
|
-
import {
|
|
13
|
+
import { WIKI_EDITOR } from '../../../constants';
|
|
14
14
|
export const onSetNodeType = (editor, element, type) => {
|
|
15
15
|
if (!type) return;
|
|
16
16
|
if (type === CALL_OUT) {
|
|
@@ -92,18 +92,29 @@ export const onDeleteNode = (editor, element) => {
|
|
|
92
92
|
at: path
|
|
93
93
|
});
|
|
94
94
|
};
|
|
95
|
-
export const
|
|
96
|
-
|
|
95
|
+
export const getTopValue = (editor, dom, containerDom, slateNode) => {
|
|
96
|
+
if (!dom) return 0;
|
|
97
|
+
if (!containerDom) return 0;
|
|
98
|
+
const currentRect = dom.getBoundingClientRect();
|
|
99
|
+
let containerRect = containerDom.getBoundingClientRect();
|
|
100
|
+
let headerHeight = 0;
|
|
101
|
+
if (editor.editorType === WIKI_EDITOR) {
|
|
102
|
+
const titleDom = document.getElementById('wiki-page-title');
|
|
103
|
+
const coverDom = document.getElementById('wiki-page-cover');
|
|
104
|
+
const titleHeight = (titleDom === null || titleDom === void 0 ? void 0 : titleDom.getBoundingClientRect().height) || 0;
|
|
105
|
+
const coverHeight = (coverDom === null || coverDom === void 0 ? void 0 : coverDom.getBoundingClientRect().height) || 0;
|
|
106
|
+
headerHeight = titleHeight + coverHeight;
|
|
107
|
+
}
|
|
108
|
+
const top = currentRect.y - containerRect.y + containerDom.scrollTop;
|
|
97
109
|
let offsetY = 0;
|
|
98
|
-
|
|
99
|
-
const headerHeight = getHeaderHeight(editor);
|
|
100
|
-
const paddingTop = parseFloat(window.getComputedStyle(dom).getPropertyValue('padding-top'));
|
|
110
|
+
let paddingTop = parseFloat(window.getComputedStyle(dom).getPropertyValue('padding-top'));
|
|
101
111
|
const lineHeight = parseFloat(window.getComputedStyle(dom).getPropertyValue('line-height'));
|
|
102
|
-
const disToolBarHeight =
|
|
112
|
+
const disToolBarHeight = 21; // side toolbar icon line-height is 21
|
|
103
113
|
if (ADD_POSITION_OFFSET_TYPE.includes(slateNode.type)) {
|
|
114
|
+
paddingTop = slateNode.type === CHECK_LIST_ITEM ? 5 : paddingTop;
|
|
104
115
|
offsetY = lineHeight / 2 + paddingTop - disToolBarHeight / 2;
|
|
105
116
|
}
|
|
106
|
-
return
|
|
117
|
+
return top + offsetY - headerHeight;
|
|
107
118
|
};
|
|
108
119
|
export const isVoidNode = node => {
|
|
109
120
|
if (!node) return true;
|
|
@@ -6,7 +6,7 @@ import SideMenu from './side-menu';
|
|
|
6
6
|
import EventBus from '../../../utils/event-bus';
|
|
7
7
|
import { useScrollContext } from '../../../hooks/use-scroll-context';
|
|
8
8
|
import { focusEditor } from '../../core';
|
|
9
|
-
import {
|
|
9
|
+
import { setSelection, isVoidNode, getNodeEntry, isBlockquote, isList, onWrapListItem, getTopValue } from './helpers';
|
|
10
10
|
import { insertImageFiles } from '../../plugins/image/helpers';
|
|
11
11
|
import { INTERNAL_EVENT, WIKI_EDITOR } from '../../../constants';
|
|
12
12
|
import { CODE_BLOCK, TABLE, BLOCKQUOTE, CHECK_LIST_ITEM, CALL_OUT, TABLE_DRAG_KEY } from '../../constants';
|
|
@@ -72,10 +72,9 @@ const SideToolbar = () => {
|
|
|
72
72
|
dom = dom.parentNode;
|
|
73
73
|
}
|
|
74
74
|
const node = ReactEditor.toSlateNode(editor, dom);
|
|
75
|
-
const top = getDomTopHeight(editor, dom, node);
|
|
76
75
|
const isEmpty = isVoidNode(node);
|
|
77
|
-
const
|
|
78
|
-
const topValue =
|
|
76
|
+
const containerDom = scrollRef.current;
|
|
77
|
+
const topValue = getTopValue(editor, dom, containerDom, node);
|
|
79
78
|
if (topValue !== sidePosition.top) setIsMoving(true);
|
|
80
79
|
let left = 20;
|
|
81
80
|
if (editor.editorType === WIKI_EDITOR) {
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { WIKI_EDITOR, DOCUMENT_PLUGIN_EDITOR } from '../constants';
|
|
2
1
|
export const getDomHeight = dom => {
|
|
3
2
|
const styles = window.getComputedStyle(dom);
|
|
4
3
|
const rect = dom.getBoundingClientRect();
|
|
@@ -45,25 +44,4 @@ export const getCursorPosition = function () {
|
|
|
45
44
|
x: x,
|
|
46
45
|
y: y
|
|
47
46
|
};
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Get the height of the header of the editor
|
|
52
|
-
* @param {Editor} editor
|
|
53
|
-
* @returns {Number} height of the header
|
|
54
|
-
*/
|
|
55
|
-
export const getHeaderHeight = editor => {
|
|
56
|
-
const {
|
|
57
|
-
editorType
|
|
58
|
-
} = editor;
|
|
59
|
-
switch (editorType) {
|
|
60
|
-
case WIKI_EDITOR:
|
|
61
|
-
return (editor === null || editor === void 0 ? void 0 : editor.getHeaderHeight()) || 0;
|
|
62
|
-
case DOCUMENT_PLUGIN_EDITOR:
|
|
63
|
-
return 67 + 48 + 49 + 37;
|
|
64
|
-
default:
|
|
65
|
-
// sdoc-editor-page-header height = 56
|
|
66
|
-
// sdoc-editor-toolbar height = 37
|
|
67
|
-
return 56 + 37;
|
|
68
|
-
}
|
|
69
47
|
};
|
|
@@ -14,7 +14,6 @@ const SdocWikiEditor = _ref => {
|
|
|
14
14
|
document,
|
|
15
15
|
docUuid,
|
|
16
16
|
isWikiReadOnly,
|
|
17
|
-
getHeaderHeight,
|
|
18
17
|
scrollRef
|
|
19
18
|
} = _ref;
|
|
20
19
|
context.initApi();
|
|
@@ -37,7 +36,6 @@ const SdocWikiEditor = _ref => {
|
|
|
37
36
|
newEditor.cursors = cursors || {};
|
|
38
37
|
newEditor.width = PAGE_EDIT_AREA_WIDTH; // default width
|
|
39
38
|
newEditor.editorType = WIKI_EDITOR;
|
|
40
|
-
newEditor.getHeaderHeight = getHeaderHeight;
|
|
41
39
|
return newEditor;
|
|
42
40
|
|
|
43
41
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|