@seafile/sdoc-editor 0.1.88 → 0.1.90
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/dropdown-menu.css +6 -0
- package/dist/basic-sdk/assets/css/layout.css +3 -1
- package/dist/basic-sdk/editor.js +2 -2
- package/dist/basic-sdk/extension/{menu → commons}/color-menu/color-item.js +2 -2
- package/dist/basic-sdk/extension/{menu → commons}/color-menu/index.css +47 -19
- package/dist/basic-sdk/extension/{menu → commons}/color-menu/index.js +38 -27
- package/dist/basic-sdk/extension/commons/{modal-portal → element-popover}/index.js +11 -8
- package/dist/basic-sdk/extension/commons/index.js +5 -0
- package/dist/basic-sdk/extension/commons/menu/menu.css +85 -0
- package/dist/basic-sdk/extension/commons/more-dropdown/index.js +38 -0
- package/dist/basic-sdk/extension/constants/index.js +5 -2
- package/dist/basic-sdk/extension/index.js +2 -2
- package/dist/basic-sdk/extension/plugins/blockquote/menu/index.js +1 -1
- package/dist/basic-sdk/extension/plugins/check-list/menu/index.js +1 -1
- package/dist/basic-sdk/extension/plugins/clear-format/menu/index.js +1 -1
- package/dist/basic-sdk/extension/plugins/code-block/hover-menu/index.js +3 -3
- package/dist/basic-sdk/extension/plugins/code-block/menu/index.js +1 -1
- package/dist/basic-sdk/extension/plugins/image/menu/index.js +1 -1
- package/dist/basic-sdk/extension/plugins/link/menu/index.js +1 -1
- package/dist/basic-sdk/extension/plugins/link/render-elem.js +2 -1
- package/dist/basic-sdk/extension/plugins/list/menu/index.js +1 -1
- package/dist/basic-sdk/extension/plugins/table/dialog/custom-table-size-dialog/index.js +1 -1
- package/dist/basic-sdk/extension/plugins/table/helpers.js +1 -2
- package/dist/basic-sdk/extension/plugins/table/menu/active-table-menu/common-menu.js +9 -5
- package/dist/basic-sdk/extension/plugins/table/menu/active-table-menu/index.css +16 -7
- package/dist/basic-sdk/extension/plugins/table/menu/active-table-menu/index.js +7 -6
- package/dist/basic-sdk/extension/plugins/table/menu/table-context-menu/index.js +3 -3
- package/dist/basic-sdk/extension/plugins/table/menu/table-menu/index.js +1 -1
- package/dist/basic-sdk/extension/plugins/table/plugin.js +1 -2
- package/dist/basic-sdk/extension/plugins/table/render/render-cell.js +2 -2
- package/dist/basic-sdk/extension/plugins/text-align/menu/index.js +81 -110
- package/dist/basic-sdk/extension/plugins/text-style/menu/index.js +6 -5
- package/dist/basic-sdk/extension/toolbar/context-toolbar/index.css +10 -0
- package/dist/basic-sdk/extension/toolbar/context-toolbar/index.js +56 -0
- package/dist/basic-sdk/extension/toolbar/header-toolbar/index.js +54 -0
- package/dist/basic-sdk/extension/toolbar/{redo-undo.js → header-toolbar/redo-undo.js} +2 -2
- package/dist/basic-sdk/extension/toolbar/index.js +3 -54
- package/dist/basic-sdk/hooks/use-selection-position.js +11 -3
- package/dist/basic-sdk/node-id/index.js +1 -1
- package/dist/layout/layout.css +3 -0
- package/dist/utils/local-storage-utils.js +16 -2
- package/package.json +1 -1
- package/dist/basic-sdk/constants/index.js +0 -1
- package/dist/basic-sdk/extension/menu/menu.css +0 -34
- package/dist/basic-sdk/extension/plugins/text-align/menu/style.css +0 -53
- package/dist/components/more-dropdown/index.js +0 -75
- package/dist/components/more-dropdown/style.css +0 -64
- /package/dist/basic-sdk/extension/{menu → commons/menu}/index.js +0 -0
- /package/dist/basic-sdk/extension/{menu → commons/menu}/menu-group.js +0 -0
- /package/dist/basic-sdk/extension/{menu → commons/menu}/menu-item.js +0 -0
- /package/dist/basic-sdk/extension/plugins/table/{number-input.js → dialog/custom-table-size-dialog/number-input.js} +0 -0
|
@@ -6,7 +6,7 @@ import _createSuper from "@babel/runtime/helpers/esm/createSuper";
|
|
|
6
6
|
import React from 'react';
|
|
7
7
|
import { MENUS_CONFIG_MAP, ORDERED_LIST, UNORDERED_LIST } from '../../../constants';
|
|
8
8
|
import { focusEditor } from '../../../core';
|
|
9
|
-
import { MenuItem } from '../../../
|
|
9
|
+
import { MenuItem } from '../../../commons';
|
|
10
10
|
import { getListType, isMenuDisabled, setListType } from '../helpers';
|
|
11
11
|
var ListMenu = /*#__PURE__*/function (_React$Component) {
|
|
12
12
|
_inherits(ListMenu, _React$Component);
|
|
@@ -5,8 +5,8 @@ import _createSuper from "@babel/runtime/helpers/esm/createSuper";
|
|
|
5
5
|
import React, { Component } from 'react';
|
|
6
6
|
import { withTranslation } from 'react-i18next';
|
|
7
7
|
import { Modal, ModalHeader, ModalBody, ModalFooter, Button, Label } from 'reactstrap';
|
|
8
|
-
import NumberInput from '../../number-input';
|
|
9
8
|
import { TABLE_MAX_ROWS, TABLE_MAX_COLUMNS } from '../../constants';
|
|
9
|
+
import NumberInput from './number-input';
|
|
10
10
|
import './index.css';
|
|
11
11
|
var CustomTableSizeDialog = /*#__PURE__*/function (_Component) {
|
|
12
12
|
_inherits(CustomTableSizeDialog, _Component);
|
|
@@ -6,13 +6,12 @@ import slugid from 'slugid';
|
|
|
6
6
|
import { Editor, Range, Transforms, Point, Node } from '@seafile/slate';
|
|
7
7
|
import { ReactEditor } from '@seafile/slate-react';
|
|
8
8
|
import { getNodeType, getParentNode, getSelectedNodeByType, isTextNode, getSelectedElems, focusEditor, getNode, findPath, replaceNodeChildren } from '../../core';
|
|
9
|
-
import { ELEMENT_TYPE, KEYBOARD } from '../../constants';
|
|
9
|
+
import { ELEMENT_TYPE, KEYBOARD, CLIPBOARD_FORMAT_KEY } from '../../constants';
|
|
10
10
|
import { TABLE_MAX_ROWS, TABLE_MAX_COLUMNS, EMPTY_SELECTED_RANGE, TABLE_ROW_MIN_HEIGHT, TABLE_CELL_MIN_WIDTH, TABLE_ELEMENT, TABLE_ELEMENT_POSITION } from './constants';
|
|
11
11
|
import EventBus from '../../../utils/event-bus';
|
|
12
12
|
import { EXTERNAL_EVENT, PAGE_EDIT_AREA_WIDTH } from '../../../../constants';
|
|
13
13
|
import ObjectUtils from '../../../utils/object-utils';
|
|
14
14
|
import { replacePastedDataId } from '../../../node-id/helpers';
|
|
15
|
-
import { CLIPBOARD_FORMAT_KEY } from '../../../constants';
|
|
16
15
|
export var isTableMenuDisabled = function isTableMenuDisabled(editor) {
|
|
17
16
|
var selection = editor.selection;
|
|
18
17
|
if (selection === null) return true;
|
|
@@ -17,9 +17,9 @@ var CommonMenu = /*#__PURE__*/function (_Component) {
|
|
|
17
17
|
className = _this$props.className,
|
|
18
18
|
disabled = _this$props.disabled;
|
|
19
19
|
var itemClass = 'btn btn-icon btn-secondary btn-active d-flex';
|
|
20
|
-
if (!isRichEditor) return itemClass + ' ' + className;
|
|
20
|
+
if (!isRichEditor) return itemClass + ' ' + className + ' sdoc-menu-with-dropdown';
|
|
21
21
|
itemClass = "rich-icon-btn d-flex ".concat(disabled ? 'rich-icon-btn-disabled' : 'rich-icon-btn-hover');
|
|
22
|
-
return itemClass + ' ' + className;
|
|
22
|
+
return itemClass + ' ' + className + ' sdoc-menu-with-dropdown';
|
|
23
23
|
};
|
|
24
24
|
_this.hidePopover = function () {
|
|
25
25
|
_this.ref && _this.ref.toggle && _this.ref.toggle();
|
|
@@ -53,11 +53,15 @@ var CommonMenu = /*#__PURE__*/function (_Component) {
|
|
|
53
53
|
id: id,
|
|
54
54
|
type: "button",
|
|
55
55
|
className: className
|
|
56
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
57
|
+
className: "sdoc-menu-with-dropdown-icon"
|
|
56
58
|
}, /*#__PURE__*/React.createElement("i", {
|
|
57
59
|
className: iconClass
|
|
58
|
-
}), /*#__PURE__*/React.createElement("
|
|
59
|
-
className: "
|
|
60
|
-
}
|
|
60
|
+
})), /*#__PURE__*/React.createElement("div", {
|
|
61
|
+
className: "sdoc-menu-with-dropdown-triangle"
|
|
62
|
+
}, /*#__PURE__*/React.createElement("i", {
|
|
63
|
+
className: "sdoc-menu-with-dropdown-triangle-icon sdocfont sdoc-".concat(isShowMenu ? 'caret-up' : 'drop-down')
|
|
64
|
+
}))), /*#__PURE__*/React.createElement(UncontrolledPopover, {
|
|
61
65
|
target: id,
|
|
62
66
|
className: "sdoc-common-menu-popover",
|
|
63
67
|
trigger: "legacy",
|
|
@@ -1,11 +1,20 @@
|
|
|
1
1
|
.sdoc-table-menu-group.menu-group .menu-group-item:not(.sdoc-remove-table) {
|
|
2
|
-
width:
|
|
3
|
-
display: flex;
|
|
4
|
-
align-items: center;
|
|
5
|
-
justify-content: center;
|
|
2
|
+
width: 36px;
|
|
6
3
|
}
|
|
7
4
|
|
|
8
|
-
.sdoc-table-menu-group .sdoc-
|
|
9
|
-
|
|
10
|
-
|
|
5
|
+
.sdoc-table-menu-group .sdoc-menu-with-dropdown .sdoc-menu-with-dropdown-icon {
|
|
6
|
+
width: 24px;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
.sdoc-table-menu-group .sdoc-menu-with-dropdown .sdoc-menu-with-dropdown-triangle {
|
|
10
|
+
width: 12px;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
.sdoc-table-menu-group .sdoc-color-menu .last-used-color-container {
|
|
14
|
+
height: 100%;
|
|
15
|
+
padding-top: 2px;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
.sdoc-color-menu-popover.sdoc-table-cell-bg-colors-popover .popover {
|
|
19
|
+
left: -24px !important;
|
|
11
20
|
}
|
|
@@ -7,12 +7,11 @@ import _createSuper from "@babel/runtime/helpers/esm/createSuper";
|
|
|
7
7
|
import React, { Component } from 'react';
|
|
8
8
|
import { withTranslation } from 'react-i18next';
|
|
9
9
|
import classnames from 'classnames';
|
|
10
|
-
import { MenuGroup, MenuItem } from '../../../../
|
|
10
|
+
import { ColorMenu, MenuGroup, MenuItem } from '../../../../commons';
|
|
11
11
|
import CommonMenu from './common-menu';
|
|
12
12
|
import { MENUS_CONFIG_MAP, REMOVE_TABLE, BG_COLOR } from '../../../../constants';
|
|
13
13
|
import { setCellStyle, insertTableElement, removeTableElement, isAllInTable } from '../../helpers';
|
|
14
14
|
import { TABLE_ELEMENT } from '../../constants';
|
|
15
|
-
import ColorMenu from '../../../../menu/color-menu';
|
|
16
15
|
import './index.css';
|
|
17
16
|
var ActiveTableMenu = /*#__PURE__*/function (_Component) {
|
|
18
17
|
_inherits(ActiveTableMenu, _Component);
|
|
@@ -57,7 +56,7 @@ var ActiveTableMenu = /*#__PURE__*/function (_Component) {
|
|
|
57
56
|
var t = _this.props.t;
|
|
58
57
|
return /*#__PURE__*/React.createElement(CommonMenu, {
|
|
59
58
|
id: "text-align",
|
|
60
|
-
iconClass: "sdocfont sdoc-align-left
|
|
59
|
+
iconClass: "sdocfont sdoc-align-left",
|
|
61
60
|
ref: function ref(_ref) {
|
|
62
61
|
return _this.textAlignRef = _ref;
|
|
63
62
|
}
|
|
@@ -82,7 +81,7 @@ var ActiveTableMenu = /*#__PURE__*/function (_Component) {
|
|
|
82
81
|
var t = _this.props.t;
|
|
83
82
|
return /*#__PURE__*/React.createElement(CommonMenu, {
|
|
84
83
|
id: "table-column",
|
|
85
|
-
iconClass: "sdocfont sdoc-column
|
|
84
|
+
iconClass: "sdocfont sdoc-column",
|
|
86
85
|
ref: function ref(_ref2) {
|
|
87
86
|
return _this.tableColumnRef = _ref2;
|
|
88
87
|
}
|
|
@@ -98,7 +97,7 @@ var ActiveTableMenu = /*#__PURE__*/function (_Component) {
|
|
|
98
97
|
var t = _this.props.t;
|
|
99
98
|
return /*#__PURE__*/React.createElement(CommonMenu, {
|
|
100
99
|
id: "table-row",
|
|
101
|
-
iconClass: "sdocfont sdoc-row
|
|
100
|
+
iconClass: "sdocfont sdoc-row",
|
|
102
101
|
ref: function ref(_ref3) {
|
|
103
102
|
return _this.tableRowRef = _ref3;
|
|
104
103
|
}
|
|
@@ -144,7 +143,9 @@ var ActiveTableMenu = /*#__PURE__*/function (_Component) {
|
|
|
144
143
|
}, menuConfig), {}, {
|
|
145
144
|
onMouseDown: function onMouseDown() {},
|
|
146
145
|
setColor: _this.setColor,
|
|
147
|
-
|
|
146
|
+
recentUsedColorsKey: 'sdoc-recent-used-bg-colors',
|
|
147
|
+
lastUsedColorKey: 'sdoc-last-used-bg-colors',
|
|
148
|
+
popoverClassName: 'sdoc-table-cell-bg-colors-popover'
|
|
148
149
|
});
|
|
149
150
|
return /*#__PURE__*/React.createElement(ColorMenu, props);
|
|
150
151
|
};
|
|
@@ -6,12 +6,12 @@ import _createSuper from "@babel/runtime/helpers/esm/createSuper";
|
|
|
6
6
|
import React from 'react';
|
|
7
7
|
import { withTranslation } from 'react-i18next';
|
|
8
8
|
import ObjectUtils from '../../../../../utils/object-utils';
|
|
9
|
+
import { ElementPopover } from '../../../../commons';
|
|
9
10
|
import { ELEMENT_TYPE } from '../../../../constants';
|
|
10
|
-
import InsertTableElement from './insert-table-element';
|
|
11
11
|
import { getSelectedNodeByType } from '../../../../core';
|
|
12
12
|
import { TABLE_MAX_COLUMNS, TABLE_MAX_ROWS, TABLE_ELEMENT, TABLE_ELEMENT_POSITION } from '../../constants';
|
|
13
13
|
import { insertTableElement, removeTableElement } from '../../helpers';
|
|
14
|
-
import
|
|
14
|
+
import InsertTableElement from './insert-table-element';
|
|
15
15
|
import './index.css';
|
|
16
16
|
var TableContextMenu = /*#__PURE__*/function (_React$Component) {
|
|
17
17
|
_inherits(TableContextMenu, _React$Component);
|
|
@@ -98,7 +98,7 @@ var TableContextMenu = /*#__PURE__*/function (_React$Component) {
|
|
|
98
98
|
var selectedCols = tableSelectedRange.maxColIndex - tableSelectedRange.minColIndex + 1;
|
|
99
99
|
var canAddRowsCount = currentRowsCount + selectedRows > TABLE_MAX_ROWS ? TABLE_MAX_ROWS - currentRowsCount : selectedRows;
|
|
100
100
|
var canAddColsCount = currentColumnsCount + selectedCols > TABLE_MAX_COLUMNS ? TABLE_MAX_COLUMNS - currentColumnsCount : selectedCols;
|
|
101
|
-
return /*#__PURE__*/React.createElement(
|
|
101
|
+
return /*#__PURE__*/React.createElement(ElementPopover, {
|
|
102
102
|
className: "sdoc-context-menu"
|
|
103
103
|
}, /*#__PURE__*/React.createElement("div", {
|
|
104
104
|
style: contextStyle,
|
|
@@ -7,7 +7,7 @@ import React from 'react';
|
|
|
7
7
|
import { withTranslation } from 'react-i18next';
|
|
8
8
|
import { insertTable, isTableMenuDisabled } from '../../helpers';
|
|
9
9
|
import { TABLE, MENUS_CONFIG_MAP } from '../../../../constants';
|
|
10
|
-
import { MenuItem } from '../../../../
|
|
10
|
+
import { MenuItem } from '../../../../commons';
|
|
11
11
|
import TableSizePopover from '../../popover/table-size-popover';
|
|
12
12
|
var TableMenu = /*#__PURE__*/function (_React$Component) {
|
|
13
13
|
_inherits(TableMenu, _React$Component);
|
|
@@ -4,13 +4,12 @@ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
|
4
4
|
import isHotkey from 'is-hotkey';
|
|
5
5
|
import { Editor, Transforms, Path } from '@seafile/slate';
|
|
6
6
|
import { getNodeType, getParentNode, getSelectedNodeByType, isLastNode, generateEmptyElement } from '../../core';
|
|
7
|
-
import { ELEMENT_TYPE, KEYBOARD, PARAGRAPH } from '../../constants';
|
|
7
|
+
import { ELEMENT_TYPE, KEYBOARD, PARAGRAPH, CLIPBOARD_FORMAT_KEY } from '../../constants';
|
|
8
8
|
import { TABLE_MAX_ROWS, EMPTY_SELECTED_RANGE, TABLE_ELEMENT, TABLE_ELEMENT_POSITION } from './constants';
|
|
9
9
|
import ObjectUtils from '../../../utils/object-utils';
|
|
10
10
|
import { getSelectedInfo, insertTableElement, removeTable, insertMultipleRowsAndColumns, setTableFragmentData, deleteTableRangeData, focusCell, deleteHandler, isTableLocation, isLastTableCell } from './helpers';
|
|
11
11
|
import EventBus from '../../../utils/event-bus';
|
|
12
12
|
import { EXTERNAL_EVENT } from '../../../../constants';
|
|
13
|
-
import { CLIPBOARD_FORMAT_KEY } from '../../../constants';
|
|
14
13
|
var withTable = function withTable(editor) {
|
|
15
14
|
var insertBreak = editor.insertBreak,
|
|
16
15
|
deleteBackward = editor.deleteBackward,
|
|
@@ -48,7 +48,7 @@ var TableCell = function TableCell(_ref) {
|
|
|
48
48
|
}
|
|
49
49
|
if (ObjectUtils.hasProperty(element.style, STYLE_KEY.BG_COLOR)) {
|
|
50
50
|
var color = element.style[STYLE_KEY.BG_COLOR];
|
|
51
|
-
if (color &&
|
|
51
|
+
if (color && color !== 'transparent' && color !== 'unset') {
|
|
52
52
|
style['backgroundColor'] = isSelected ? colorBlend(SELECTED_TABLE_CELL_BG_COLOR, color, 0.9) : color;
|
|
53
53
|
}
|
|
54
54
|
}
|
|
@@ -88,7 +88,7 @@ function renderTableCell(props) {
|
|
|
88
88
|
if (ObjectUtils.hasProperty(element, STYLE_KEY.TEXT_ALIGN)) {
|
|
89
89
|
style[STYLE_KEY.TEXT_ALIGN] = element[STYLE_KEY.TEXT_ALIGN];
|
|
90
90
|
}
|
|
91
|
-
if (ObjectUtils.hasProperty(element.style, STYLE_KEY.BG_COLOR)) {
|
|
91
|
+
if (ObjectUtils.hasProperty(element.style, STYLE_KEY.BG_COLOR) && element.style[STYLE_KEY.BG_COLOR]) {
|
|
92
92
|
style['backgroundColor'] = element.style[STYLE_KEY.BG_COLOR];
|
|
93
93
|
}
|
|
94
94
|
var column = getCellColumn(editor, element);
|
|
@@ -1,116 +1,87 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import _createSuper from "@babel/runtime/helpers/esm/createSuper";
|
|
5
|
-
import React from 'react';
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
2
|
+
import React, { useRef, useState, useCallback } from 'react';
|
|
3
|
+
import { UncontrolledPopover } from 'reactstrap';
|
|
6
4
|
import { withTranslation } from 'react-i18next';
|
|
7
5
|
import classnames from 'classnames';
|
|
8
6
|
import { getAlignType, isMenuDisabled, setAlignType } from '../helpers';
|
|
9
7
|
import { TEXT_ALIGN, MENUS_CONFIG_MAP } from '../../../constants';
|
|
10
|
-
|
|
11
|
-
var
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
8
|
+
var TextAlignMenu = function TextAlignMenu(_ref) {
|
|
9
|
+
var isRichEditor = _ref.isRichEditor,
|
|
10
|
+
className = _ref.className,
|
|
11
|
+
editor = _ref.editor;
|
|
12
|
+
var _useState = useState(false),
|
|
13
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
14
|
+
isShowMenu = _useState2[0],
|
|
15
|
+
setMenuShow = _useState2[1];
|
|
16
|
+
var popoverRef = useRef(null);
|
|
17
|
+
var disabled = isMenuDisabled(editor);
|
|
18
|
+
var buttonId = 'sdoc-button-text-align';
|
|
19
|
+
var toggle = useCallback(function (event) {
|
|
20
|
+
popoverRef.current.toggle();
|
|
21
|
+
setMenuShow(!isShowMenu);
|
|
22
|
+
|
|
23
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
24
|
+
}, [isShowMenu]);
|
|
25
|
+
var getCurrentType = useCallback(function () {
|
|
26
|
+
return getAlignType(editor);
|
|
27
|
+
}, [editor]);
|
|
28
|
+
var setType = useCallback(function (type) {
|
|
29
|
+
setAlignType(editor, type);
|
|
30
|
+
toggle();
|
|
31
|
+
|
|
32
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
33
|
+
}, [editor, isShowMenu]);
|
|
34
|
+
var validClassName = classnames(className, 'sdoc-menu-with-dropdown', {
|
|
35
|
+
'menu-show': isShowMenu,
|
|
36
|
+
'disabled': disabled,
|
|
37
|
+
'rich-icon-btn d-flex': isRichEditor,
|
|
38
|
+
'rich-icon-btn-disabled': isRichEditor && disabled,
|
|
39
|
+
'rich-icon-btn-hover': isRichEditor && !disabled,
|
|
40
|
+
'btn btn-icon btn-secondary btn-active d-flex': !isRichEditor
|
|
41
|
+
});
|
|
42
|
+
var curType = getCurrentType();
|
|
43
|
+
var curIcon = MENUS_CONFIG_MAP[TEXT_ALIGN].filter(function (item) {
|
|
44
|
+
return item.type === curType;
|
|
45
|
+
})[0].iconClass;
|
|
46
|
+
var caretIconClass = "sdoc-menu-with-dropdown-triangle-icon sdocfont sdoc-".concat(isShowMenu ? 'caret-up' : 'drop-down');
|
|
47
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("button", {
|
|
48
|
+
type: "button",
|
|
49
|
+
className: validClassName,
|
|
50
|
+
id: buttonId,
|
|
51
|
+
disabled: disabled
|
|
52
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
53
|
+
className: "sdoc-menu-with-dropdown-icon"
|
|
54
|
+
}, /*#__PURE__*/React.createElement("span", {
|
|
55
|
+
className: curIcon
|
|
56
|
+
})), !disabled && /*#__PURE__*/React.createElement("div", {
|
|
57
|
+
className: "sdoc-menu-with-dropdown-triangle"
|
|
58
|
+
}, /*#__PURE__*/React.createElement("span", {
|
|
59
|
+
className: caretIconClass
|
|
60
|
+
}))), !disabled && /*#__PURE__*/React.createElement(UncontrolledPopover, {
|
|
61
|
+
target: buttonId,
|
|
62
|
+
className: "sdoc-menu-popover sdoc-dropdown-menu",
|
|
63
|
+
trigger: "legacy",
|
|
64
|
+
placement: "bottom-start",
|
|
65
|
+
hideArrow: true,
|
|
66
|
+
toggle: toggle,
|
|
67
|
+
fade: false,
|
|
68
|
+
ref: popoverRef
|
|
69
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
70
|
+
className: "pt-2 pb-2"
|
|
71
|
+
}, MENUS_CONFIG_MAP[TEXT_ALIGN].map(function (item, index) {
|
|
72
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
73
|
+
key: index,
|
|
74
|
+
className: "sdoc-dropdown-menu-item",
|
|
75
|
+
onClick: function onClick() {
|
|
76
|
+
return setType(item.type);
|
|
61
77
|
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
};
|
|
72
|
-
_this.setMenuRef = function (ref) {
|
|
73
|
-
_this.menu = ref;
|
|
74
|
-
};
|
|
75
|
-
_this.state = {
|
|
76
|
-
isDropdownMenuOpen: false
|
|
77
|
-
};
|
|
78
|
-
return _this;
|
|
79
|
-
}
|
|
80
|
-
_createClass(TextAlignMenu, [{
|
|
81
|
-
key: "render",
|
|
82
|
-
value: function render() {
|
|
83
|
-
var _this2 = this;
|
|
84
|
-
var isDropdownMenuOpen = this.state.isDropdownMenuOpen;
|
|
85
|
-
var caretIconClass = "caret-icon sdocfont sdoc-".concat(isDropdownMenuOpen ? 'caret-up' : 'drop-down');
|
|
86
|
-
var curType = this.getCurrentType();
|
|
87
|
-
var curIcon = MENUS_CONFIG_MAP[TEXT_ALIGN].filter(function (item) {
|
|
88
|
-
return item.type == curType;
|
|
89
|
-
})[0].iconClass;
|
|
90
|
-
var disabled = this.isDisabled();
|
|
91
|
-
return /*#__PURE__*/React.createElement("div", {
|
|
92
|
-
className: "align-menu"
|
|
93
|
-
}, /*#__PURE__*/React.createElement("div", {
|
|
94
|
-
className: classnames('align-toggle px-2', {
|
|
95
|
-
'align-toggle-disabled': disabled
|
|
96
|
-
}),
|
|
97
|
-
onClick: disabled ? function () {} : this.onToggleClick
|
|
98
|
-
}, /*#__PURE__*/React.createElement("span", {
|
|
99
|
-
className: "mr-1 ".concat(curIcon)
|
|
100
|
-
}), !disabled && /*#__PURE__*/React.createElement("span", {
|
|
101
|
-
className: caretIconClass
|
|
102
|
-
})), isDropdownMenuOpen && /*#__PURE__*/React.createElement("div", {
|
|
103
|
-
ref: this.setMenuRef,
|
|
104
|
-
className: "align-popover sdoc-dropdown-menu"
|
|
105
|
-
}, MENUS_CONFIG_MAP[TEXT_ALIGN].map(function (item, index) {
|
|
106
|
-
return /*#__PURE__*/React.createElement("span", {
|
|
107
|
-
key: index,
|
|
108
|
-
className: "sdoc-dropdown-menu-item ".concat(item.iconClass),
|
|
109
|
-
onClick: _this2.setType.bind(_this2, item.type)
|
|
110
|
-
});
|
|
111
|
-
})));
|
|
112
|
-
}
|
|
113
|
-
}]);
|
|
114
|
-
return TextAlignMenu;
|
|
115
|
-
}(React.Component);
|
|
78
|
+
}, /*#__PURE__*/React.createElement("i", {
|
|
79
|
+
className: item.iconClass
|
|
80
|
+
}));
|
|
81
|
+
}))));
|
|
82
|
+
};
|
|
83
|
+
TextAlignMenu.defaultProps = {
|
|
84
|
+
isRichEditor: true,
|
|
85
|
+
className: 'menu-group-item'
|
|
86
|
+
};
|
|
116
87
|
export default withTranslation('sdoc-editor')(TextAlignMenu);
|
|
@@ -4,15 +4,14 @@ import { withTranslation } from 'react-i18next';
|
|
|
4
4
|
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
|
-
import { MenuItem } from '../../../
|
|
7
|
+
import { MenuItem, ColorMenu, MoreDropdown } from '../../../commons';
|
|
8
8
|
import { getValue, isMenuDisabled, addMark, removeMark } from '../helpers';
|
|
9
|
-
import MoreDropdown from '../../../../../components/more-dropdown';
|
|
10
|
-
import ColorMenu from '../../../menu/color-menu';
|
|
11
9
|
var TextStyleMenuList = function TextStyleMenuList(_ref) {
|
|
12
10
|
var editor = _ref.editor,
|
|
13
11
|
t = _ref.t,
|
|
14
12
|
isRichEditor = _ref.isRichEditor,
|
|
15
|
-
className = _ref.className
|
|
13
|
+
className = _ref.className,
|
|
14
|
+
idPrefix = _ref.idPrefix;
|
|
16
15
|
var isActive = useCallback(function (type) {
|
|
17
16
|
var isMark = getValue(editor, type);
|
|
18
17
|
return !!isMark;
|
|
@@ -59,7 +58,9 @@ var TextStyleMenuList = function TextStyleMenuList(_ref) {
|
|
|
59
58
|
};
|
|
60
59
|
itemProps['defaultColorTip'] = item.type === ELEMENT_TYPE.COLOR ? t('Default') : '';
|
|
61
60
|
}
|
|
62
|
-
return _objectSpread(_objectSpread({}, itemProps), item)
|
|
61
|
+
return _objectSpread(_objectSpread(_objectSpread({}, itemProps), item), {}, {
|
|
62
|
+
id: idPrefix ? "".concat(idPrefix, "_").concat(item.id) : item.id
|
|
63
|
+
});
|
|
63
64
|
});
|
|
64
65
|
|
|
65
66
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import React, { useRef, useEffect, useCallback } from 'react';
|
|
2
|
+
import { createPortal } from 'react-dom';
|
|
3
|
+
import { useFocused, useSlateStatic, useReadOnly } from '@seafile/slate-react';
|
|
4
|
+
import { Editor, Range } from '@seafile/slate';
|
|
5
|
+
import { MenuGroup } from '../../commons';
|
|
6
|
+
import TextStyleMenuList from '../../plugins/text-style/menu';
|
|
7
|
+
import { useScrollContext } from '../../../hooks/use-scroll-context';
|
|
8
|
+
import { getSelectedNodeByType } from '../../core';
|
|
9
|
+
import { CODE_BLOCK } from '../../constants';
|
|
10
|
+
import './index.css';
|
|
11
|
+
var ContextToolbar = function ContextToolbar() {
|
|
12
|
+
var ref = useRef(null);
|
|
13
|
+
var editor = useSlateStatic();
|
|
14
|
+
var scrollRef = useScrollContext();
|
|
15
|
+
var inFocus = useFocused();
|
|
16
|
+
var readOnly = useReadOnly();
|
|
17
|
+
var setContextToolbarPosition = useCallback(function () {
|
|
18
|
+
var el = ref.current;
|
|
19
|
+
var domSelection = window.getSelection();
|
|
20
|
+
var domRange = domSelection.getRangeAt(0);
|
|
21
|
+
var rect = domRange.getBoundingClientRect();
|
|
22
|
+
el.style.top = "".concat(rect.top - el.offsetHeight, "px");
|
|
23
|
+
el.style.left = "".concat(rect.left, "px");
|
|
24
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
25
|
+
}, []);
|
|
26
|
+
var onScroll = useCallback(function (e) {
|
|
27
|
+
setContextToolbarPosition();
|
|
28
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
29
|
+
}, []);
|
|
30
|
+
useEffect(function () {
|
|
31
|
+
var el = ref.current;
|
|
32
|
+
var selection = editor.selection;
|
|
33
|
+
if (!el) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
if (readOnly || !selection || !inFocus || Range.isCollapsed(selection) || Editor.string(editor, selection) === '' || getSelectedNodeByType(editor, CODE_BLOCK)) {
|
|
37
|
+
scrollRef.current && scrollRef.current.removeEventListener('scroll', onScroll);
|
|
38
|
+
el.removeAttribute('style');
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
scrollRef.current && scrollRef.current.addEventListener('scroll', onScroll);
|
|
42
|
+
setContextToolbarPosition();
|
|
43
|
+
});
|
|
44
|
+
var onMouseDown = useCallback(function (event) {
|
|
45
|
+
event.preventDefault(); // prevent toolbar from taking focus away from editor
|
|
46
|
+
}, []);
|
|
47
|
+
return createPortal( /*#__PURE__*/React.createElement("div", {
|
|
48
|
+
ref: ref,
|
|
49
|
+
className: "sdoc-context-toolbar",
|
|
50
|
+
onMouseDown: onMouseDown
|
|
51
|
+
}, /*#__PURE__*/React.createElement(MenuGroup, null, /*#__PURE__*/React.createElement(TextStyleMenuList, {
|
|
52
|
+
editor: editor,
|
|
53
|
+
idPrefix: 'sdoc_context_toolbar'
|
|
54
|
+
}))), document.body);
|
|
55
|
+
};
|
|
56
|
+
export default ContextToolbar;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import useSelectionUpdate from '../../../hooks/use-selection-update';
|
|
3
|
+
import { ORDERED_LIST, UNORDERED_LIST } from '../../constants';
|
|
4
|
+
import { MenuGroup } from '../../commons';
|
|
5
|
+
import QuoteMenu from '../../plugins/blockquote/menu';
|
|
6
|
+
import LinkMenu from '../../plugins/link/menu';
|
|
7
|
+
import ListMenu from '../../plugins/list/menu';
|
|
8
|
+
import ImageMenu from '../../plugins/image/menu';
|
|
9
|
+
import HeaderMenu from '../../plugins/header/menu';
|
|
10
|
+
import CheckListMenu from '../../plugins/check-list/menu';
|
|
11
|
+
import TextStyleMenuList from '../../plugins/text-style/menu';
|
|
12
|
+
import CodeBlockMenu from '../../plugins/code-block/menu';
|
|
13
|
+
import TextAlignMenu from '../../plugins/text-align/menu';
|
|
14
|
+
import { TableMenu, ActiveTableMenu } from '../../plugins/table/menu';
|
|
15
|
+
import ClearFormatMenu from '../../plugins/clear-format/menu';
|
|
16
|
+
import HistoryMenu from './redo-undo';
|
|
17
|
+
var Toolbar = function Toolbar(_ref) {
|
|
18
|
+
var editor = _ref.editor;
|
|
19
|
+
useSelectionUpdate();
|
|
20
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
21
|
+
className: "sdoc-editor-toolbar"
|
|
22
|
+
}, /*#__PURE__*/React.createElement(MenuGroup, null, /*#__PURE__*/React.createElement(HistoryMenu, {
|
|
23
|
+
editor: editor
|
|
24
|
+
}), /*#__PURE__*/React.createElement(ClearFormatMenu, {
|
|
25
|
+
editor: editor
|
|
26
|
+
})), /*#__PURE__*/React.createElement(HeaderMenu, {
|
|
27
|
+
editor: editor
|
|
28
|
+
}), /*#__PURE__*/React.createElement(MenuGroup, null, /*#__PURE__*/React.createElement(TextStyleMenuList, {
|
|
29
|
+
editor: editor
|
|
30
|
+
})), /*#__PURE__*/React.createElement(MenuGroup, null, /*#__PURE__*/React.createElement(QuoteMenu, {
|
|
31
|
+
editor: editor
|
|
32
|
+
}), /*#__PURE__*/React.createElement(ListMenu, {
|
|
33
|
+
editor: editor,
|
|
34
|
+
type: UNORDERED_LIST
|
|
35
|
+
}), /*#__PURE__*/React.createElement(ListMenu, {
|
|
36
|
+
editor: editor,
|
|
37
|
+
type: ORDERED_LIST
|
|
38
|
+
}), /*#__PURE__*/React.createElement(CheckListMenu, {
|
|
39
|
+
editor: editor
|
|
40
|
+
}), /*#__PURE__*/React.createElement(TextAlignMenu, {
|
|
41
|
+
editor: editor
|
|
42
|
+
})), /*#__PURE__*/React.createElement(MenuGroup, null, /*#__PURE__*/React.createElement(CodeBlockMenu, {
|
|
43
|
+
editor: editor
|
|
44
|
+
}), /*#__PURE__*/React.createElement(TableMenu, {
|
|
45
|
+
editor: editor
|
|
46
|
+
})), /*#__PURE__*/React.createElement(ActiveTableMenu, {
|
|
47
|
+
editor: editor
|
|
48
|
+
}), /*#__PURE__*/React.createElement(MenuGroup, null, /*#__PURE__*/React.createElement(ImageMenu, {
|
|
49
|
+
editor: editor
|
|
50
|
+
}), /*#__PURE__*/React.createElement(LinkMenu, {
|
|
51
|
+
editor: editor
|
|
52
|
+
})));
|
|
53
|
+
};
|
|
54
|
+
export default Toolbar;
|
|
@@ -4,8 +4,8 @@ import _createClass from "@babel/runtime/helpers/esm/createClass";
|
|
|
4
4
|
import _inherits from "@babel/runtime/helpers/esm/inherits";
|
|
5
5
|
import _createSuper from "@babel/runtime/helpers/esm/createSuper";
|
|
6
6
|
import React from 'react';
|
|
7
|
-
import { MenuItem } from '
|
|
8
|
-
import { MENUS_CONFIG_MAP, REDO, UNDO } from '
|
|
7
|
+
import { MenuItem } from '../../commons';
|
|
8
|
+
import { MENUS_CONFIG_MAP, REDO, UNDO } from '../../constants';
|
|
9
9
|
var HistoryMenu = /*#__PURE__*/function (_React$Component) {
|
|
10
10
|
_inherits(HistoryMenu, _React$Component);
|
|
11
11
|
var _super = _createSuper(HistoryMenu);
|
|
@@ -1,54 +1,3 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
import { MenuGroup } from '../menu';
|
|
5
|
-
import QuoteMenu from '../plugins/blockquote/menu';
|
|
6
|
-
import LinkMenu from '../plugins/link/menu';
|
|
7
|
-
import ListMenu from '../plugins/list/menu';
|
|
8
|
-
import ImageMenu from '../plugins/image/menu';
|
|
9
|
-
import HeaderMenu from '../plugins/header/menu';
|
|
10
|
-
import CheckListMenu from '../plugins/check-list/menu';
|
|
11
|
-
import TextStyleMenuList from '../plugins/text-style/menu';
|
|
12
|
-
import CodeBlockMenu from '../plugins/code-block/menu';
|
|
13
|
-
import TextAlignMenu from '../plugins/text-align/menu';
|
|
14
|
-
import HistoryMenu from './redo-undo';
|
|
15
|
-
import { TableMenu, ActiveTableMenu } from '../plugins/table/menu';
|
|
16
|
-
import ClearFormatMenu from '../plugins/clear-format/menu';
|
|
17
|
-
var Toolbar = function Toolbar(_ref) {
|
|
18
|
-
var editor = _ref.editor;
|
|
19
|
-
useSelectionUpdate();
|
|
20
|
-
return /*#__PURE__*/React.createElement("div", {
|
|
21
|
-
className: "sdoc-editor-toolbar"
|
|
22
|
-
}, /*#__PURE__*/React.createElement(MenuGroup, null, /*#__PURE__*/React.createElement(HistoryMenu, {
|
|
23
|
-
editor: editor
|
|
24
|
-
})), /*#__PURE__*/React.createElement(MenuGroup, null, /*#__PURE__*/React.createElement(ClearFormatMenu, {
|
|
25
|
-
editor: editor
|
|
26
|
-
})), /*#__PURE__*/React.createElement(HeaderMenu, {
|
|
27
|
-
editor: editor
|
|
28
|
-
}), /*#__PURE__*/React.createElement(MenuGroup, null, /*#__PURE__*/React.createElement(TextStyleMenuList, {
|
|
29
|
-
editor: editor
|
|
30
|
-
})), /*#__PURE__*/React.createElement(MenuGroup, null, /*#__PURE__*/React.createElement(QuoteMenu, {
|
|
31
|
-
editor: editor
|
|
32
|
-
}), /*#__PURE__*/React.createElement(ListMenu, {
|
|
33
|
-
editor: editor,
|
|
34
|
-
type: UNORDERED_LIST
|
|
35
|
-
}), /*#__PURE__*/React.createElement(ListMenu, {
|
|
36
|
-
editor: editor,
|
|
37
|
-
type: ORDERED_LIST
|
|
38
|
-
}), /*#__PURE__*/React.createElement(CheckListMenu, {
|
|
39
|
-
editor: editor
|
|
40
|
-
}), /*#__PURE__*/React.createElement(TextAlignMenu, {
|
|
41
|
-
editor: editor
|
|
42
|
-
})), /*#__PURE__*/React.createElement(MenuGroup, null, /*#__PURE__*/React.createElement(CodeBlockMenu, {
|
|
43
|
-
editor: editor
|
|
44
|
-
}), /*#__PURE__*/React.createElement(TableMenu, {
|
|
45
|
-
editor: editor
|
|
46
|
-
})), /*#__PURE__*/React.createElement(ActiveTableMenu, {
|
|
47
|
-
editor: editor
|
|
48
|
-
}), /*#__PURE__*/React.createElement(MenuGroup, null, /*#__PURE__*/React.createElement(ImageMenu, {
|
|
49
|
-
editor: editor
|
|
50
|
-
}), /*#__PURE__*/React.createElement(LinkMenu, {
|
|
51
|
-
editor: editor
|
|
52
|
-
})));
|
|
53
|
-
};
|
|
54
|
-
export default Toolbar;
|
|
1
|
+
import Toolbar from './header-toolbar';
|
|
2
|
+
import ContextToolbar from './context-toolbar';
|
|
3
|
+
export { Toolbar, ContextToolbar };
|