@seafile/sdoc-editor 0.1.39 → 0.1.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.
- package/dist/basic-sdk/assets/css/outline.css +1 -1
- package/dist/basic-sdk/extension/constants/element-type.js +1 -1
- package/dist/basic-sdk/extension/constants/index.js +26 -1
- package/dist/basic-sdk/extension/constants/keyboard.js +7 -0
- package/dist/basic-sdk/extension/core/queries/index.js +23 -0
- package/dist/basic-sdk/extension/menu/menu-item.js +7 -8
- package/dist/basic-sdk/extension/plugins/blockquote/menu/index.js +1 -1
- package/dist/basic-sdk/extension/plugins/blockquote/plugin.js +19 -2
- package/dist/basic-sdk/extension/plugins/check-list/helpers.js +7 -2
- package/dist/basic-sdk/extension/plugins/header/helpers.js +11 -5
- package/dist/basic-sdk/extension/plugins/header/menu/index.js +7 -3
- package/dist/basic-sdk/extension/plugins/header/menu/style.css +5 -1
- package/dist/basic-sdk/extension/plugins/image/helpers.js +9 -2
- package/dist/basic-sdk/extension/plugins/index.js +3 -2
- package/dist/basic-sdk/extension/plugins/table/dialog/custom-table-size-dialog/index.css +7 -0
- package/dist/basic-sdk/extension/plugins/table/dialog/custom-table-size-dialog/index.js +90 -0
- package/dist/basic-sdk/extension/plugins/table/helpers.js +81 -0
- package/dist/basic-sdk/extension/plugins/table/index.js +14 -0
- package/dist/basic-sdk/extension/plugins/table/menu/active-table-menu/common-menu.js +78 -0
- package/dist/basic-sdk/extension/plugins/table/menu/active-table-menu/index.css +7 -0
- package/dist/basic-sdk/extension/plugins/table/menu/active-table-menu/index.js +136 -0
- package/dist/basic-sdk/extension/plugins/table/menu/index.js +3 -0
- package/dist/basic-sdk/extension/plugins/table/menu/table-menu/index.js +60 -0
- package/dist/basic-sdk/extension/plugins/table/model.js +19 -0
- package/dist/basic-sdk/extension/plugins/table/number-input.js +28 -0
- package/dist/basic-sdk/extension/plugins/table/plugin.js +500 -0
- package/dist/basic-sdk/extension/plugins/table/popover/table-size-popover/index.css +57 -0
- package/dist/basic-sdk/extension/plugins/table/popover/table-size-popover/index.js +134 -0
- package/dist/basic-sdk/extension/plugins/table/render/render-cell.js +32 -0
- package/dist/basic-sdk/extension/plugins/table/render/render-row.js +24 -0
- package/dist/basic-sdk/extension/plugins/table/render/render-table/index.css +30 -0
- package/dist/basic-sdk/extension/plugins/table/render/render-table/index.js +41 -0
- package/dist/basic-sdk/extension/plugins/table/render-elem.js +4 -0
- package/dist/basic-sdk/extension/plugins/text-style/helpers.js +1 -6
- package/dist/basic-sdk/extension/render/render-element.js +20 -2
- package/dist/basic-sdk/extension/toolbar/index.js +6 -1
- package/dist/basic-sdk/node-id/helpers.js +1 -1
- package/dist/basic-sdk/utils/event-handler.js +6 -0
- package/dist/basic-sdk/utils/object-utils.js +3 -0
- package/package.json +1 -1
- package/public/locales/en/sdoc-editor.json +4 -1
- package/public/locales/zh-CN/sdoc-editor.json +5 -1
|
@@ -21,8 +21,8 @@ export var CODE_BLOCK = 'code-block';
|
|
|
21
21
|
export var CODE_LINE = 'code-line';
|
|
22
22
|
export var IMAGE = 'image';
|
|
23
23
|
export var TABLE = 'table';
|
|
24
|
-
export var TABLE_CELL = 'table-cell';
|
|
25
24
|
export var TABLE_ROW = 'table-row';
|
|
25
|
+
export var TABLE_CELL = 'table-cell';
|
|
26
26
|
export var FORMULA = 'formula';
|
|
27
27
|
export var COLUMN = 'column';
|
|
28
28
|
export var TEXT_STYLE = 'text-style';
|
|
@@ -3,11 +3,15 @@ var _MENUS_CONFIG_MAP, _HEADER_TITLE_MAP;
|
|
|
3
3
|
// extension plugin
|
|
4
4
|
import * as ELEMENT_TYPE from './element-type';
|
|
5
5
|
import { BLOCKQUOTE, BOLD, ITALIC, HEADER, HEADER1, HEADER2, HEADER3, HEADER4, HEADER5, HEADER6, ORDERED_LIST, UNORDERED_LIST, LIST_ITEM, LIST_LIC, CHECK_LIST, CHECK_LIST_ITEM, PARAGRAPH, LINK, HTML, CODE_BLOCK, CODE_LINE, IMAGE, TABLE, TABLE_CELL, TABLE_ROW, FORMULA, COLUMN, TEXT_STYLE, BOLD_ITALIC } from './element-type';
|
|
6
|
+
import KEYBOARD from './keyboard';
|
|
6
7
|
|
|
7
8
|
// history
|
|
8
9
|
export var UNDO = 'undo';
|
|
9
10
|
export var REDO = 'redo';
|
|
10
11
|
|
|
12
|
+
// remove
|
|
13
|
+
export var REMOVE_TABLE = 'remove_table';
|
|
14
|
+
|
|
11
15
|
// menus config
|
|
12
16
|
export var MENUS_CONFIG_MAP = (_MENUS_CONFIG_MAP = {}, _defineProperty(_MENUS_CONFIG_MAP, BLOCKQUOTE, {
|
|
13
17
|
id: "sdoc_".concat(BLOCKQUOTE),
|
|
@@ -37,6 +41,14 @@ export var MENUS_CONFIG_MAP = (_MENUS_CONFIG_MAP = {}, _defineProperty(_MENUS_CO
|
|
|
37
41
|
id: "sdoc_".concat(IMAGE),
|
|
38
42
|
iconClass: 'iconfont icon-image',
|
|
39
43
|
text: 'insert_image'
|
|
44
|
+
}), _defineProperty(_MENUS_CONFIG_MAP, TABLE, {
|
|
45
|
+
id: "sdoc_".concat(TABLE),
|
|
46
|
+
iconClass: 'iconfont icon-table',
|
|
47
|
+
text: 'insert_table'
|
|
48
|
+
}), _defineProperty(_MENUS_CONFIG_MAP, REMOVE_TABLE, {
|
|
49
|
+
id: "sdoc_".concat(REMOVE_TABLE),
|
|
50
|
+
iconClass: 'iconfont icon-delete-table',
|
|
51
|
+
text: 'remove_table'
|
|
40
52
|
}), _defineProperty(_MENUS_CONFIG_MAP, TEXT_STYLE, [{
|
|
41
53
|
id: ITALIC,
|
|
42
54
|
iconClass: 'iconfont icon-italic',
|
|
@@ -65,4 +77,17 @@ export var DIFF_TYPE = {
|
|
|
65
77
|
MODIFY: 'modify',
|
|
66
78
|
COMMON: 'common'
|
|
67
79
|
};
|
|
68
|
-
export
|
|
80
|
+
export var STYLE_KEY = {
|
|
81
|
+
TEXT_ALIGN: 'textAlign'
|
|
82
|
+
};
|
|
83
|
+
export var TABLE_ELEMENT = {
|
|
84
|
+
TABLE: 'table',
|
|
85
|
+
ROW: 'row',
|
|
86
|
+
COLUMN: 'column',
|
|
87
|
+
CELL: 'cell'
|
|
88
|
+
};
|
|
89
|
+
export var TABLE_ELEMENT_POSITION = {
|
|
90
|
+
AFTER: 'after',
|
|
91
|
+
BEFORE: 'before'
|
|
92
|
+
};
|
|
93
|
+
export { BLOCKQUOTE, BOLD, ITALIC, HEADER, HEADER1, HEADER2, HEADER3, HEADER4, HEADER5, HEADER6, ORDERED_LIST, UNORDERED_LIST, LIST_ITEM, LIST_LIC, CHECK_LIST, CHECK_LIST_ITEM, PARAGRAPH, LINK, HTML, CODE_BLOCK, CODE_LINE, IMAGE, TABLE, TABLE_CELL, TABLE_ROW, FORMULA, COLUMN, TEXT_STYLE, BOLD_ITALIC, ELEMENT_TYPE, KEYBOARD };
|
|
@@ -6,6 +6,7 @@ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
|
6
6
|
var _excluded = ["at"];
|
|
7
7
|
import { Editor, Text, Path, Span, Element, Node, Range } from '@seafile/slate';
|
|
8
8
|
import { match } from '../utils';
|
|
9
|
+
import ObjectUtils from '../../../utils/object-utils';
|
|
9
10
|
|
|
10
11
|
// options
|
|
11
12
|
export var getQueryOptions = function getQueryOptions(editor, options) {
|
|
@@ -35,6 +36,28 @@ export var getNode = function getNode(editor, path) {
|
|
|
35
36
|
export var getNodeType = function getNodeType(node) {
|
|
36
37
|
return Element.isElement(node) ? node.type : '';
|
|
37
38
|
};
|
|
39
|
+
export var isTextNode = function isTextNode(node) {
|
|
40
|
+
if (!node) return false;
|
|
41
|
+
if (!ObjectUtils.hasProperty(node, 'children') && ObjectUtils.hasProperty(node, 'text')) return true;
|
|
42
|
+
};
|
|
43
|
+
export var getParentNode = function getParentNode(nodes, nodeId) {
|
|
44
|
+
var parentNode;
|
|
45
|
+
for (var i = 0; i < nodes.length; i++) {
|
|
46
|
+
var node = nodes[i];
|
|
47
|
+
var childrenNodes = node.children;
|
|
48
|
+
if (!Array.isArray(childrenNodes)) continue;
|
|
49
|
+
if (childrenNodes.find(function (node) {
|
|
50
|
+
return node.id === nodeId;
|
|
51
|
+
})) {
|
|
52
|
+
parentNode = node;
|
|
53
|
+
} else {
|
|
54
|
+
parentNode = getParentNode(childrenNodes, nodeId);
|
|
55
|
+
}
|
|
56
|
+
if (!parentNode) continue;
|
|
57
|
+
break;
|
|
58
|
+
}
|
|
59
|
+
return parentNode;
|
|
60
|
+
};
|
|
38
61
|
export var getNodes = function getNodes(node, options) {
|
|
39
62
|
return Node.nodes(node, options);
|
|
40
63
|
};
|
|
@@ -16,9 +16,9 @@ var MenuItem = /*#__PURE__*/function (_React$Component) {
|
|
|
16
16
|
if (_this.props.disabled) return;
|
|
17
17
|
_this.props.onMouseDown(event, _this.props.type);
|
|
18
18
|
};
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}
|
|
19
|
+
// onClick = (event) => {
|
|
20
|
+
// event.stopPropagation();
|
|
21
|
+
// }
|
|
22
22
|
_this.toggle = function () {
|
|
23
23
|
_this.setState({
|
|
24
24
|
isShowToolTip: !_this.state.isShowToolTip
|
|
@@ -55,17 +55,16 @@ var MenuItem = /*#__PURE__*/function (_React$Component) {
|
|
|
55
55
|
show: 0,
|
|
56
56
|
hide: 0
|
|
57
57
|
};
|
|
58
|
-
return /*#__PURE__*/React.createElement("button", {
|
|
58
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("button", {
|
|
59
|
+
id: id,
|
|
59
60
|
type: "button",
|
|
60
61
|
className: className,
|
|
61
62
|
disabled: disabled,
|
|
62
63
|
"data-active": isActive,
|
|
63
|
-
onClick: this.
|
|
64
|
-
onMouseDown: this.onMouseDown
|
|
64
|
+
onClick: this.onMouseDown
|
|
65
65
|
}, /*#__PURE__*/React.createElement("i", {
|
|
66
|
-
id: id,
|
|
67
66
|
className: iconClass
|
|
68
|
-
}), /*#__PURE__*/React.createElement(Tooltip, {
|
|
67
|
+
})), /*#__PURE__*/React.createElement(Tooltip, {
|
|
69
68
|
target: id,
|
|
70
69
|
isOpen: isShowToolTip,
|
|
71
70
|
delay: delay,
|
|
@@ -25,7 +25,7 @@ var QuoteMenu = /*#__PURE__*/function (_React$Component) {
|
|
|
25
25
|
var editor = _this.props.editor;
|
|
26
26
|
return isMenuDisabled(editor);
|
|
27
27
|
};
|
|
28
|
-
_this.onMouseDown = function () {
|
|
28
|
+
_this.onMouseDown = function (e) {
|
|
29
29
|
var editor = _this.props.editor;
|
|
30
30
|
var active = _this.isActive(editor);
|
|
31
31
|
var newType = active ? PARAGRAPH : BLOCKQUOTE;
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
2
2
|
import { Editor, Element, Point, Transforms, Node } from '@seafile/slate';
|
|
3
3
|
import { ReactEditor } from '@seafile/slate-react';
|
|
4
|
-
import { generateEmptyElement } from '../../core';
|
|
4
|
+
import { generateEmptyElement, getSelectedNodeByType, isSelectionAtBlockStart } from '../../core';
|
|
5
5
|
import { BLOCKQUOTE, PARAGRAPH } from '../../constants';
|
|
6
|
+
import { setBlockQuoteType } from './helpers';
|
|
6
7
|
var withBlockquote = function withBlockquote(editor) {
|
|
7
8
|
var insertBreak = editor.insertBreak,
|
|
8
|
-
insertText = editor.insertText
|
|
9
|
+
insertText = editor.insertText,
|
|
10
|
+
deleteBackward = editor.deleteBackward;
|
|
9
11
|
var newEditor = editor;
|
|
10
12
|
newEditor.insertBreak = function () {
|
|
11
13
|
var selection = editor.selection;
|
|
@@ -41,6 +43,21 @@ var withBlockquote = function withBlockquote(editor) {
|
|
|
41
43
|
// In other cases, insert a newline
|
|
42
44
|
insertText('\n');
|
|
43
45
|
};
|
|
46
|
+
newEditor.deleteBackward = function (unit) {
|
|
47
|
+
var selection = newEditor.selection;
|
|
48
|
+
if (selection === null) {
|
|
49
|
+
deleteBackward(unit);
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
var node = getSelectedNodeByType(editor, BLOCKQUOTE);
|
|
53
|
+
if (node) {
|
|
54
|
+
if (isSelectionAtBlockStart(editor)) {
|
|
55
|
+
setBlockQuoteType(editor, PARAGRAPH);
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
deleteBackward(unit);
|
|
60
|
+
};
|
|
44
61
|
return newEditor;
|
|
45
62
|
};
|
|
46
63
|
export default withBlockquote;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
2
2
|
import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIteratorHelper";
|
|
3
3
|
import { Transforms, Editor, Element } from '@seafile/slate';
|
|
4
|
-
import { CHECK_LIST_ITEM, PARAGRAPH } from '../../constants';
|
|
4
|
+
import { CHECK_LIST_ITEM, PARAGRAPH, ELEMENT_TYPE } from '../../constants';
|
|
5
5
|
import { getSelectedNodeByType } from '../../core';
|
|
6
6
|
export var isMenuDisabled = function isMenuDisabled(editor) {
|
|
7
7
|
if (editor.selection == null) return true;
|
|
@@ -26,7 +26,12 @@ export var isMenuDisabled = function isMenuDisabled(editor) {
|
|
|
26
26
|
var notMatch = selectedElements.some(function (element) {
|
|
27
27
|
if (Editor.isVoid(editor, element) && Editor.isBlock(editor, element)) return true;
|
|
28
28
|
var type = element.type;
|
|
29
|
-
if (
|
|
29
|
+
if (type === ELEMENT_TYPE.CODE_LINE) return true;
|
|
30
|
+
if (type === ELEMENT_TYPE.CODE_BLOCK) return true;
|
|
31
|
+
if (type === ELEMENT_TYPE.LIST_ITEM) return true;
|
|
32
|
+
if (type === ELEMENT_TYPE.TABLE) return true;
|
|
33
|
+
if (type === ELEMENT_TYPE.TABLE_ROW) return true;
|
|
34
|
+
if (type === ELEMENT_TYPE.TABLE_CELL) return true;
|
|
30
35
|
return false;
|
|
31
36
|
});
|
|
32
37
|
if (notMatch) return true;
|
|
@@ -1,12 +1,19 @@
|
|
|
1
1
|
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
2
2
|
import { Editor, Transforms } from '@seafile/slate';
|
|
3
|
-
import { getNodeType } from '../../core';
|
|
3
|
+
import { getNodeType, isTextNode, getParentNode } from '../../core';
|
|
4
|
+
import { ELEMENT_TYPE } from '../../constants';
|
|
4
5
|
export var isMenuDisabled = function isMenuDisabled(editor) {
|
|
5
6
|
if (!editor.selection) return true;
|
|
6
7
|
var _Editor$nodes = Editor.nodes(editor, {
|
|
7
8
|
match: function match(n) {
|
|
8
9
|
var type = getNodeType(n);
|
|
9
|
-
if (
|
|
10
|
+
if (!type && isTextNode(n) && n.id) {
|
|
11
|
+
var parentNode = getParentNode(editor.children, n.id);
|
|
12
|
+
type = getNodeType(parentNode);
|
|
13
|
+
}
|
|
14
|
+
if (type === ELEMENT_TYPE.CODE_LINE) return true;
|
|
15
|
+
if (type === ELEMENT_TYPE.CODE_BLOCK) return true;
|
|
16
|
+
if (type === ELEMENT_TYPE.PARAGRAPH) return true;
|
|
10
17
|
if (type.startsWith('header')) return true;
|
|
11
18
|
return false;
|
|
12
19
|
},
|
|
@@ -14,9 +21,8 @@ export var isMenuDisabled = function isMenuDisabled(editor) {
|
|
|
14
21
|
mode: 'highest'
|
|
15
22
|
}),
|
|
16
23
|
_Editor$nodes2 = _slicedToArray(_Editor$nodes, 1),
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
return true;
|
|
24
|
+
match = _Editor$nodes2[0];
|
|
25
|
+
return !match;
|
|
20
26
|
};
|
|
21
27
|
export var getHeaderType = function getHeaderType(editor) {
|
|
22
28
|
var _Editor$nodes3 = Editor.nodes(editor, {
|
|
@@ -4,6 +4,7 @@ import _inherits from "@babel/runtime/helpers/esm/inherits";
|
|
|
4
4
|
import _createSuper from "@babel/runtime/helpers/esm/createSuper";
|
|
5
5
|
import React from 'react';
|
|
6
6
|
import { withTranslation } from 'react-i18next';
|
|
7
|
+
import classnames from 'classnames';
|
|
7
8
|
import { getHeaderType, isMenuDisabled, setHeaderType } from '../helpers';
|
|
8
9
|
import { HEADER1, HEADER2, HEADER3, HEADER4, HEADER5, HEADER6, HEADER_TITLE_MAP, PARAGRAPH } from '../../../constants';
|
|
9
10
|
import './style.css';
|
|
@@ -78,14 +79,17 @@ var HeaderMenu = /*#__PURE__*/function (_React$Component) {
|
|
|
78
79
|
var isShowHeaderPopover = this.state.isShowHeaderPopover;
|
|
79
80
|
var headerIconClass = "iconfont icon-".concat(isShowHeaderPopover ? 'caret-up' : 'drop-down');
|
|
80
81
|
var headerType = this.getValue();
|
|
82
|
+
var disabled = this.isDisabled();
|
|
81
83
|
return /*#__PURE__*/React.createElement("div", {
|
|
82
84
|
className: "header-menu"
|
|
83
85
|
}, /*#__PURE__*/React.createElement("div", {
|
|
84
|
-
className:
|
|
85
|
-
|
|
86
|
+
className: classnames('header-toggle', {
|
|
87
|
+
'header-toggle-disabled': disabled
|
|
88
|
+
}),
|
|
89
|
+
onClick: disabled ? function () {} : this.onToggleClick
|
|
86
90
|
}, /*#__PURE__*/React.createElement("span", {
|
|
87
91
|
className: "active"
|
|
88
|
-
}, t(HEADER_TITLE_MAP[headerType])), /*#__PURE__*/React.createElement("span", {
|
|
92
|
+
}, t(HEADER_TITLE_MAP[headerType])), !disabled && /*#__PURE__*/React.createElement("span", {
|
|
89
93
|
className: headerIconClass
|
|
90
94
|
})), isShowHeaderPopover && /*#__PURE__*/React.createElement("div", {
|
|
91
95
|
className: "header-popover"
|
|
@@ -16,7 +16,11 @@
|
|
|
16
16
|
padding-left: 5px;
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
.header-menu .header-toggle
|
|
19
|
+
.header-menu .header-toggle-disabled {
|
|
20
|
+
color: #999;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
.header-menu .header-toggle:not(.header-toggle-disabled):hover {
|
|
20
24
|
background: #e5e5e5;
|
|
21
25
|
border-radius: 2px;
|
|
22
26
|
}
|
|
@@ -2,8 +2,8 @@ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
|
2
2
|
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
3
3
|
import urlJoin from 'url-join';
|
|
4
4
|
import { Editor, Range, Transforms } from '@seafile/slate';
|
|
5
|
-
import { BLOCKQUOTE, CODE_BLOCK, IMAGE, ORDERED_LIST, UNORDERED_LIST } from '../../constants';
|
|
6
|
-
import { generateEmptyElement, getNodeType } from '../../core';
|
|
5
|
+
import { BLOCKQUOTE, CODE_BLOCK, IMAGE, ORDERED_LIST, UNORDERED_LIST, ELEMENT_TYPE } from '../../constants';
|
|
6
|
+
import { generateEmptyElement, getNodeType, isTextNode, getParentNode } from '../../core';
|
|
7
7
|
import context from '../../../../context';
|
|
8
8
|
export var isInsertImageMenuDisabled = function isInsertImageMenuDisabled(editor) {
|
|
9
9
|
var selection = editor.selection;
|
|
@@ -12,6 +12,13 @@ export var isInsertImageMenuDisabled = function isInsertImageMenuDisabled(editor
|
|
|
12
12
|
var _Editor$nodes = Editor.nodes(editor, {
|
|
13
13
|
match: function match(n) {
|
|
14
14
|
var type = getNodeType(n);
|
|
15
|
+
if (!type && isTextNode(n) && n.id) {
|
|
16
|
+
var parentNode = getParentNode(editor.children, n.id);
|
|
17
|
+
type = getNodeType(parentNode);
|
|
18
|
+
}
|
|
19
|
+
if (type === ELEMENT_TYPE.TABLE) return true;
|
|
20
|
+
if (type === ELEMENT_TYPE.TABLE_ROW) return true;
|
|
21
|
+
if (type === ELEMENT_TYPE.TABLE_CELL) return true;
|
|
15
22
|
if (type === CODE_BLOCK) return true;
|
|
16
23
|
if (type === ORDERED_LIST) return true;
|
|
17
24
|
if (type === UNORDERED_LIST) return true;
|
|
@@ -7,6 +7,7 @@ import CheckListPlugin from './check-list';
|
|
|
7
7
|
import TextPlugin from './text-style';
|
|
8
8
|
import CodeBlockPlugin from './code-block';
|
|
9
9
|
import ImagePlugin from './image';
|
|
10
|
-
|
|
10
|
+
import TablePlugin from './table';
|
|
11
|
+
var Plugins = [MarkDownPlugin, HeaderPlugin, LinkPlugin, BlockquotePlugin, ListPlugin, CheckListPlugin, TextPlugin, CodeBlockPlugin, ImagePlugin, TablePlugin];
|
|
11
12
|
export default Plugins;
|
|
12
|
-
export { MarkDownPlugin, HeaderPlugin, LinkPlugin, BlockquotePlugin, ListPlugin, CheckListPlugin, TextPlugin, CodeBlockPlugin, ImagePlugin };
|
|
13
|
+
export { MarkDownPlugin, HeaderPlugin, LinkPlugin, BlockquotePlugin, ListPlugin, CheckListPlugin, TextPlugin, CodeBlockPlugin, ImagePlugin, TablePlugin };
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
|
|
2
|
+
import _createClass from "@babel/runtime/helpers/esm/createClass";
|
|
3
|
+
import _inherits from "@babel/runtime/helpers/esm/inherits";
|
|
4
|
+
import _createSuper from "@babel/runtime/helpers/esm/createSuper";
|
|
5
|
+
import React, { Component } from 'react';
|
|
6
|
+
import { withTranslation } from 'react-i18next';
|
|
7
|
+
import { Modal, ModalHeader, ModalBody, ModalFooter, Button, Label } from 'reactstrap';
|
|
8
|
+
import NumberInput from '../../number-input';
|
|
9
|
+
import './index.css';
|
|
10
|
+
var CustomTableSizeDialog = /*#__PURE__*/function (_Component) {
|
|
11
|
+
_inherits(CustomTableSizeDialog, _Component);
|
|
12
|
+
var _super = _createSuper(CustomTableSizeDialog);
|
|
13
|
+
function CustomTableSizeDialog(props) {
|
|
14
|
+
var _this;
|
|
15
|
+
_classCallCheck(this, CustomTableSizeDialog);
|
|
16
|
+
_this = _super.call(this, props);
|
|
17
|
+
_this.toggle = function () {
|
|
18
|
+
_this.props.toggle();
|
|
19
|
+
};
|
|
20
|
+
_this.handleSubmit = function () {
|
|
21
|
+
var _this$state = _this.state,
|
|
22
|
+
rows = _this$state.rows,
|
|
23
|
+
cols = _this$state.cols;
|
|
24
|
+
_this.props.submit([parseInt(rows), parseInt(cols)]);
|
|
25
|
+
};
|
|
26
|
+
_this.rowsChange = function (event) {
|
|
27
|
+
var value = event.target.value;
|
|
28
|
+
if (value === _this.state.rows) return;
|
|
29
|
+
_this.setState({
|
|
30
|
+
rows: value
|
|
31
|
+
});
|
|
32
|
+
};
|
|
33
|
+
_this.colsChange = function (event) {
|
|
34
|
+
var value = event.target.value;
|
|
35
|
+
if (value === _this.state.cols) return;
|
|
36
|
+
_this.setState({
|
|
37
|
+
cols: value
|
|
38
|
+
});
|
|
39
|
+
};
|
|
40
|
+
_this.state = {
|
|
41
|
+
rows: '0',
|
|
42
|
+
cols: '0'
|
|
43
|
+
};
|
|
44
|
+
return _this;
|
|
45
|
+
}
|
|
46
|
+
_createClass(CustomTableSizeDialog, [{
|
|
47
|
+
key: "render",
|
|
48
|
+
value: function render() {
|
|
49
|
+
var t = this.props.t;
|
|
50
|
+
var _this$state2 = this.state,
|
|
51
|
+
rows = _this$state2.rows,
|
|
52
|
+
cols = _this$state2.cols;
|
|
53
|
+
return /*#__PURE__*/React.createElement(Modal, {
|
|
54
|
+
isOpen: true,
|
|
55
|
+
toggle: this.toggle,
|
|
56
|
+
size: "md",
|
|
57
|
+
className: "sdoc-custom-table-size-dialog",
|
|
58
|
+
zIndex: 1111
|
|
59
|
+
}, /*#__PURE__*/React.createElement(ModalHeader, {
|
|
60
|
+
toggle: this.toggle
|
|
61
|
+
}, t('Customize_the_number_of_rows_and_columns')), /*#__PURE__*/React.createElement(ModalBody, null, /*#__PURE__*/React.createElement("div", {
|
|
62
|
+
className: "d-flex sdoc-custom-table-size-container"
|
|
63
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
64
|
+
className: "d-flex flex-column sdoc-custom-table-size-item mr-4"
|
|
65
|
+
}, /*#__PURE__*/React.createElement(Label, {
|
|
66
|
+
className: "mb-2"
|
|
67
|
+
}, t('Rows')), /*#__PURE__*/React.createElement(NumberInput, {
|
|
68
|
+
max: 50,
|
|
69
|
+
value: rows,
|
|
70
|
+
onChange: this.rowsChange
|
|
71
|
+
})), /*#__PURE__*/React.createElement("div", {
|
|
72
|
+
className: "d-flex flex-column sdoc-custom-table-size-item"
|
|
73
|
+
}, /*#__PURE__*/React.createElement(Label, {
|
|
74
|
+
className: "mb-2"
|
|
75
|
+
}, t('Columns')), /*#__PURE__*/React.createElement(NumberInput, {
|
|
76
|
+
max: 50,
|
|
77
|
+
value: cols,
|
|
78
|
+
onChange: this.colsChange
|
|
79
|
+
})))), /*#__PURE__*/React.createElement(ModalFooter, null, /*#__PURE__*/React.createElement(Button, {
|
|
80
|
+
color: "secondary",
|
|
81
|
+
onClick: this.toggle
|
|
82
|
+
}, t('Cancel')), /*#__PURE__*/React.createElement(Button, {
|
|
83
|
+
color: "primary",
|
|
84
|
+
onClick: this.handleSubmit
|
|
85
|
+
}, t('Submit'))));
|
|
86
|
+
}
|
|
87
|
+
}]);
|
|
88
|
+
return CustomTableSizeDialog;
|
|
89
|
+
}(Component);
|
|
90
|
+
export default withTranslation('sdoc-editor')(CustomTableSizeDialog);
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
2
|
+
import slugid from 'slugid';
|
|
3
|
+
import { Editor, Range, Transforms } from '@seafile/slate';
|
|
4
|
+
import { ELEMENT_TYPE } from '../../constants';
|
|
5
|
+
import { getNodeType, getParentNode, isTextNode } from '../../core';
|
|
6
|
+
export var isTableMenuDisabled = function isTableMenuDisabled(editor) {
|
|
7
|
+
var selection = editor.selection;
|
|
8
|
+
if (selection === null) return true;
|
|
9
|
+
if (!Range.isCollapsed(selection)) return true;
|
|
10
|
+
var _Editor$nodes = Editor.nodes(editor, {
|
|
11
|
+
match: function match(n) {
|
|
12
|
+
var type = getNodeType(n);
|
|
13
|
+
if (!type && isTextNode(n) && n.id) {
|
|
14
|
+
var parentNode = getParentNode(editor.children, n.id);
|
|
15
|
+
type = getNodeType(parentNode);
|
|
16
|
+
}
|
|
17
|
+
if (type.startsWith('header')) return true;
|
|
18
|
+
if (type === ELEMENT_TYPE.CODE_BLOCK) return true;
|
|
19
|
+
if (type === ELEMENT_TYPE.ORDERED_LIST) return true;
|
|
20
|
+
if (type === ELEMENT_TYPE.UNORDERED_LIST) return true;
|
|
21
|
+
if (type === ELEMENT_TYPE.BLOCKQUOTE) return true;
|
|
22
|
+
if (type === ELEMENT_TYPE.LIST_ITEM) return true;
|
|
23
|
+
if (type === ELEMENT_TYPE.LIST_LIC) return true;
|
|
24
|
+
if (type === ELEMENT_TYPE.TABLE) return true;
|
|
25
|
+
if (type === ELEMENT_TYPE.TABLE_CELL) return true;
|
|
26
|
+
if (type === ELEMENT_TYPE.TABLE_ROW) return true;
|
|
27
|
+
if (Editor.isVoid(editor, n)) return true;
|
|
28
|
+
return false;
|
|
29
|
+
},
|
|
30
|
+
universal: true
|
|
31
|
+
}),
|
|
32
|
+
_Editor$nodes2 = _slicedToArray(_Editor$nodes, 1),
|
|
33
|
+
match = _Editor$nodes2[0];
|
|
34
|
+
if (match) return true;
|
|
35
|
+
return false;
|
|
36
|
+
};
|
|
37
|
+
export var generateTableCell = function generateTableCell() {
|
|
38
|
+
return {
|
|
39
|
+
id: slugid.nice(),
|
|
40
|
+
type: ELEMENT_TYPE.TABLE_CELL,
|
|
41
|
+
children: [{
|
|
42
|
+
text: '',
|
|
43
|
+
id: slugid.nice()
|
|
44
|
+
}]
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
export var generateTableRow = function generateTableRow(colsCount) {
|
|
48
|
+
var children = [];
|
|
49
|
+
for (var i = 0; i < colsCount; i++) {
|
|
50
|
+
var tableCell = generateTableCell();
|
|
51
|
+
children.push(tableCell);
|
|
52
|
+
}
|
|
53
|
+
return {
|
|
54
|
+
id: slugid.nice(),
|
|
55
|
+
type: ELEMENT_TYPE.TABLE_ROW,
|
|
56
|
+
children: children
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
export var generateEmptyTable = function generateEmptyTable() {
|
|
60
|
+
var size = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [0, 0];
|
|
61
|
+
var rowsCount = size[0];
|
|
62
|
+
var colsCount = size[1];
|
|
63
|
+
var children = [];
|
|
64
|
+
for (var i = 0; i < rowsCount; i++) {
|
|
65
|
+
var tableRow = generateTableRow(colsCount);
|
|
66
|
+
children.push(tableRow);
|
|
67
|
+
}
|
|
68
|
+
return {
|
|
69
|
+
id: slugid.nice(),
|
|
70
|
+
type: ELEMENT_TYPE.TABLE,
|
|
71
|
+
children: children
|
|
72
|
+
};
|
|
73
|
+
};
|
|
74
|
+
export var insertTable = function insertTable(editor, size, selection) {
|
|
75
|
+
if (!size) return;
|
|
76
|
+
if (isTableMenuDisabled(editor)) return;
|
|
77
|
+
var tableNode = generateEmptyTable(size);
|
|
78
|
+
Transforms.insertNodes(editor, tableNode, {
|
|
79
|
+
at: selection
|
|
80
|
+
});
|
|
81
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { TABLE } from '../../constants';
|
|
2
|
+
import { TableMenu } from './menu';
|
|
3
|
+
import Table from './model';
|
|
4
|
+
import withTable from './plugin';
|
|
5
|
+
import { renderTable, renderTableRow, renderTableCell } from './render-elem';
|
|
6
|
+
var TablePlugin = {
|
|
7
|
+
type: TABLE,
|
|
8
|
+
nodeType: 'element',
|
|
9
|
+
model: Table,
|
|
10
|
+
editorMenus: [TableMenu],
|
|
11
|
+
editorPlugin: withTable,
|
|
12
|
+
renderElements: [renderTable, renderTableRow, renderTableCell]
|
|
13
|
+
};
|
|
14
|
+
export default TablePlugin;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
|
|
2
|
+
import _createClass from "@babel/runtime/helpers/esm/createClass";
|
|
3
|
+
import _inherits from "@babel/runtime/helpers/esm/inherits";
|
|
4
|
+
import _createSuper from "@babel/runtime/helpers/esm/createSuper";
|
|
5
|
+
import React, { Component } from 'react';
|
|
6
|
+
import { UncontrolledPopover } from 'reactstrap';
|
|
7
|
+
var CommonMenu = /*#__PURE__*/function (_Component) {
|
|
8
|
+
_inherits(CommonMenu, _Component);
|
|
9
|
+
var _super = _createSuper(CommonMenu);
|
|
10
|
+
function CommonMenu(props) {
|
|
11
|
+
var _this;
|
|
12
|
+
_classCallCheck(this, CommonMenu);
|
|
13
|
+
_this = _super.call(this, props);
|
|
14
|
+
_this.getClassName = function () {
|
|
15
|
+
var _this$props = _this.props,
|
|
16
|
+
isRichEditor = _this$props.isRichEditor,
|
|
17
|
+
className = _this$props.className,
|
|
18
|
+
disabled = _this$props.disabled;
|
|
19
|
+
var itemClass = 'btn btn-icon btn-secondary btn-active d-flex';
|
|
20
|
+
if (!isRichEditor) return itemClass + ' ' + className;
|
|
21
|
+
itemClass = "rich-icon-btn d-flex ".concat(disabled ? 'rich-icon-btn-disabled' : 'rich-icon-btn-hover');
|
|
22
|
+
return itemClass + ' ' + className;
|
|
23
|
+
};
|
|
24
|
+
_this.hidePopover = function () {
|
|
25
|
+
_this.ref && _this.ref.toggle && _this.ref.toggle();
|
|
26
|
+
};
|
|
27
|
+
_this.setRef = function (ref) {
|
|
28
|
+
_this.ref = ref;
|
|
29
|
+
if (!_this.ref) return;
|
|
30
|
+
var toggle = _this.ref.toggle;
|
|
31
|
+
_this.ref.toggle = function () {
|
|
32
|
+
toggle && toggle();
|
|
33
|
+
_this.setState({
|
|
34
|
+
isShowMenu: !_this.state.isShowMenu
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
_this.state = {
|
|
39
|
+
isShowMenu: false
|
|
40
|
+
};
|
|
41
|
+
return _this;
|
|
42
|
+
}
|
|
43
|
+
_createClass(CommonMenu, [{
|
|
44
|
+
key: "render",
|
|
45
|
+
value: function render() {
|
|
46
|
+
var _this$props2 = this.props,
|
|
47
|
+
id = _this$props2.id,
|
|
48
|
+
iconClass = _this$props2.iconClass,
|
|
49
|
+
children = _this$props2.children;
|
|
50
|
+
var isShowMenu = this.state.isShowMenu;
|
|
51
|
+
var className = this.getClassName();
|
|
52
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("button", {
|
|
53
|
+
id: id,
|
|
54
|
+
type: "button",
|
|
55
|
+
className: className
|
|
56
|
+
}, /*#__PURE__*/React.createElement("i", {
|
|
57
|
+
className: iconClass
|
|
58
|
+
}), /*#__PURE__*/React.createElement("span", {
|
|
59
|
+
className: "iconfont icon-".concat(isShowMenu ? 'caret-up' : 'drop-down')
|
|
60
|
+
})), /*#__PURE__*/React.createElement(UncontrolledPopover, {
|
|
61
|
+
target: id,
|
|
62
|
+
className: "sdoc-common-menu-popover",
|
|
63
|
+
trigger: "legacy",
|
|
64
|
+
placement: "bottom-start",
|
|
65
|
+
hideArrow: true,
|
|
66
|
+
ref: this.setRef
|
|
67
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
68
|
+
className: "sdoc-common-menu-popover-container"
|
|
69
|
+
}, children)));
|
|
70
|
+
}
|
|
71
|
+
}]);
|
|
72
|
+
return CommonMenu;
|
|
73
|
+
}(Component);
|
|
74
|
+
CommonMenu.defaultProps = {
|
|
75
|
+
isRichEditor: true,
|
|
76
|
+
className: 'menu-group-item'
|
|
77
|
+
};
|
|
78
|
+
export default CommonMenu;
|