@seafile/sdoc-editor 0.1.86 → 0.1.88-beta
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/assets/css/simple-editor.css +11 -0
- package/dist/basic-sdk/assets/css/dropdown-menu.css +6 -0
- package/dist/basic-sdk/editor.js +12 -38
- package/dist/{components/modal-portal.js → basic-sdk/extension/commons/element-popover/index.js} +11 -8
- package/dist/basic-sdk/extension/constants/color.js +2 -1
- package/dist/basic-sdk/extension/constants/element-type.js +4 -1
- package/dist/basic-sdk/extension/constants/index.js +25 -3
- package/dist/basic-sdk/extension/core/queries/index.js +1 -1
- package/dist/basic-sdk/extension/index.js +1 -2
- package/dist/basic-sdk/{comment → extension/menu}/color-menu/color-item.js +2 -2
- package/dist/basic-sdk/{comment → extension/menu}/color-menu/index.css +61 -9
- package/dist/basic-sdk/{comment → extension/menu}/color-menu/index.js +57 -32
- package/dist/basic-sdk/extension/menu/index.js +1 -2
- package/dist/basic-sdk/extension/menu/menu-item.js +1 -0
- package/dist/basic-sdk/extension/menu/menu.css +52 -1
- package/dist/basic-sdk/extension/plugins/clear-format/helpers.js +56 -0
- package/dist/basic-sdk/extension/plugins/clear-format/menu/index.js +25 -0
- package/dist/{components/code-block-hover-menu → basic-sdk/extension/plugins/code-block/hover-menu}/index.js +4 -4
- package/dist/basic-sdk/extension/plugins/code-block/render-elem.js +1 -1
- package/dist/basic-sdk/extension/plugins/html/rules/code-block.js +1 -1
- package/dist/basic-sdk/extension/plugins/table/constants/index.js +2 -1
- package/dist/basic-sdk/extension/plugins/table/dialog/custom-table-size-dialog/index.js +1 -1
- package/dist/basic-sdk/extension/plugins/table/index.js +2 -3
- 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 +19 -3
- package/dist/basic-sdk/extension/plugins/table/menu/active-table-menu/index.js +9 -6
- package/dist/basic-sdk/extension/plugins/table/menu/index.js +2 -2
- package/dist/basic-sdk/extension/plugins/table/menu/{context-menu → table-context-menu}/index.js +15 -11
- package/dist/basic-sdk/extension/plugins/table/render/hooks.js +51 -1
- package/dist/basic-sdk/extension/plugins/table/render/index.css +0 -34
- package/dist/basic-sdk/extension/plugins/table/render/render-cell.js +19 -7
- package/dist/basic-sdk/extension/plugins/table/render/table-root.js +12 -3
- package/dist/basic-sdk/extension/plugins/text-align/menu/index.js +81 -110
- package/dist/basic-sdk/extension/plugins/text-style/menu/index.js +73 -73
- package/dist/basic-sdk/extension/plugins/text-style/render-elem.js +3 -0
- package/dist/basic-sdk/extension/toolbar/index.js +3 -0
- package/dist/basic-sdk/highlight-decorate/setNodeToDecorations.js +1 -1
- package/dist/basic-sdk/hooks/use-selection-position.js +11 -3
- package/dist/components/more-dropdown/index.js +36 -73
- package/dist/utils/local-storage-utils.js +16 -2
- package/package.json +1 -1
- package/public/locales/en/sdoc-editor.json +4 -1
- package/public/locales/zh-CN/sdoc-editor.json +4 -1
- package/public/media/sdoc-editor-font/iconfont.eot +0 -0
- package/public/media/sdoc-editor-font/iconfont.svg +6 -0
- package/public/media/sdoc-editor-font/iconfont.ttf +0 -0
- package/public/media/sdoc-editor-font/iconfont.woff +0 -0
- package/public/media/sdoc-editor-font/iconfont.woff2 +0 -0
- package/public/media/sdoc-editor-font.css +18 -6
- package/dist/basic-sdk/extension/menu/context-menu/index.css +0 -1
- package/dist/basic-sdk/extension/menu/context-menu/index.js +0 -38
- package/dist/basic-sdk/extension/plugins/text-align/menu/style.css +0 -53
- package/dist/components/more-dropdown/style.css +0 -64
- /package/dist/{components/code-block-hover-menu → basic-sdk/extension/plugins/code-block/hover-menu}/index.css +0 -0
- /package/dist/basic-sdk/{utils → extension/plugins/code-block}/prismjs.js +0 -0
- /package/dist/basic-sdk/extension/plugins/table/{number-input.js → dialog/custom-table-size-dialog/number-input.js} +0 -0
- /package/dist/basic-sdk/extension/plugins/table/menu/{context-menu → table-context-menu}/index.css +0 -0
- /package/dist/basic-sdk/extension/plugins/table/menu/{context-menu → table-context-menu}/insert-table-element.js +0 -0
|
@@ -4,6 +4,9 @@
|
|
|
4
4
|
font-size: 0.75rem;
|
|
5
5
|
border-right: 1px solid #e5e6e8;
|
|
6
6
|
color: #555555;
|
|
7
|
+
display: flex;
|
|
8
|
+
align-items: center;
|
|
9
|
+
justify-content: center;
|
|
7
10
|
}
|
|
8
11
|
|
|
9
12
|
.menu-group .menu-group-item {
|
|
@@ -11,7 +14,7 @@
|
|
|
11
14
|
height: 30px;
|
|
12
15
|
line-height: 30px;
|
|
13
16
|
margin-right: 10px;
|
|
14
|
-
border:
|
|
17
|
+
border: none !important;
|
|
15
18
|
color: #555555;
|
|
16
19
|
background-color: #fff;
|
|
17
20
|
}
|
|
@@ -32,3 +35,51 @@
|
|
|
32
35
|
.menu-group .menu-group-item .sdocfont {
|
|
33
36
|
font-size: 14px;
|
|
34
37
|
}
|
|
38
|
+
|
|
39
|
+
/* sdoc-menu-with-dropdown */
|
|
40
|
+
.menu-group .menu-group-item.sdoc-menu-with-dropdown {
|
|
41
|
+
width: 36px;
|
|
42
|
+
height: 30px;
|
|
43
|
+
display: flex;
|
|
44
|
+
align-items: center;
|
|
45
|
+
justify-content: center;
|
|
46
|
+
border: 0 !important;
|
|
47
|
+
padding: 0 !important;
|
|
48
|
+
margin-right: 10px;
|
|
49
|
+
overflow: hidden;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
.menu-group .menu-group-item.sdoc-menu-with-dropdown.disabled {
|
|
53
|
+
color: #999;
|
|
54
|
+
width: 24px !important;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
.sdoc-menu-with-dropdown:not(.disabled):hover {
|
|
58
|
+
background: #e5e5e5;
|
|
59
|
+
border-radius: 2px;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
.sdoc-menu-with-dropdown .sdoc-menu-with-dropdown-icon {
|
|
63
|
+
width: 24px;
|
|
64
|
+
height: 30px;
|
|
65
|
+
display: flex;
|
|
66
|
+
align-items: center;
|
|
67
|
+
justify-content: center;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
.sdoc-menu-with-dropdown .sdoc-menu-with-dropdown-icon .sdocfont {
|
|
71
|
+
font-size: 14px;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
.sdoc-menu-with-dropdown .sdoc-menu-with-dropdown-triangle {
|
|
75
|
+
width: 12px;
|
|
76
|
+
height: 30px;
|
|
77
|
+
display: flex;
|
|
78
|
+
align-items: center;
|
|
79
|
+
justify-content: center;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
.sdoc-menu-with-dropdown .sdoc-menu-with-dropdown-triangle .sdoc-menu-with-dropdown-triangle-icon {
|
|
83
|
+
font-size: 14px;
|
|
84
|
+
transform: scale(.8);
|
|
85
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIteratorHelper";
|
|
2
|
+
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
3
|
+
import { Editor, Text } from '@seafile/slate';
|
|
4
|
+
import { CODE_BLOCK, CODE_LINE } from '../../constants';
|
|
5
|
+
import { getNodeType } from '../../core';
|
|
6
|
+
export var isMenuDisabled = function isMenuDisabled(editor) {
|
|
7
|
+
if (editor.selection == null) return true;
|
|
8
|
+
var _Editor$nodes = Editor.nodes(editor, {
|
|
9
|
+
match: function match(n) {
|
|
10
|
+
var type = getNodeType(n);
|
|
11
|
+
if ([CODE_BLOCK, CODE_LINE].includes(type)) return true; // code-block
|
|
12
|
+
if (Editor.isVoid(editor, n)) return true; // void node
|
|
13
|
+
|
|
14
|
+
return false;
|
|
15
|
+
},
|
|
16
|
+
universal: true
|
|
17
|
+
}),
|
|
18
|
+
_Editor$nodes2 = _slicedToArray(_Editor$nodes, 1),
|
|
19
|
+
match = _Editor$nodes2[0];
|
|
20
|
+
if (match) return true;
|
|
21
|
+
return false;
|
|
22
|
+
};
|
|
23
|
+
var removeMarks = function removeMarks(editor, textNode) {
|
|
24
|
+
// Iterate text node properties, clearing styles
|
|
25
|
+
var keys = Object.keys(textNode);
|
|
26
|
+
keys.forEach(function (key) {
|
|
27
|
+
if (key === 'text') {
|
|
28
|
+
// Keep only the text attribute (Text attributes are necessary)
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
// All other attributes are deleted
|
|
32
|
+
Editor.removeMark(editor, key);
|
|
33
|
+
});
|
|
34
|
+
};
|
|
35
|
+
export var clearStyles = function clearStyles(editor) {
|
|
36
|
+
var nodeEntries = Editor.nodes(editor, {
|
|
37
|
+
match: function match(n) {
|
|
38
|
+
return Text.isText(n);
|
|
39
|
+
},
|
|
40
|
+
universal: true
|
|
41
|
+
});
|
|
42
|
+
var _iterator = _createForOfIteratorHelper(nodeEntries),
|
|
43
|
+
_step;
|
|
44
|
+
try {
|
|
45
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
46
|
+
var nodeEntry = _step.value;
|
|
47
|
+
// single text node
|
|
48
|
+
var n = nodeEntry[0];
|
|
49
|
+
removeMarks(editor, n);
|
|
50
|
+
}
|
|
51
|
+
} catch (err) {
|
|
52
|
+
_iterator.e(err);
|
|
53
|
+
} finally {
|
|
54
|
+
_iterator.f();
|
|
55
|
+
}
|
|
56
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
2
|
+
import React, { useCallback } from 'react';
|
|
3
|
+
import { CLEAR_FORMAT, MENUS_CONFIG_MAP } from '../../../constants';
|
|
4
|
+
import { MenuItem } from '../../../menu';
|
|
5
|
+
import { isMenuDisabled, clearStyles } from '../helpers';
|
|
6
|
+
var menuConfig = MENUS_CONFIG_MAP[CLEAR_FORMAT];
|
|
7
|
+
var ClearFormatMenu = function ClearFormatMenu(_ref) {
|
|
8
|
+
var isRichEditor = _ref.isRichEditor,
|
|
9
|
+
className = _ref.className,
|
|
10
|
+
editor = _ref.editor;
|
|
11
|
+
var onMouseDown = useCallback(function () {
|
|
12
|
+
clearStyles(editor);
|
|
13
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
14
|
+
}, []);
|
|
15
|
+
var props = _objectSpread(_objectSpread({
|
|
16
|
+
isRichEditor: isRichEditor,
|
|
17
|
+
className: className
|
|
18
|
+
}, menuConfig), {}, {
|
|
19
|
+
disabled: isMenuDisabled(editor),
|
|
20
|
+
isActive: false,
|
|
21
|
+
'onMouseDown': onMouseDown
|
|
22
|
+
});
|
|
23
|
+
return /*#__PURE__*/React.createElement(MenuItem, props);
|
|
24
|
+
};
|
|
25
|
+
export default ClearFormatMenu;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
2
2
|
import React, { useCallback, useEffect, useState } from 'react';
|
|
3
|
-
import { createPortal } from 'react-dom';
|
|
4
3
|
import { withTranslation } from 'react-i18next';
|
|
5
|
-
import
|
|
4
|
+
import ElementPopover from '../../../commons/element-popover';
|
|
5
|
+
import { genCodeLangs } from '../prismjs';
|
|
6
6
|
import './index.css';
|
|
7
7
|
var CodeBlockHoverMenu = function CodeBlockHoverMenu(_ref) {
|
|
8
8
|
var style = _ref.style,
|
|
@@ -68,7 +68,7 @@ var CodeBlockHoverMenu = function CodeBlockHoverMenu(_ref) {
|
|
|
68
68
|
}).text;
|
|
69
69
|
setSelectedLanguageText(selectedLanguageText);
|
|
70
70
|
}, [language]);
|
|
71
|
-
return /*#__PURE__*/React.createElement(
|
|
71
|
+
return /*#__PURE__*/React.createElement(ElementPopover, null, /*#__PURE__*/React.createElement("div", {
|
|
72
72
|
className: "sdoc-code-block-hover-menu-container",
|
|
73
73
|
style: menuPosition
|
|
74
74
|
}, /*#__PURE__*/React.createElement("div", {
|
|
@@ -110,6 +110,6 @@ var CodeBlockHoverMenu = function CodeBlockHoverMenu(_ref) {
|
|
|
110
110
|
}, /*#__PURE__*/React.createElement("i", {
|
|
111
111
|
className: "sdocfont sdoc-check-square icon-font"
|
|
112
112
|
})), item.text);
|
|
113
|
-
}))))))
|
|
113
|
+
}))))));
|
|
114
114
|
};
|
|
115
115
|
export default withTranslation('sdoc-editor')(CodeBlockHoverMenu);
|
|
@@ -4,7 +4,7 @@ import React, { useCallback, useEffect, useState, useRef } from 'react';
|
|
|
4
4
|
import { ReactEditor, useSlateStatic, useReadOnly } from '@seafile/slate-react';
|
|
5
5
|
import { Transforms } from '@seafile/slate';
|
|
6
6
|
import { useScrollContext } from '../../../hooks/use-scroll-context';
|
|
7
|
-
import CodeBlockHoverMenu from '
|
|
7
|
+
import CodeBlockHoverMenu from './hover-menu';
|
|
8
8
|
import { setClipboardData } from './helpers';
|
|
9
9
|
import '../../../assets/css/code-block.css';
|
|
10
10
|
var CodeBlock = function CodeBlock(_ref) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import slugid from 'slugid';
|
|
2
2
|
import { CODE_BLOCK, CODE_LINE } from '../../../constants';
|
|
3
|
-
import { genCodeLangs } from '
|
|
3
|
+
import { genCodeLangs } from '../../code-block/prismjs';
|
|
4
4
|
var codeBlockRule = function codeBlockRule(element, parseChild) {
|
|
5
5
|
var nodeName = element.nodeName,
|
|
6
6
|
childNodes = element.childNodes;
|
|
@@ -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);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { TABLE } from '../../constants';
|
|
2
|
-
import { TableMenu
|
|
2
|
+
import { TableMenu } from './menu';
|
|
3
3
|
import Table from './model';
|
|
4
4
|
import withTable from './plugin';
|
|
5
5
|
import { renderTable, renderTableRow, renderTableCell } from './render-elem';
|
|
@@ -9,7 +9,6 @@ var TablePlugin = {
|
|
|
9
9
|
model: Table,
|
|
10
10
|
editorMenus: [TableMenu],
|
|
11
11
|
editorPlugin: withTable,
|
|
12
|
-
renderElements: [renderTable, renderTableRow, renderTableCell]
|
|
13
|
-
contextMenu: ContextMenu
|
|
12
|
+
renderElements: [renderTable, renderTableRow, renderTableCell]
|
|
14
13
|
};
|
|
15
14
|
export default TablePlugin;
|
|
@@ -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,4 +1,20 @@
|
|
|
1
|
-
.sdoc-table-menu-group .sdoc-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
.sdoc-table-menu-group.menu-group .menu-group-item:not(.sdoc-remove-table) {
|
|
2
|
+
width: 36px;
|
|
3
|
+
}
|
|
4
|
+
|
|
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;
|
|
4
20
|
}
|
|
@@ -6,12 +6,13 @@ import _inherits from "@babel/runtime/helpers/esm/inherits";
|
|
|
6
6
|
import _createSuper from "@babel/runtime/helpers/esm/createSuper";
|
|
7
7
|
import React, { Component } from 'react';
|
|
8
8
|
import { withTranslation } from 'react-i18next';
|
|
9
|
+
import classnames from 'classnames';
|
|
9
10
|
import { MenuGroup, MenuItem } from '../../../../menu';
|
|
10
11
|
import CommonMenu from './common-menu';
|
|
11
12
|
import { MENUS_CONFIG_MAP, REMOVE_TABLE, BG_COLOR } from '../../../../constants';
|
|
12
13
|
import { setCellStyle, insertTableElement, removeTableElement, isAllInTable } from '../../helpers';
|
|
13
14
|
import { TABLE_ELEMENT } from '../../constants';
|
|
14
|
-
import ColorMenu from '
|
|
15
|
+
import ColorMenu from '../../../../menu/color-menu';
|
|
15
16
|
import './index.css';
|
|
16
17
|
var ActiveTableMenu = /*#__PURE__*/function (_Component) {
|
|
17
18
|
_inherits(ActiveTableMenu, _Component);
|
|
@@ -56,7 +57,7 @@ var ActiveTableMenu = /*#__PURE__*/function (_Component) {
|
|
|
56
57
|
var t = _this.props.t;
|
|
57
58
|
return /*#__PURE__*/React.createElement(CommonMenu, {
|
|
58
59
|
id: "text-align",
|
|
59
|
-
iconClass: "sdocfont sdoc-align-left
|
|
60
|
+
iconClass: "sdocfont sdoc-align-left",
|
|
60
61
|
ref: function ref(_ref) {
|
|
61
62
|
return _this.textAlignRef = _ref;
|
|
62
63
|
}
|
|
@@ -81,7 +82,7 @@ var ActiveTableMenu = /*#__PURE__*/function (_Component) {
|
|
|
81
82
|
var t = _this.props.t;
|
|
82
83
|
return /*#__PURE__*/React.createElement(CommonMenu, {
|
|
83
84
|
id: "table-column",
|
|
84
|
-
iconClass: "sdocfont sdoc-column
|
|
85
|
+
iconClass: "sdocfont sdoc-column",
|
|
85
86
|
ref: function ref(_ref2) {
|
|
86
87
|
return _this.tableColumnRef = _ref2;
|
|
87
88
|
}
|
|
@@ -97,7 +98,7 @@ var ActiveTableMenu = /*#__PURE__*/function (_Component) {
|
|
|
97
98
|
var t = _this.props.t;
|
|
98
99
|
return /*#__PURE__*/React.createElement(CommonMenu, {
|
|
99
100
|
id: "table-row",
|
|
100
|
-
iconClass: "sdocfont sdoc-row
|
|
101
|
+
iconClass: "sdocfont sdoc-row",
|
|
101
102
|
ref: function ref(_ref3) {
|
|
102
103
|
return _this.tableRowRef = _ref3;
|
|
103
104
|
}
|
|
@@ -116,7 +117,7 @@ var ActiveTableMenu = /*#__PURE__*/function (_Component) {
|
|
|
116
117
|
var menuConfig = MENUS_CONFIG_MAP[REMOVE_TABLE];
|
|
117
118
|
var props = _objectSpread(_objectSpread({
|
|
118
119
|
isRichEditor: isRichEditor,
|
|
119
|
-
className: className,
|
|
120
|
+
className: classnames(className, 'sdoc-remove-table menu-group-item'),
|
|
120
121
|
disabled: false,
|
|
121
122
|
isActive: false
|
|
122
123
|
}, menuConfig), {}, {
|
|
@@ -143,7 +144,9 @@ var ActiveTableMenu = /*#__PURE__*/function (_Component) {
|
|
|
143
144
|
}, menuConfig), {}, {
|
|
144
145
|
onMouseDown: function onMouseDown() {},
|
|
145
146
|
setColor: _this.setColor,
|
|
146
|
-
|
|
147
|
+
recentUsedColorsKey: 'sdoc-recent-used-bg-colors',
|
|
148
|
+
lastUsedColorKey: 'sdoc-last-used-bg-colors',
|
|
149
|
+
popoverClassName: 'sdoc-table-cell-bg-colors-popover'
|
|
147
150
|
});
|
|
148
151
|
return /*#__PURE__*/React.createElement(ColorMenu, props);
|
|
149
152
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import TableMenu from './table-menu';
|
|
2
2
|
import ActiveTableMenu from './active-table-menu';
|
|
3
|
-
import
|
|
4
|
-
export { TableMenu, ActiveTableMenu,
|
|
3
|
+
import TableContextMenu from './table-context-menu';
|
|
4
|
+
export { TableMenu, ActiveTableMenu, TableContextMenu };
|
package/dist/basic-sdk/extension/plugins/table/menu/{context-menu → table-context-menu}/index.js
RENAMED
|
@@ -6,18 +6,19 @@ 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/element-popover';
|
|
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 InsertTableElement from './insert-table-element';
|
|
14
15
|
import './index.css';
|
|
15
|
-
var
|
|
16
|
-
_inherits(
|
|
17
|
-
var _super = _createSuper(
|
|
18
|
-
function
|
|
16
|
+
var TableContextMenu = /*#__PURE__*/function (_React$Component) {
|
|
17
|
+
_inherits(TableContextMenu, _React$Component);
|
|
18
|
+
var _super = _createSuper(TableContextMenu);
|
|
19
|
+
function TableContextMenu(props) {
|
|
19
20
|
var _this;
|
|
20
|
-
_classCallCheck(this,
|
|
21
|
+
_classCallCheck(this, TableContextMenu);
|
|
21
22
|
_this = _super.call(this, props);
|
|
22
23
|
_this.updateMenuPosition = function () {
|
|
23
24
|
var menuHeight = _this.menu.offsetHeight;
|
|
@@ -61,7 +62,7 @@ var ContextMenu = /*#__PURE__*/function (_React$Component) {
|
|
|
61
62
|
_this.position = null;
|
|
62
63
|
return _this;
|
|
63
64
|
}
|
|
64
|
-
_createClass(
|
|
65
|
+
_createClass(TableContextMenu, [{
|
|
65
66
|
key: "componentDidMount",
|
|
66
67
|
value: function componentDidMount() {
|
|
67
68
|
this.position = this.props.contextMenuPosition;
|
|
@@ -88,6 +89,7 @@ var ContextMenu = /*#__PURE__*/function (_React$Component) {
|
|
|
88
89
|
var contextStyle = this.state.contextStyle;
|
|
89
90
|
var editor = this.props.editor;
|
|
90
91
|
var currentTable = getSelectedNodeByType(editor, ELEMENT_TYPE.TABLE);
|
|
92
|
+
if (!currentTable) return null;
|
|
91
93
|
var currentRow = getSelectedNodeByType(editor, ELEMENT_TYPE.TABLE_ROW);
|
|
92
94
|
var currentRowsCount = currentTable.children.length;
|
|
93
95
|
var currentColumnsCount = currentRow.children.length;
|
|
@@ -96,7 +98,9 @@ var ContextMenu = /*#__PURE__*/function (_React$Component) {
|
|
|
96
98
|
var selectedCols = tableSelectedRange.maxColIndex - tableSelectedRange.minColIndex + 1;
|
|
97
99
|
var canAddRowsCount = currentRowsCount + selectedRows > TABLE_MAX_ROWS ? TABLE_MAX_ROWS - currentRowsCount : selectedRows;
|
|
98
100
|
var canAddColsCount = currentColumnsCount + selectedCols > TABLE_MAX_COLUMNS ? TABLE_MAX_COLUMNS - currentColumnsCount : selectedCols;
|
|
99
|
-
return /*#__PURE__*/React.createElement(
|
|
101
|
+
return /*#__PURE__*/React.createElement(ElementPopover, {
|
|
102
|
+
className: "sdoc-context-menu"
|
|
103
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
100
104
|
style: contextStyle,
|
|
101
105
|
ref: function ref(_ref) {
|
|
102
106
|
return _this2.menu = _ref;
|
|
@@ -128,9 +132,9 @@ var ContextMenu = /*#__PURE__*/function (_React$Component) {
|
|
|
128
132
|
insertTableElement: this.insertTableElement
|
|
129
133
|
}), /*#__PURE__*/React.createElement("div", {
|
|
130
134
|
className: 'seafile-divider dropdown-divider'
|
|
131
|
-
}), this.renderRemoveBtn(TABLE_ELEMENT.ROW, 'Delete_row'), this.renderRemoveBtn(TABLE_ELEMENT.COLUMN, 'Delete_column'), this.renderRemoveBtn(TABLE_ELEMENT.TABLE, 'Delete_table'));
|
|
135
|
+
}), this.renderRemoveBtn(TABLE_ELEMENT.ROW, 'Delete_row'), this.renderRemoveBtn(TABLE_ELEMENT.COLUMN, 'Delete_column'), this.renderRemoveBtn(TABLE_ELEMENT.TABLE, 'Delete_table')));
|
|
132
136
|
}
|
|
133
137
|
}]);
|
|
134
|
-
return
|
|
138
|
+
return TableContextMenu;
|
|
135
139
|
}(React.Component);
|
|
136
|
-
export default withTranslation('sdoc-editor')(
|
|
140
|
+
export default withTranslation('sdoc-editor')(TableContextMenu);
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
2
|
+
import { createContext, useCallback, useContext, useEffect, useState } from 'react';
|
|
3
|
+
import { useScrollContext } from '../../../../hooks/use-scroll-context';
|
|
2
4
|
export var TableRootContext = createContext();
|
|
3
5
|
export var useTableRootContext = function useTableRootContext() {
|
|
4
6
|
return useContext(TableRootContext);
|
|
@@ -18,4 +20,52 @@ export var useSettingSelectRangeContext = function useSettingSelectRangeContext(
|
|
|
18
20
|
export var TableRootScrollLeftContext = createContext();
|
|
19
21
|
export var useTableRootScrollLeftContext = function useTableRootScrollLeftContext() {
|
|
20
22
|
return useContext(TableRootScrollLeftContext);
|
|
23
|
+
};
|
|
24
|
+
export var useContextMenu = function useContextMenu(tableScrollWrapper) {
|
|
25
|
+
var scrollRef = useScrollContext();
|
|
26
|
+
var _useState = useState(),
|
|
27
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
28
|
+
isShowContextMenu = _useState2[0],
|
|
29
|
+
setShowContextMenu = _useState2[1];
|
|
30
|
+
var _useState3 = useState({}),
|
|
31
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
32
|
+
menuPosition = _useState4[0],
|
|
33
|
+
setMenuPosition = _useState4[1];
|
|
34
|
+
var onContextMenu = useCallback(function (event) {
|
|
35
|
+
event.preventDefault();
|
|
36
|
+
var menuPosition = {
|
|
37
|
+
left: event.clientX,
|
|
38
|
+
top: event.clientY
|
|
39
|
+
};
|
|
40
|
+
setShowContextMenu(true);
|
|
41
|
+
setMenuPosition(menuPosition);
|
|
42
|
+
}, []);
|
|
43
|
+
var hideContextMenu = useCallback(function (e) {
|
|
44
|
+
if (isShowContextMenu) {
|
|
45
|
+
setShowContextMenu(false);
|
|
46
|
+
}
|
|
47
|
+
}, [isShowContextMenu]);
|
|
48
|
+
var hideByContextmenuEvent = useCallback(function (e) {
|
|
49
|
+
var table = tableScrollWrapper.current;
|
|
50
|
+
var clickIsInCurrentTable = table && table.contains(e.target) && table !== e.target;
|
|
51
|
+
if (!clickIsInCurrentTable) {
|
|
52
|
+
setShowContextMenu(false);
|
|
53
|
+
}
|
|
54
|
+
}, [tableScrollWrapper]);
|
|
55
|
+
useEffect(function () {
|
|
56
|
+
document.addEventListener('mousedown', hideContextMenu);
|
|
57
|
+
document.addEventListener('contextmenu', hideByContextmenuEvent, true);
|
|
58
|
+
scrollRef.current && scrollRef.current.addEventListener('scroll', hideContextMenu);
|
|
59
|
+
return function () {
|
|
60
|
+
document.removeEventListener('mousedown', hideContextMenu);
|
|
61
|
+
document.removeEventListener('contextmenu', hideByContextmenuEvent, true);
|
|
62
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
63
|
+
scrollRef.current && scrollRef.current.removeEventListener('scroll', hideContextMenu);
|
|
64
|
+
};
|
|
65
|
+
}, [hideContextMenu, hideByContextmenuEvent, scrollRef]);
|
|
66
|
+
return {
|
|
67
|
+
isShowContextMenu: isShowContextMenu,
|
|
68
|
+
menuPosition: menuPosition,
|
|
69
|
+
onContextMenu: onContextMenu
|
|
70
|
+
};
|
|
21
71
|
};
|
|
@@ -65,43 +65,9 @@
|
|
|
65
65
|
|
|
66
66
|
.sdoc-table-wrapper .cell-selected {
|
|
67
67
|
caret-color: transparent;
|
|
68
|
-
background-color: #fff4e6;
|
|
69
68
|
position: relative;
|
|
70
69
|
}
|
|
71
70
|
|
|
72
|
-
.sdoc-table-wrapper .cell-light-height-top-border::before {
|
|
73
|
-
content: '';
|
|
74
|
-
position: absolute;
|
|
75
|
-
top: -1px;
|
|
76
|
-
left: 0;
|
|
77
|
-
width: calc(100% + 1px);
|
|
78
|
-
height: 2px;
|
|
79
|
-
border-top: 1px double #ffa94d !important;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
.sdoc-table-wrapper .cell-light-height-top-border:first-child:before {
|
|
83
|
-
left: -1px;
|
|
84
|
-
width: calc(100% + 2px);
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
.sdoc-table-wrapper .cell-light-height-bottom-border {
|
|
88
|
-
border-bottom: 1px double #ffa94d !important;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
.sdoc-table-wrapper .cell-light-height-left-border::after {
|
|
92
|
-
content: '';
|
|
93
|
-
position: absolute;
|
|
94
|
-
top: 0px;
|
|
95
|
-
left: -1px;
|
|
96
|
-
width: 2px;
|
|
97
|
-
height: calc(100% + 1px);
|
|
98
|
-
border-left: 1px double #ffa94d !important;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
.sdoc-table-wrapper .cell-light-height-right-border {
|
|
102
|
-
border-right: 1px double #ffa94d !important;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
71
|
.sdoc-table-wrapper .table-row-height-just {
|
|
106
72
|
width: 100%;
|
|
107
73
|
height: 5px;
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
2
|
-
import React from 'react';
|
|
2
|
+
import React, { useCallback } from 'react';
|
|
3
3
|
import classnames from 'classnames';
|
|
4
4
|
import { useSlateStatic, useReadOnly } from '@seafile/slate-react';
|
|
5
|
+
import { Transforms } from '@seafile/slate';
|
|
5
6
|
import ObjectUtils from '../../../../utils/object-utils';
|
|
6
7
|
import { STYLE_KEY } from '../../../constants';
|
|
7
|
-
import { findPath } from '../../../core';
|
|
8
|
+
import { findPath, focusEditor } from '../../../core';
|
|
8
9
|
import { useResizeHandlersContext, useTableSelectedRangeContext } from './hooks';
|
|
9
|
-
import { EMPTY_SELECTED_RANGE } from '../constants';
|
|
10
|
+
import { EMPTY_SELECTED_RANGE, SELECTED_TABLE_CELL_BG_COLOR } from '../constants';
|
|
10
11
|
import { getTableColumns, getCellColumn, colorBlend } from '../helpers';
|
|
11
12
|
var TableCell = function TableCell(_ref) {
|
|
12
13
|
var attributes = _ref.attributes,
|
|
@@ -31,14 +32,24 @@ var TableCell = function TableCell(_ref) {
|
|
|
31
32
|
var isSelectedLastCell = isSelected && cellIndex === maxColIndex;
|
|
32
33
|
var isSelectedFirstRow = isSelected && rowIndex === minRowIndex;
|
|
33
34
|
var isSelectedLastRow = isSelected && rowIndex === maxRowIndex;
|
|
35
|
+
var onContextMenu = useCallback(function (event) {
|
|
36
|
+
var path = findPath(editor, element);
|
|
37
|
+
focusEditor(editor, path);
|
|
38
|
+
Transforms.collapse(editor, {
|
|
39
|
+
edge: 'end'
|
|
40
|
+
});
|
|
41
|
+
}, [editor, element]);
|
|
34
42
|
var style = attributes.style || {};
|
|
35
43
|
if (ObjectUtils.hasProperty(element.style, STYLE_KEY.TEXT_ALIGN)) {
|
|
36
44
|
style[STYLE_KEY.TEXT_ALIGN] = element.style[STYLE_KEY.TEXT_ALIGN];
|
|
37
45
|
}
|
|
46
|
+
if (isSelected) {
|
|
47
|
+
style['backgroundColor'] = SELECTED_TABLE_CELL_BG_COLOR;
|
|
48
|
+
}
|
|
38
49
|
if (ObjectUtils.hasProperty(element.style, STYLE_KEY.BG_COLOR)) {
|
|
39
50
|
var color = element.style[STYLE_KEY.BG_COLOR];
|
|
40
|
-
if (color &&
|
|
41
|
-
style['backgroundColor'] = isSelected ? colorBlend(
|
|
51
|
+
if (color && color !== 'transparent' && color !== 'unset') {
|
|
52
|
+
style['backgroundColor'] = isSelected ? colorBlend(SELECTED_TABLE_CELL_BG_COLOR, color, 0.9) : color;
|
|
42
53
|
}
|
|
43
54
|
}
|
|
44
55
|
return /*#__PURE__*/React.createElement("div", Object.assign({}, attributes, {
|
|
@@ -55,7 +66,8 @@ var TableCell = function TableCell(_ref) {
|
|
|
55
66
|
}),
|
|
56
67
|
"data-id": element.id,
|
|
57
68
|
"row-index": rowIndex,
|
|
58
|
-
"cell-index": cellIndex
|
|
69
|
+
"cell-index": cellIndex,
|
|
70
|
+
onContextMenu: onContextMenu
|
|
59
71
|
}), children);
|
|
60
72
|
};
|
|
61
73
|
function renderTableCell(props) {
|
|
@@ -76,7 +88,7 @@ function renderTableCell(props) {
|
|
|
76
88
|
if (ObjectUtils.hasProperty(element, STYLE_KEY.TEXT_ALIGN)) {
|
|
77
89
|
style[STYLE_KEY.TEXT_ALIGN] = element[STYLE_KEY.TEXT_ALIGN];
|
|
78
90
|
}
|
|
79
|
-
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]) {
|
|
80
92
|
style['backgroundColor'] = element.style[STYLE_KEY.BG_COLOR];
|
|
81
93
|
}
|
|
82
94
|
var column = getCellColumn(editor, element);
|
|
@@ -3,7 +3,8 @@ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
|
3
3
|
import React, { useState, useRef, useCallback } from 'react';
|
|
4
4
|
import classnames from 'classnames';
|
|
5
5
|
import { useSlateStatic } from '@seafile/slate-react';
|
|
6
|
-
import { TableRootContext, TableRootScrollLeftContext } from './hooks';
|
|
6
|
+
import { TableRootContext, TableRootScrollLeftContext, useContextMenu } from './hooks';
|
|
7
|
+
import { TableContextMenu } from '../menu';
|
|
7
8
|
var TableRoot = function TableRoot(_ref) {
|
|
8
9
|
var attributes = _ref.attributes,
|
|
9
10
|
_ref$columns = _ref.columns,
|
|
@@ -21,6 +22,10 @@ var TableRoot = function TableRoot(_ref) {
|
|
|
21
22
|
var onScroll = useCallback(function (event) {
|
|
22
23
|
setScrollLeft(event.target.scrollLeft);
|
|
23
24
|
}, []);
|
|
25
|
+
var _useContextMenu = useContextMenu(tableScrollWrapper),
|
|
26
|
+
isShowContextMenu = _useContextMenu.isShowContextMenu,
|
|
27
|
+
menuPosition = _useContextMenu.menuPosition,
|
|
28
|
+
onContextMenu = _useContextMenu.onContextMenu;
|
|
24
29
|
return /*#__PURE__*/React.createElement(TableRootContext.Provider, {
|
|
25
30
|
value: tableScrollWrapper.current
|
|
26
31
|
}, /*#__PURE__*/React.createElement(TableRootScrollLeftContext.Provider, {
|
|
@@ -39,7 +44,11 @@ var TableRoot = function TableRoot(_ref) {
|
|
|
39
44
|
'scroll-at-left': scrollLeft === 0
|
|
40
45
|
}),
|
|
41
46
|
ref: tableScrollWrapper,
|
|
42
|
-
onScroll: onScroll
|
|
43
|
-
|
|
47
|
+
onScroll: onScroll,
|
|
48
|
+
onContextMenu: onContextMenu
|
|
49
|
+
}, children)), isShowContextMenu && /*#__PURE__*/React.createElement(TableContextMenu, {
|
|
50
|
+
editor: editor,
|
|
51
|
+
contextMenuPosition: menuPosition
|
|
52
|
+
})));
|
|
44
53
|
};
|
|
45
54
|
export default TableRoot;
|