@seafile/sdoc-editor 0.1.131 → 0.1.133
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/extension/commons/element-popover/index.js +13 -0
- package/dist/basic-sdk/extension/plugins/code-block/helpers.js +4 -1
- package/dist/basic-sdk/extension/plugins/font/menu/font-size/index.js +1 -33
- package/dist/basic-sdk/extension/plugins/table/helpers.js +2 -1
- package/dist/basic-sdk/extension/plugins/text-style/menu/index.js +46 -1
- package/dist/basic-sdk/extension/toolbar/side-toolbar/helpers.js +2 -1
- package/dist/basic-sdk/extension/toolbar/side-toolbar/index.js +2 -2
- package/dist/basic-sdk/extension/toolbar/side-toolbar/side-menu.js +20 -5
- package/package.json +1 -1
|
@@ -28,6 +28,19 @@ var ElementPopover = /*#__PURE__*/function (_React$Component) {
|
|
|
28
28
|
value: function componentDidMount() {
|
|
29
29
|
document.body.appendChild(this.el);
|
|
30
30
|
}
|
|
31
|
+
}, {
|
|
32
|
+
key: "componentDidUpdate",
|
|
33
|
+
value: function componentDidUpdate() {
|
|
34
|
+
var _this$props = this.props,
|
|
35
|
+
className = _this$props.className,
|
|
36
|
+
style = _this$props.style;
|
|
37
|
+
if (className) {
|
|
38
|
+
this.el.className = className;
|
|
39
|
+
}
|
|
40
|
+
if (style) {
|
|
41
|
+
this.el.style = style;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
31
44
|
}, {
|
|
32
45
|
key: "componentWillUnmount",
|
|
33
46
|
value: function componentWillUnmount() {
|
|
@@ -78,8 +78,11 @@ export var changeToCodeBlock = function changeToCodeBlock(editor, language) {
|
|
|
78
78
|
}]
|
|
79
79
|
};
|
|
80
80
|
|
|
81
|
+
var path = Editor.path(editor, editor.selection);
|
|
82
|
+
var atPath = path ? [path[0]] : editor.selection;
|
|
81
83
|
Transforms.insertNodes(editor, newCodeBlockNode, {
|
|
82
|
-
mode: 'highest'
|
|
84
|
+
mode: 'highest',
|
|
85
|
+
at: atPath
|
|
83
86
|
});
|
|
84
87
|
};
|
|
85
88
|
export var changeToPlainText = function changeToPlainText(editor) {
|
|
@@ -6,8 +6,6 @@ import classnames from 'classnames';
|
|
|
6
6
|
import { isMenuDisabled, getFontSize, setFontSize } from '../../helpers';
|
|
7
7
|
import { DEFAULT_COMMON_FONT_SIZE, FONT_SIZE, SPECIAL_FONT_SIZE_NAME } from '../../../../constants';
|
|
8
8
|
import context from '../../../../../../context';
|
|
9
|
-
import { eventStopPropagation } from '../../../../../utils/mouse-event';
|
|
10
|
-
import FontSizeScale from './font-size-scale';
|
|
11
9
|
import Tooltip from '../../../../commons/tooltip';
|
|
12
10
|
import './index.css';
|
|
13
11
|
var FontSize = function FontSize(_ref) {
|
|
@@ -25,7 +23,6 @@ var FontSize = function FontSize(_ref) {
|
|
|
25
23
|
var disabled = isMenuDisabled(editor, readonly);
|
|
26
24
|
var fontSizeButtonId = 'sdoc-button-font-size';
|
|
27
25
|
var selectedFontSize = getFontSize(editor);
|
|
28
|
-
var selectedFontSizeValue = selectedFontSize;
|
|
29
26
|
var lang = (context.getSetting('lang') || '').toLowerCase();
|
|
30
27
|
if (SPECIAL_FONT_SIZE_NAME.includes(selectedFontSize)) {
|
|
31
28
|
var fontItem = FONT_SIZE.find(function (item) {
|
|
@@ -34,7 +31,6 @@ var FontSize = function FontSize(_ref) {
|
|
|
34
31
|
if (lang !== 'zh-cn') {
|
|
35
32
|
selectedFontSize = fontItem ? fontItem.value : DEFAULT_COMMON_FONT_SIZE;
|
|
36
33
|
}
|
|
37
|
-
selectedFontSizeValue = fontItem ? fontItem.value : DEFAULT_COMMON_FONT_SIZE;
|
|
38
34
|
}
|
|
39
35
|
var fontSizeRef = useRef(null);
|
|
40
36
|
var toggle = useCallback(function (event) {
|
|
@@ -50,20 +46,6 @@ var FontSize = function FontSize(_ref) {
|
|
|
50
46
|
|
|
51
47
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
52
48
|
}, [editor, selectedFontSize, isShowMenu]);
|
|
53
|
-
var increaseFontSize = useCallback(function (event) {
|
|
54
|
-
eventStopPropagation(event);
|
|
55
|
-
setFontSize(editor, selectedFontSizeValue + 1);
|
|
56
|
-
|
|
57
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
58
|
-
}, [editor, selectedFontSize, selectedFontSizeValue]);
|
|
59
|
-
var reduceFontSize = useCallback(function (event) {
|
|
60
|
-
eventStopPropagation(event);
|
|
61
|
-
var nextFontSize = selectedFontSizeValue - 1;
|
|
62
|
-
if (nextFontSize < 1) return;
|
|
63
|
-
setFontSize(editor, nextFontSize);
|
|
64
|
-
|
|
65
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
66
|
-
}, [editor, selectedFontSize, selectedFontSizeValue]);
|
|
67
49
|
var validClassName = classnames(className, 'sdoc-menu-with-dropdown sdoc-font-size-menu', {
|
|
68
50
|
'menu-show': isShowMenu,
|
|
69
51
|
'disabled': disabled,
|
|
@@ -96,21 +78,7 @@ var FontSize = function FontSize(_ref) {
|
|
|
96
78
|
className: caretIconClass
|
|
97
79
|
}))), /*#__PURE__*/React.createElement(Tooltip, {
|
|
98
80
|
target: fontSizeButtonId
|
|
99
|
-
}, t('Font_size')), /*#__PURE__*/React.createElement(
|
|
100
|
-
disabled: disabled,
|
|
101
|
-
onClick: increaseFontSize,
|
|
102
|
-
id: "sdoc-increase-font-size",
|
|
103
|
-
tipMessage: t('Increase_font_size')
|
|
104
|
-
}, /*#__PURE__*/React.createElement("i", {
|
|
105
|
-
className: "sdocfont sdoc-increase-font-size"
|
|
106
|
-
})), /*#__PURE__*/React.createElement(FontSizeScale, {
|
|
107
|
-
disabled: disabled,
|
|
108
|
-
onClick: reduceFontSize,
|
|
109
|
-
id: "sdoc-reduce-font-size",
|
|
110
|
-
tipMessage: t('Reduce_font_size')
|
|
111
|
-
}, /*#__PURE__*/React.createElement("i", {
|
|
112
|
-
className: "sdocfont sdoc-reduce-font-size"
|
|
113
|
-
})), !disabled && /*#__PURE__*/React.createElement(UncontrolledPopover, {
|
|
81
|
+
}, t('Font_size')), !disabled && /*#__PURE__*/React.createElement(UncontrolledPopover, {
|
|
114
82
|
target: fontSizeButtonId,
|
|
115
83
|
className: "sdoc-menu-popover sdoc-dropdown-menu sdoc-font-size-menu-popover",
|
|
116
84
|
trigger: "legacy",
|
|
@@ -96,8 +96,9 @@ export var insertTable = function insertTable(editor, size, selection) {
|
|
|
96
96
|
if (!size) return;
|
|
97
97
|
if (isTableMenuDisabled(editor)) return;
|
|
98
98
|
var tableNode = generateEmptyTable(editor, size);
|
|
99
|
+
var path = Editor.path(editor, selection);
|
|
99
100
|
Transforms.insertNodes(editor, tableNode, {
|
|
100
|
-
at:
|
|
101
|
+
at: [path[0]]
|
|
101
102
|
});
|
|
102
103
|
};
|
|
103
104
|
export var getSelectedInfo = function getSelectedInfo(editor) {
|
|
@@ -5,8 +5,13 @@ import { Editor } from '@seafile/slate';
|
|
|
5
5
|
import { TEXT_STYLE, TEXT_STYLE_MORE, MENUS_CONFIG_MAP, ELEMENT_TYPE } from '../../../constants';
|
|
6
6
|
import { focusEditor } from '../../../core';
|
|
7
7
|
import { MenuItem, ColorMenu, MoreDropdown } from '../../../commons';
|
|
8
|
+
import { getFontSize, setFontSize } from '../../font/helpers';
|
|
9
|
+
import context from '../../../../../context';
|
|
10
|
+
import FontSizeScale from '../../font/menu/font-size/font-size-scale';
|
|
8
11
|
import { getValue, isMenuDisabled, addMark, removeMark } from '../helpers';
|
|
9
12
|
import { useColorContext } from '../../../../hooks/use-color-context';
|
|
13
|
+
import { eventStopPropagation } from '../../../../utils/mouse-event';
|
|
14
|
+
import { DEFAULT_COMMON_FONT_SIZE, FONT_SIZE, SPECIAL_FONT_SIZE_NAME } from '../../../constants';
|
|
10
15
|
var TextStyleMenuList = function TextStyleMenuList(_ref) {
|
|
11
16
|
var editor = _ref.editor,
|
|
12
17
|
t = _ref.t,
|
|
@@ -14,6 +19,18 @@ var TextStyleMenuList = function TextStyleMenuList(_ref) {
|
|
|
14
19
|
className = _ref.className,
|
|
15
20
|
idPrefix = _ref.idPrefix,
|
|
16
21
|
readonly = _ref.readonly;
|
|
22
|
+
var selectedFontSize = getFontSize(editor);
|
|
23
|
+
var selectedFontSizeValue = selectedFontSize;
|
|
24
|
+
var lang = (context.getSetting('lang') || '').toLowerCase();
|
|
25
|
+
if (SPECIAL_FONT_SIZE_NAME.includes(selectedFontSize)) {
|
|
26
|
+
var fontItem = FONT_SIZE.find(function (item) {
|
|
27
|
+
return item.name === selectedFontSize;
|
|
28
|
+
});
|
|
29
|
+
if (lang !== 'zh-cn') {
|
|
30
|
+
selectedFontSize = fontItem ? fontItem.value : DEFAULT_COMMON_FONT_SIZE;
|
|
31
|
+
}
|
|
32
|
+
selectedFontSizeValue = fontItem ? fontItem.value : DEFAULT_COMMON_FONT_SIZE;
|
|
33
|
+
}
|
|
17
34
|
var _useColorContext = useColorContext(),
|
|
18
35
|
lastUsedFontColor = _useColorContext.lastUsedFontColor,
|
|
19
36
|
updateLastUsedFontColor = _useColorContext.updateLastUsedFontColor,
|
|
@@ -50,6 +67,20 @@ var TextStyleMenuList = function TextStyleMenuList(_ref) {
|
|
|
50
67
|
|
|
51
68
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
52
69
|
}, [editor]);
|
|
70
|
+
var increaseFontSize = useCallback(function (event) {
|
|
71
|
+
eventStopPropagation(event);
|
|
72
|
+
setFontSize(editor, selectedFontSizeValue + 1);
|
|
73
|
+
|
|
74
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
75
|
+
}, [editor, selectedFontSize, selectedFontSizeValue]);
|
|
76
|
+
var reduceFontSize = useCallback(function (event) {
|
|
77
|
+
eventStopPropagation(event);
|
|
78
|
+
var nextFontSize = selectedFontSizeValue - 1;
|
|
79
|
+
if (nextFontSize < 1) return;
|
|
80
|
+
setFontSize(editor, nextFontSize);
|
|
81
|
+
|
|
82
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
83
|
+
}, [editor, selectedFontSize, selectedFontSizeValue]);
|
|
53
84
|
var getTextStyleList = useCallback(function (key) {
|
|
54
85
|
return MENUS_CONFIG_MAP[key].map(function (item) {
|
|
55
86
|
var itemProps = {
|
|
@@ -85,6 +116,20 @@ var TextStyleMenuList = function TextStyleMenuList(_ref) {
|
|
|
85
116
|
return /*#__PURE__*/React.createElement(MenuItem, Object.assign({
|
|
86
117
|
key: index
|
|
87
118
|
}, itemProps));
|
|
88
|
-
})
|
|
119
|
+
}), /*#__PURE__*/React.createElement(FontSizeScale, {
|
|
120
|
+
disabled: isDisabled(),
|
|
121
|
+
onClick: increaseFontSize,
|
|
122
|
+
id: "sdoc-increase-font-size",
|
|
123
|
+
tipMessage: t('Increase_font_size')
|
|
124
|
+
}, /*#__PURE__*/React.createElement("i", {
|
|
125
|
+
className: "sdocfont sdoc-increase-font-size"
|
|
126
|
+
})), /*#__PURE__*/React.createElement(FontSizeScale, {
|
|
127
|
+
disabled: isDisabled(),
|
|
128
|
+
onClick: reduceFontSize,
|
|
129
|
+
id: "sdoc-reduce-font-size",
|
|
130
|
+
tipMessage: t('Reduce_font_size')
|
|
131
|
+
}, /*#__PURE__*/React.createElement("i", {
|
|
132
|
+
className: "sdocfont sdoc-reduce-font-size"
|
|
133
|
+
}))));
|
|
89
134
|
};
|
|
90
135
|
export default withTranslation('sdoc-editor')(TextStyleMenuList);
|
|
@@ -117,5 +117,6 @@ export var insertBelowLink = function insertBelowLink(editor, title, url) {
|
|
|
117
117
|
export var getDomTopHeight = function getDomTopHeight(dom) {
|
|
118
118
|
var HEADER_HEIGHT = 56 + 44;
|
|
119
119
|
var rect = dom.getBoundingClientRect();
|
|
120
|
-
|
|
120
|
+
var HightCenter = (rect.height - 24) / 2;
|
|
121
|
+
return rect.y - HEADER_HEIGHT + HightCenter;
|
|
121
122
|
};
|
|
@@ -98,9 +98,9 @@ var SideToolbar = function SideToolbar() {
|
|
|
98
98
|
});
|
|
99
99
|
}, [editor, isShowSideMenu, slateNode]);
|
|
100
100
|
var iconClass = classnames('sdocfont', {
|
|
101
|
-
'sdoc-more-vertical': !isActive,
|
|
101
|
+
'sdoc-more-vertical': !isActive && !isNodeEmpty,
|
|
102
102
|
'sdoc-more-vertical-right': isActive && !isNodeEmpty,
|
|
103
|
-
'sdoc-append':
|
|
103
|
+
'sdoc-append': isNodeEmpty
|
|
104
104
|
});
|
|
105
105
|
return /*#__PURE__*/React.createElement("div", {
|
|
106
106
|
className: "sdoc-side-toolbar-container",
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
2
|
+
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
2
3
|
import { withTranslation } from 'react-i18next';
|
|
3
4
|
import { useSlateStatic } from '@seafile/slate-react';
|
|
4
5
|
import EventBus from '../../../utils/event-bus';
|
|
@@ -15,6 +16,11 @@ var SideMenu = function SideMenu(_ref) {
|
|
|
15
16
|
menuPosition = _ref.menuPosition,
|
|
16
17
|
onReset = _ref.onReset,
|
|
17
18
|
t = _ref.t;
|
|
19
|
+
var sideMenuRef = useRef(null);
|
|
20
|
+
var _useState = useState(''),
|
|
21
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
22
|
+
menuStyle = _useState2[0],
|
|
23
|
+
setMenuStyle = _useState2[1];
|
|
18
24
|
var editor = useSlateStatic();
|
|
19
25
|
useEffect(function () {
|
|
20
26
|
var eventBus = EventBus.getInstance();
|
|
@@ -35,14 +41,23 @@ var SideMenu = function SideMenu(_ref) {
|
|
|
35
41
|
onDeleteNode(editor, slateNode);
|
|
36
42
|
onReset();
|
|
37
43
|
}, [editor, onReset, slateNode]);
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
44
|
+
useEffect(function () {
|
|
45
|
+
var top = menuPosition.top;
|
|
46
|
+
if (sideMenuRef.current) {
|
|
47
|
+
var overflowY = menuPosition.top + sideMenuRef.current.offsetHeight - document.body.clientHeight;
|
|
48
|
+
if (overflowY > 0) {
|
|
49
|
+
top = menuPosition.top - overflowY - 10;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
setMenuStyle("top: ".concat(top, "px; left: ").concat(menuPosition.left, "px"));
|
|
53
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
54
|
+
}, [menuPosition, sideMenuRef.current]);
|
|
41
55
|
return /*#__PURE__*/React.createElement(ElementPopover, {
|
|
42
56
|
className: "sdoc-side-menu-popover",
|
|
43
57
|
style: menuStyle
|
|
44
58
|
}, /*#__PURE__*/React.createElement("div", {
|
|
45
|
-
className: "sdoc-side-menu"
|
|
59
|
+
className: "sdoc-side-menu",
|
|
60
|
+
ref: sideMenuRef
|
|
46
61
|
}, /*#__PURE__*/React.createElement(SideMenuItem, {
|
|
47
62
|
menuId: "sdoc-side-menu-item__transform",
|
|
48
63
|
iconClass: "sdocfont sdoc-table-of-content",
|