@seafile/sdoc-editor 0.1.43 → 0.1.45
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 +4 -0
- package/dist/basic-sdk/assets/css/outline.css +1 -0
- package/dist/basic-sdk/assets/css/sdoc-editor-plugins.css +1 -1
- package/dist/basic-sdk/assets/css/textlink-hovermenu.css +2 -2
- package/dist/basic-sdk/cursor/decorate.js +35 -0
- package/dist/basic-sdk/cursor/helper.js +40 -0
- package/dist/basic-sdk/editor.js +17 -16
- package/dist/basic-sdk/extension/constants/index.js +13 -13
- package/dist/basic-sdk/extension/menu/menu.css +2 -2
- package/dist/basic-sdk/extension/plugins/header/menu/index.js +1 -1
- package/dist/basic-sdk/extension/plugins/header/menu/style.css +2 -2
- package/dist/basic-sdk/extension/plugins/header/render-elem.js +1 -1
- package/dist/basic-sdk/extension/plugins/image/render-elem.js +2 -2
- package/dist/basic-sdk/extension/plugins/link/menu/hover-link-dialog.js +2 -2
- package/dist/basic-sdk/extension/plugins/table/constants/index.js +2 -0
- package/dist/basic-sdk/extension/plugins/table/dialog/custom-table-size-dialog/index.js +3 -2
- package/dist/basic-sdk/extension/plugins/table/menu/active-table-menu/common-menu.js +1 -1
- package/dist/basic-sdk/extension/plugins/table/menu/active-table-menu/index.css +1 -1
- package/dist/basic-sdk/extension/plugins/table/menu/active-table-menu/index.js +6 -6
- package/dist/basic-sdk/extension/plugins/table/plugin.js +81 -15
- package/dist/basic-sdk/extension/plugins/table/render/render-table/index.css +2 -2
- package/dist/basic-sdk/extension/plugins/table/render/render-table/index.js +1 -1
- package/dist/basic-sdk/extension/plugins/text-style/caret.js +47 -0
- package/dist/basic-sdk/extension/plugins/text-style/render-elem.js +6 -1
- package/dist/basic-sdk/extension/render/render-element.js +1 -1
- package/dist/basic-sdk/outline.js +2 -2
- package/dist/basic-sdk/socket/helpers.js +10 -4
- package/dist/basic-sdk/socket/socket-client.js +4 -2
- package/dist/basic-sdk/socket/socket-manager.js +3 -2
- package/dist/basic-sdk/socket/with-socket-io.js +19 -5
- package/dist/basic-sdk/viewer.js +7 -13
- package/dist/components/doc-info/index.js +1 -1
- package/dist/components/doc-operations/collaborators-operation/index.js +1 -1
- package/dist/components/doc-operations/index.js +3 -3
- package/dist/components/doc-operations/style.css +3 -2
- package/dist/components/toast/alert.js +4 -4
- package/package.json +2 -1
- package/public/locales/en/sdoc-editor.json +2 -2
- package/public/locales/zh-CN/sdoc-editor.json +2 -2
- package/public/media/sdoc-editor-font/iconfont.eot +0 -0
- package/public/media/sdoc-editor-font/iconfont.svg +37 -87
- 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 +58 -158
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
2
|
+
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
3
|
+
import { Text, Path, Range } from '@seafile/slate';
|
|
4
|
+
export var getDecorate = function getDecorate(editor) {
|
|
5
|
+
return function (nodeEntry) {
|
|
6
|
+
var ranges = [];
|
|
7
|
+
var _nodeEntry = _slicedToArray(nodeEntry, 2),
|
|
8
|
+
node = _nodeEntry[0],
|
|
9
|
+
path = _nodeEntry[1];
|
|
10
|
+
var cursors = Object.values(editor.cursors || {});
|
|
11
|
+
if (Text.isText(node) && (cursors === null || cursors === void 0 ? void 0 : cursors.length)) {
|
|
12
|
+
cursors.forEach(function (cursor) {
|
|
13
|
+
if (Range.includes(cursor, path)) {
|
|
14
|
+
var focus = cursor.focus,
|
|
15
|
+
anchor = cursor.anchor,
|
|
16
|
+
isForward = cursor.isForward;
|
|
17
|
+
var isFocusNode = Path.equals(focus.path, path);
|
|
18
|
+
var isAnchorNode = Path.equals(anchor.path, path);
|
|
19
|
+
ranges.push(_objectSpread(_objectSpread({}, cursor), {}, {
|
|
20
|
+
isCaret: isFocusNode,
|
|
21
|
+
anchor: {
|
|
22
|
+
path: path,
|
|
23
|
+
offset: isAnchorNode ? anchor.offset : isForward ? 0 : node.text.length
|
|
24
|
+
},
|
|
25
|
+
focus: {
|
|
26
|
+
path: path,
|
|
27
|
+
offset: isFocusNode ? focus.offset : isForward ? node.text.length : 0
|
|
28
|
+
}
|
|
29
|
+
}));
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
return ranges;
|
|
34
|
+
};
|
|
35
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
2
|
+
import { Range } from '@seafile/slate';
|
|
3
|
+
import randomColor from 'randomcolor';
|
|
4
|
+
|
|
5
|
+
// selection: { anchor, focus }
|
|
6
|
+
// cursor: { anchor, focus }
|
|
7
|
+
|
|
8
|
+
export var setCursor = function setCursor(id, editor, operations, cursorData) {
|
|
9
|
+
var cursorOps = operations.filter(function (operation) {
|
|
10
|
+
return operation.type === 'set_selection';
|
|
11
|
+
});
|
|
12
|
+
if (!editor.cursors) editor.cursors = {};
|
|
13
|
+
var oldCursor = editor.cursors[id] ? editor.cursors[id] : {};
|
|
14
|
+
var lastCursorOp = cursorOps[cursorOps.length - 1];
|
|
15
|
+
var selection = editor.selection;
|
|
16
|
+
if (selection) {
|
|
17
|
+
var newCursor = lastCursorOp && lastCursorOp.newProperties || {};
|
|
18
|
+
var newCursorData = _objectSpread(_objectSpread(_objectSpread(_objectSpread({}, oldCursor), newCursor), selection), _objectSpread(_objectSpread({}, cursorData), {}, {
|
|
19
|
+
isForward: Range.isForward(selection)
|
|
20
|
+
}));
|
|
21
|
+
editor.cursors[id] = newCursorData;
|
|
22
|
+
} else {
|
|
23
|
+
delete editor.cursors[id];
|
|
24
|
+
}
|
|
25
|
+
return editor;
|
|
26
|
+
};
|
|
27
|
+
export var generateCursorData = function generateCursorData(config) {
|
|
28
|
+
var user = config.user;
|
|
29
|
+
var options = {
|
|
30
|
+
luminosity: 'dark',
|
|
31
|
+
format: 'rgba',
|
|
32
|
+
alpha: 1
|
|
33
|
+
};
|
|
34
|
+
var color = randomColor(options);
|
|
35
|
+
return {
|
|
36
|
+
name: user.name,
|
|
37
|
+
color: color,
|
|
38
|
+
alphaColor: color.slice(0, -2) + '0.2)'
|
|
39
|
+
};
|
|
40
|
+
};
|
package/dist/basic-sdk/editor.js
CHANGED
|
@@ -4,14 +4,16 @@ 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 { Node } from '@seafile/slate';
|
|
7
8
|
import { Editable, Slate, ReactEditor } from '@seafile/slate-react';
|
|
8
9
|
import { Editor } from '@seafile/slate';
|
|
9
10
|
import editor, { renderLeaf as _renderLeaf, renderElement as _renderElement, Toolbar } from './extension';
|
|
10
|
-
import {
|
|
11
|
+
import { withSocketIO } from './socket';
|
|
11
12
|
import withNodeId from './node-id';
|
|
12
13
|
import SDocOutline from './outline';
|
|
13
14
|
import EventProxy from './utils/event-handler';
|
|
14
15
|
import { focusEditor } from './extension/core';
|
|
16
|
+
import { getDecorate } from './cursor/decorate';
|
|
15
17
|
import './assets/css/layout.css';
|
|
16
18
|
import './assets/css/sdoc-editor-plugins.css';
|
|
17
19
|
var SDocEditor = /*#__PURE__*/function (_React$Component) {
|
|
@@ -21,9 +23,6 @@ var SDocEditor = /*#__PURE__*/function (_React$Component) {
|
|
|
21
23
|
var _this;
|
|
22
24
|
_classCallCheck(this, SDocEditor);
|
|
23
25
|
_this = _super.call(this, props);
|
|
24
|
-
_this.getSocketManager = function () {
|
|
25
|
-
return _this.socketManager;
|
|
26
|
-
};
|
|
27
26
|
_this.onChange = function (slateValue) {
|
|
28
27
|
var onValueChanged = _this.props.onValueChanged;
|
|
29
28
|
_this.setState({
|
|
@@ -55,7 +54,12 @@ var SDocEditor = /*#__PURE__*/function (_React$Component) {
|
|
|
55
54
|
_this.socketManager = null;
|
|
56
55
|
_this.editor = withNodeId(editor);
|
|
57
56
|
if (props.isOpenSocket) {
|
|
58
|
-
|
|
57
|
+
var document = props.document,
|
|
58
|
+
config = props.config;
|
|
59
|
+
_this.editor = withSocketIO(_this.editor, {
|
|
60
|
+
document: document,
|
|
61
|
+
config: config
|
|
62
|
+
});
|
|
59
63
|
}
|
|
60
64
|
_this.eventProxy = new EventProxy(_this.editor);
|
|
61
65
|
return _this;
|
|
@@ -63,21 +67,16 @@ var SDocEditor = /*#__PURE__*/function (_React$Component) {
|
|
|
63
67
|
_createClass(SDocEditor, [{
|
|
64
68
|
key: "componentDidMount",
|
|
65
69
|
value: function componentDidMount() {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
if (isOpenSocket) {
|
|
71
|
-
this.socketManager = SocketManager.getInstance(this.editor, document, config);
|
|
70
|
+
this.editor.openConnection();
|
|
71
|
+
if (Node.string(editor) === '') {
|
|
72
|
+
var firstNodePath = ReactEditor.findPath(editor, this.editor.children[0]);
|
|
73
|
+
focusEditor(this.editor, firstNodePath);
|
|
72
74
|
}
|
|
73
|
-
var firstNodepath = ReactEditor.findPath(editor, this.editor.children[0]);
|
|
74
|
-
focusEditor(this.editor, firstNodepath);
|
|
75
75
|
}
|
|
76
76
|
}, {
|
|
77
77
|
key: "componentWillUnmount",
|
|
78
78
|
value: function componentWillUnmount() {
|
|
79
|
-
this.
|
|
80
|
-
this.socketManager = null;
|
|
79
|
+
this.editor.closeConnection();
|
|
81
80
|
}
|
|
82
81
|
}, {
|
|
83
82
|
key: "render",
|
|
@@ -86,6 +85,7 @@ var SDocEditor = /*#__PURE__*/function (_React$Component) {
|
|
|
86
85
|
var slateValue = this.state.slateValue;
|
|
87
86
|
var config = this.props.config;
|
|
88
87
|
var docUuid = config.docUuid;
|
|
88
|
+
var decorate = getDecorate(editor);
|
|
89
89
|
return /*#__PURE__*/React.createElement("div", {
|
|
90
90
|
className: "sdoc-editor-container"
|
|
91
91
|
}, /*#__PURE__*/React.createElement(Toolbar, {
|
|
@@ -111,7 +111,8 @@ var SDocEditor = /*#__PURE__*/function (_React$Component) {
|
|
|
111
111
|
return _renderLeaf(props, _this2.editor);
|
|
112
112
|
},
|
|
113
113
|
onKeyDown: this.eventProxy.onKeyDown,
|
|
114
|
-
onDOMBeforeInput: this.onDOMBeforeInput
|
|
114
|
+
onDOMBeforeInput: this.onDOMBeforeInput,
|
|
115
|
+
decorate: decorate
|
|
115
116
|
}))))));
|
|
116
117
|
}
|
|
117
118
|
}]);
|
|
@@ -15,58 +15,58 @@ export var REMOVE_TABLE = 'remove_table';
|
|
|
15
15
|
// menus config
|
|
16
16
|
export var MENUS_CONFIG_MAP = (_MENUS_CONFIG_MAP = {}, _defineProperty(_MENUS_CONFIG_MAP, BLOCKQUOTE, {
|
|
17
17
|
id: "sdoc_".concat(BLOCKQUOTE),
|
|
18
|
-
iconClass: '
|
|
18
|
+
iconClass: 'sdocfont sdoc-quote-left',
|
|
19
19
|
text: 'quote'
|
|
20
20
|
}), _defineProperty(_MENUS_CONFIG_MAP, ORDERED_LIST, {
|
|
21
21
|
id: ORDERED_LIST,
|
|
22
|
-
iconClass: '
|
|
22
|
+
iconClass: 'sdocfont sdoc-list-ol',
|
|
23
23
|
text: 'ordered_list'
|
|
24
24
|
}), _defineProperty(_MENUS_CONFIG_MAP, UNORDERED_LIST, {
|
|
25
25
|
id: UNORDERED_LIST,
|
|
26
|
-
iconClass: '
|
|
26
|
+
iconClass: 'sdocfont sdoc-list-ul',
|
|
27
27
|
text: 'unordered_list'
|
|
28
28
|
}), _defineProperty(_MENUS_CONFIG_MAP, CHECK_LIST, {
|
|
29
29
|
id: CHECK_LIST,
|
|
30
|
-
iconClass: '
|
|
30
|
+
iconClass: 'sdocfont sdoc-check-square',
|
|
31
31
|
text: 'check_list_item'
|
|
32
32
|
}), _defineProperty(_MENUS_CONFIG_MAP, CODE_BLOCK, {
|
|
33
33
|
id: CODE_BLOCK,
|
|
34
|
-
iconClass: '
|
|
34
|
+
iconClass: 'sdocfont sdoc-code-block',
|
|
35
35
|
text: 'code_block'
|
|
36
36
|
}), _defineProperty(_MENUS_CONFIG_MAP, LINK, {
|
|
37
37
|
id: "sdoc_".concat(LINK),
|
|
38
|
-
iconClass: '
|
|
38
|
+
iconClass: 'sdocfont sdoc-link',
|
|
39
39
|
text: 'insert_link'
|
|
40
40
|
}), _defineProperty(_MENUS_CONFIG_MAP, IMAGE, {
|
|
41
41
|
id: "sdoc_".concat(IMAGE),
|
|
42
|
-
iconClass: '
|
|
42
|
+
iconClass: 'sdocfont sdoc-image',
|
|
43
43
|
text: 'insert_image'
|
|
44
44
|
}), _defineProperty(_MENUS_CONFIG_MAP, TABLE, {
|
|
45
45
|
id: "sdoc_".concat(TABLE),
|
|
46
|
-
iconClass: '
|
|
46
|
+
iconClass: 'sdocfont sdoc-table',
|
|
47
47
|
text: 'insert_table'
|
|
48
48
|
}), _defineProperty(_MENUS_CONFIG_MAP, REMOVE_TABLE, {
|
|
49
49
|
id: "sdoc_".concat(REMOVE_TABLE),
|
|
50
|
-
iconClass: '
|
|
50
|
+
iconClass: 'sdocfont sdoc-delete-table',
|
|
51
51
|
text: 'remove_table'
|
|
52
52
|
}), _defineProperty(_MENUS_CONFIG_MAP, TEXT_STYLE, [{
|
|
53
53
|
id: ITALIC,
|
|
54
|
-
iconClass: '
|
|
54
|
+
iconClass: 'sdocfont sdoc-italic',
|
|
55
55
|
text: 'italic',
|
|
56
56
|
type: 'ITALIC'
|
|
57
57
|
}, {
|
|
58
58
|
id: BOLD,
|
|
59
|
-
iconClass: '
|
|
59
|
+
iconClass: 'sdocfont sdoc-bold',
|
|
60
60
|
text: 'bold',
|
|
61
61
|
type: 'BOLD'
|
|
62
62
|
}]), _defineProperty(_MENUS_CONFIG_MAP, UNDO, {
|
|
63
63
|
id: UNDO,
|
|
64
|
-
iconClass: '
|
|
64
|
+
iconClass: 'sdocfont sdoc-revoke',
|
|
65
65
|
text: 'undo',
|
|
66
66
|
type: 'undo'
|
|
67
67
|
}), _defineProperty(_MENUS_CONFIG_MAP, REDO, {
|
|
68
68
|
id: REDO,
|
|
69
|
-
iconClass: '
|
|
69
|
+
iconClass: 'sdocfont sdoc-redo',
|
|
70
70
|
text: 'redo',
|
|
71
71
|
type: 'redo'
|
|
72
72
|
}), _MENUS_CONFIG_MAP);
|
|
@@ -77,7 +77,7 @@ var HeaderMenu = /*#__PURE__*/function (_React$Component) {
|
|
|
77
77
|
value: function render() {
|
|
78
78
|
var t = this.props.t;
|
|
79
79
|
var isShowHeaderPopover = this.state.isShowHeaderPopover;
|
|
80
|
-
var headerIconClass = "
|
|
80
|
+
var headerIconClass = "sdocfont sdoc-".concat(isShowHeaderPopover ? 'caret-up' : 'drop-down');
|
|
81
81
|
var headerType = this.getValue();
|
|
82
82
|
var disabled = this.isDisabled();
|
|
83
83
|
return /*#__PURE__*/React.createElement("div", {
|
|
@@ -25,13 +25,13 @@
|
|
|
25
25
|
border-radius: 2px;
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
.header-menu .header-toggle .
|
|
28
|
+
.header-menu .header-toggle .sdocfont {
|
|
29
29
|
width: 30px;
|
|
30
30
|
height: 30px;
|
|
31
31
|
display: inline-flex;
|
|
32
32
|
justify-content: center;
|
|
33
33
|
align-items: center;
|
|
34
|
-
font-size:
|
|
34
|
+
font-size: 14px;
|
|
35
35
|
transform: scale(.8);
|
|
36
36
|
cursor: pointer;
|
|
37
37
|
}
|
|
@@ -21,7 +21,7 @@ var renderHeader = function renderHeader(props, editor) {
|
|
|
21
21
|
position: isShowPlaceHolder ? 'relative' : ''
|
|
22
22
|
}
|
|
23
23
|
}), isShowPlaceHolder && /*#__PURE__*/React.createElement(Placeholder, {
|
|
24
|
-
title: '
|
|
24
|
+
title: 'Please_enter_title'
|
|
25
25
|
}), children);
|
|
26
26
|
};
|
|
27
27
|
export default renderHeader;
|
|
@@ -103,7 +103,7 @@ var Image = /*#__PURE__*/function (_React$Component) {
|
|
|
103
103
|
var imageClassName = isSelected ? 'image-selected' : '';
|
|
104
104
|
var imageStyle = this.getImageStyle();
|
|
105
105
|
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("span", Object.assign({
|
|
106
|
-
className: classNames('sdoc-image', className)
|
|
106
|
+
className: classNames('sdoc-image-wrapper', className)
|
|
107
107
|
}, attributes), /*#__PURE__*/React.createElement("img", {
|
|
108
108
|
className: imageClassName,
|
|
109
109
|
ref: this.setImageRef,
|
|
@@ -120,7 +120,7 @@ var Image = /*#__PURE__*/function (_React$Component) {
|
|
|
120
120
|
contentEditable: false,
|
|
121
121
|
onClick: this.setFullScreen
|
|
122
122
|
}, /*#__PURE__*/React.createElement("i", {
|
|
123
|
-
className: '
|
|
123
|
+
className: 'sdocfont sdoc-fullscreen',
|
|
124
124
|
title: t('Full_screen')
|
|
125
125
|
}))), isResizing && /*#__PURE__*/React.createElement("span", {
|
|
126
126
|
className: "image-size",
|
|
@@ -36,13 +36,13 @@ var LinkHoverComponent = /*#__PURE__*/function (_React$Component) {
|
|
|
36
36
|
className: "link-op-icon",
|
|
37
37
|
onClick: this.props.onDeleteLink
|
|
38
38
|
}, /*#__PURE__*/React.createElement("i", {
|
|
39
|
-
className: "
|
|
39
|
+
className: "sdocfont sdoc-delete"
|
|
40
40
|
})), /*#__PURE__*/React.createElement("span", {
|
|
41
41
|
role: "button",
|
|
42
42
|
className: "link-op-icon",
|
|
43
43
|
onClick: this.props.onEditLink
|
|
44
44
|
}, /*#__PURE__*/React.createElement("i", {
|
|
45
|
-
className: "
|
|
45
|
+
className: "sdocfont sdoc-rename"
|
|
46
46
|
}))), /*#__PURE__*/React.createElement("span", {
|
|
47
47
|
className: "link-op-menu-triangle"
|
|
48
48
|
})), document.body));
|
|
@@ -6,6 +6,7 @@ import React, { Component } from 'react';
|
|
|
6
6
|
import { withTranslation } from 'react-i18next';
|
|
7
7
|
import { Modal, ModalHeader, ModalBody, ModalFooter, Button, Label } from 'reactstrap';
|
|
8
8
|
import NumberInput from '../../number-input';
|
|
9
|
+
import { TABLE_MAX_ROWS, TABLE_MAX_COLUMNS } from '../../constants';
|
|
9
10
|
import './index.css';
|
|
10
11
|
var CustomTableSizeDialog = /*#__PURE__*/function (_Component) {
|
|
11
12
|
_inherits(CustomTableSizeDialog, _Component);
|
|
@@ -65,7 +66,7 @@ var CustomTableSizeDialog = /*#__PURE__*/function (_Component) {
|
|
|
65
66
|
}, /*#__PURE__*/React.createElement(Label, {
|
|
66
67
|
className: "mb-2"
|
|
67
68
|
}, t('Rows')), /*#__PURE__*/React.createElement(NumberInput, {
|
|
68
|
-
max:
|
|
69
|
+
max: TABLE_MAX_ROWS,
|
|
69
70
|
value: rows,
|
|
70
71
|
onChange: this.rowsChange
|
|
71
72
|
})), /*#__PURE__*/React.createElement("div", {
|
|
@@ -73,7 +74,7 @@ var CustomTableSizeDialog = /*#__PURE__*/function (_Component) {
|
|
|
73
74
|
}, /*#__PURE__*/React.createElement(Label, {
|
|
74
75
|
className: "mb-2"
|
|
75
76
|
}, t('Columns')), /*#__PURE__*/React.createElement(NumberInput, {
|
|
76
|
-
max:
|
|
77
|
+
max: TABLE_MAX_COLUMNS,
|
|
77
78
|
value: cols,
|
|
78
79
|
onChange: this.colsChange
|
|
79
80
|
})))), /*#__PURE__*/React.createElement(ModalFooter, null, /*#__PURE__*/React.createElement(Button, {
|
|
@@ -56,7 +56,7 @@ var CommonMenu = /*#__PURE__*/function (_Component) {
|
|
|
56
56
|
}, /*#__PURE__*/React.createElement("i", {
|
|
57
57
|
className: iconClass
|
|
58
58
|
}), /*#__PURE__*/React.createElement("span", {
|
|
59
|
-
className: "
|
|
59
|
+
className: "sdocfont sdoc-".concat(isShowMenu ? 'caret-up' : 'drop-down')
|
|
60
60
|
})), /*#__PURE__*/React.createElement(UncontrolledPopover, {
|
|
61
61
|
target: id,
|
|
62
62
|
className: "sdoc-common-menu-popover",
|
|
@@ -53,7 +53,7 @@ var ActiveTableMenu = /*#__PURE__*/function (_Component) {
|
|
|
53
53
|
var t = _this.props.t;
|
|
54
54
|
return /*#__PURE__*/React.createElement(CommonMenu, {
|
|
55
55
|
id: "text-align",
|
|
56
|
-
iconClass: "
|
|
56
|
+
iconClass: "sdocfont sdoc-left-alignment mr-1",
|
|
57
57
|
ref: function ref(_ref) {
|
|
58
58
|
return _this.textAlignRef = _ref;
|
|
59
59
|
}
|
|
@@ -61,24 +61,24 @@ var ActiveTableMenu = /*#__PURE__*/function (_Component) {
|
|
|
61
61
|
className: "dropdown-item",
|
|
62
62
|
onClick: _this.setTextAlignStyle.bind(_assertThisInitialized(_this), 'left')
|
|
63
63
|
}, /*#__PURE__*/React.createElement("i", {
|
|
64
|
-
className: "
|
|
64
|
+
className: "sdocfont sdoc-left-alignment mr-2"
|
|
65
65
|
}), t('left')), /*#__PURE__*/React.createElement("button", {
|
|
66
66
|
className: "dropdown-item",
|
|
67
67
|
onClick: _this.setTextAlignStyle.bind(_assertThisInitialized(_this), 'center')
|
|
68
68
|
}, /*#__PURE__*/React.createElement("i", {
|
|
69
|
-
className: "
|
|
69
|
+
className: "sdocfont sdoc-center-horizontally mr-2"
|
|
70
70
|
}), t('center')), /*#__PURE__*/React.createElement("button", {
|
|
71
71
|
className: "dropdown-item",
|
|
72
72
|
onClick: _this.setTextAlignStyle.bind(_assertThisInitialized(_this), 'right')
|
|
73
73
|
}, /*#__PURE__*/React.createElement("i", {
|
|
74
|
-
className: "
|
|
74
|
+
className: "sdocfont sdoc-align-right mr-2"
|
|
75
75
|
}), t('right')));
|
|
76
76
|
};
|
|
77
77
|
_this.renderTableColumn = function () {
|
|
78
78
|
var t = _this.props.t;
|
|
79
79
|
return /*#__PURE__*/React.createElement(CommonMenu, {
|
|
80
80
|
id: "table-column",
|
|
81
|
-
iconClass: "
|
|
81
|
+
iconClass: "sdocfont sdoc-column mr-1",
|
|
82
82
|
ref: function ref(_ref2) {
|
|
83
83
|
return _this.tableColumnRef = _ref2;
|
|
84
84
|
}
|
|
@@ -94,7 +94,7 @@ var ActiveTableMenu = /*#__PURE__*/function (_Component) {
|
|
|
94
94
|
var t = _this.props.t;
|
|
95
95
|
return /*#__PURE__*/React.createElement(CommonMenu, {
|
|
96
96
|
id: "table-row",
|
|
97
|
-
iconClass: "
|
|
97
|
+
iconClass: "sdocfont sdoc-row mr-1",
|
|
98
98
|
ref: function ref(_ref3) {
|
|
99
99
|
return _this.tableRowRef = _ref3;
|
|
100
100
|
}
|
|
@@ -9,6 +9,7 @@ import { getNodeType, getParentNode, getSelectedNodeByType, isTextNode, isLastNo
|
|
|
9
9
|
import { getNodePathById } from '../../../socket/helpers';
|
|
10
10
|
import { ELEMENT_TYPE, TABLE_ELEMENT, TABLE_ELEMENT_POSITION, KEYBOARD } from '../../constants';
|
|
11
11
|
import { generateTableRow, generateTableCell } from './helpers';
|
|
12
|
+
import { TABLE_MAX_ROWS, TABLE_MAX_COLUMNS } from './constants';
|
|
12
13
|
var deleteHandler = function deleteHandler(editor) {
|
|
13
14
|
var selection = editor.selection;
|
|
14
15
|
if (selection == null) return false;
|
|
@@ -185,6 +186,16 @@ var focusCell = function focusCell(editor, event) {
|
|
|
185
186
|
});
|
|
186
187
|
}
|
|
187
188
|
};
|
|
189
|
+
var isLastTableCell = function isLastTableCell(editor, cellNode) {
|
|
190
|
+
if (cellNode[0].type !== ELEMENT_TYPE.TABLE_CELL) return false;
|
|
191
|
+
var _getSelectedInfo3 = getSelectedInfo(editor),
|
|
192
|
+
tableSize = _getSelectedInfo3.tableSize;
|
|
193
|
+
var lastRowIndex = tableSize[0] - 1;
|
|
194
|
+
var lastColumnIndex = tableSize[1] - 1;
|
|
195
|
+
var cellNodePath = cellNode[1];
|
|
196
|
+
var cellNodePathDeep = cellNodePath.length;
|
|
197
|
+
return cellNodePath[cellNodePathDeep - 1] === lastColumnIndex && cellNodePath[cellNodePathDeep - 2] === lastRowIndex;
|
|
198
|
+
};
|
|
188
199
|
var withTable = function withTable(editor) {
|
|
189
200
|
var insertBreak = editor.insertBreak,
|
|
190
201
|
deleteBackward = editor.deleteBackward,
|
|
@@ -192,7 +203,8 @@ var withTable = function withTable(editor) {
|
|
|
192
203
|
insertData = editor.insertData,
|
|
193
204
|
selectAll = editor.selectAll,
|
|
194
205
|
normalizeNode = editor.normalizeNode,
|
|
195
|
-
deleteFragment = editor.deleteFragment
|
|
206
|
+
deleteFragment = editor.deleteFragment,
|
|
207
|
+
handleTab = editor.handleTab;
|
|
196
208
|
var newEditor = editor;
|
|
197
209
|
newEditor.tableOnKeyDown = function (event) {
|
|
198
210
|
// Handle special keyboard events
|
|
@@ -214,6 +226,9 @@ var withTable = function withTable(editor) {
|
|
|
214
226
|
if (isHotkey(KEYBOARD.LEFT, event)) {
|
|
215
227
|
focusCell(newEditor, event, KEYBOARD.LEFT);
|
|
216
228
|
}
|
|
229
|
+
if (isHotkey('tab', event)) {
|
|
230
|
+
event.preventDefault();
|
|
231
|
+
}
|
|
217
232
|
};
|
|
218
233
|
newEditor.insertBreak = function () {
|
|
219
234
|
var selectedNode = getSelectedNodeByType(newEditor, ELEMENT_TYPE.TABLE);
|
|
@@ -318,9 +333,9 @@ var withTable = function withTable(editor) {
|
|
|
318
333
|
|
|
319
334
|
// Some text is selected in a cell
|
|
320
335
|
if (selectedNodesCount === 3) {
|
|
321
|
-
var
|
|
322
|
-
cell =
|
|
323
|
-
cellPath =
|
|
336
|
+
var _getSelectedInfo4 = getSelectedInfo(newEditor),
|
|
337
|
+
cell = _getSelectedInfo4.cell,
|
|
338
|
+
cellPath = _getSelectedInfo4.cellPath;
|
|
324
339
|
var selection = newEditor.selection;
|
|
325
340
|
var focus = selection.focus,
|
|
326
341
|
anchor = selection.anchor;
|
|
@@ -378,6 +393,55 @@ var withTable = function withTable(editor) {
|
|
|
378
393
|
deleteFragment(fragment);
|
|
379
394
|
};
|
|
380
395
|
|
|
396
|
+
// Jump to the next cell when pressing tab in the table
|
|
397
|
+
newEditor.handleTab = function (event) {
|
|
398
|
+
var selectedNode = getSelectedNodeByType(newEditor, ELEMENT_TYPE.TABLE);
|
|
399
|
+
if (!selectedNode) {
|
|
400
|
+
handleTab(event);
|
|
401
|
+
return;
|
|
402
|
+
}
|
|
403
|
+
var above = Editor.above(newEditor);
|
|
404
|
+
|
|
405
|
+
// Select multiple cells, jump to the first selected cell
|
|
406
|
+
if (above[0].type === ELEMENT_TYPE.TABLE) {
|
|
407
|
+
var _selection = newEditor.selection;
|
|
408
|
+
var anchor = _selection.anchor;
|
|
409
|
+
Transforms.select(newEditor, _toConsumableArray(anchor.path.slice(0, -1)));
|
|
410
|
+
return;
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
// Add row to the last cell
|
|
414
|
+
if (isLastTableCell(newEditor, above)) {
|
|
415
|
+
var _getSelectedInfo5 = getSelectedInfo(newEditor),
|
|
416
|
+
tablePath = _getSelectedInfo5.tablePath,
|
|
417
|
+
tableSize = _getSelectedInfo5.tableSize;
|
|
418
|
+
if (tableSize[0] === TABLE_MAX_ROWS) return;
|
|
419
|
+
newEditor.insertTableElement(TABLE_ELEMENT.ROW, TABLE_ELEMENT_POSITION.AFTER);
|
|
420
|
+
Transforms.select(newEditor, [].concat(_toConsumableArray(tablePath), [tableSize[0], 0]));
|
|
421
|
+
return;
|
|
422
|
+
}
|
|
423
|
+
var selection = newEditor.selection;
|
|
424
|
+
|
|
425
|
+
// The default behavior, the cursor is in the middle of the text, and the current text content is selected
|
|
426
|
+
// Change to jump to next cell
|
|
427
|
+
if (selection.anchor.offset === selection.focus.offset) {
|
|
428
|
+
var _getSelectedInfo6 = getSelectedInfo(newEditor),
|
|
429
|
+
_tableSize = _getSelectedInfo6.tableSize,
|
|
430
|
+
_tablePath = _getSelectedInfo6.tablePath,
|
|
431
|
+
rowIndex = _getSelectedInfo6.rowIndex,
|
|
432
|
+
cellIndex = _getSelectedInfo6.cellIndex;
|
|
433
|
+
var lastColumnIndex = _tableSize[1] - 1;
|
|
434
|
+
var nextCell = [rowIndex, cellIndex + 1];
|
|
435
|
+
if (lastColumnIndex < nextCell[1]) {
|
|
436
|
+
nextCell = [rowIndex + 1, 0];
|
|
437
|
+
}
|
|
438
|
+
Transforms.select(newEditor, [].concat(_toConsumableArray(_tablePath), _toConsumableArray(nextCell)));
|
|
439
|
+
return;
|
|
440
|
+
}
|
|
441
|
+
var next = Editor.next(newEditor);
|
|
442
|
+
Transforms.select(newEditor, next[1]);
|
|
443
|
+
};
|
|
444
|
+
|
|
381
445
|
// specific business logic
|
|
382
446
|
newEditor.isInTable = function () {
|
|
383
447
|
var selectedNodes = getSelectedElems(newEditor);
|
|
@@ -425,12 +489,13 @@ var withTable = function withTable(editor) {
|
|
|
425
489
|
};
|
|
426
490
|
newEditor.insertTableElement = function (type) {
|
|
427
491
|
var position = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : TABLE_ELEMENT_POSITION.AFTER;
|
|
428
|
-
var
|
|
429
|
-
tablePath =
|
|
430
|
-
tableSize =
|
|
431
|
-
rowIndex =
|
|
432
|
-
cellIndex =
|
|
492
|
+
var _getSelectedInfo7 = getSelectedInfo(newEditor),
|
|
493
|
+
tablePath = _getSelectedInfo7.tablePath,
|
|
494
|
+
tableSize = _getSelectedInfo7.tableSize,
|
|
495
|
+
rowIndex = _getSelectedInfo7.rowIndex,
|
|
496
|
+
cellIndex = _getSelectedInfo7.cellIndex;
|
|
433
497
|
if (type === TABLE_ELEMENT.ROW) {
|
|
498
|
+
if (tableSize[0] === TABLE_MAX_ROWS) return;
|
|
434
499
|
var targetPath = position === TABLE_ELEMENT_POSITION.AFTER ? [].concat(_toConsumableArray(tablePath), [rowIndex + 1]) : [].concat(_toConsumableArray(tablePath), [rowIndex]);
|
|
435
500
|
var row = generateTableRow(tableSize[1]);
|
|
436
501
|
Transforms.insertNodes(editor, row, {
|
|
@@ -441,6 +506,7 @@ var withTable = function withTable(editor) {
|
|
|
441
506
|
return;
|
|
442
507
|
}
|
|
443
508
|
if (type === TABLE_ELEMENT.COLUMN) {
|
|
509
|
+
if (tableSize[1] === TABLE_MAX_COLUMNS) return;
|
|
444
510
|
var newCellIndex = position === TABLE_ELEMENT_POSITION.AFTER ? cellIndex + 1 : cellIndex;
|
|
445
511
|
for (var i = 0; i < tableSize[0]; i++) {
|
|
446
512
|
var newCellPath = [].concat(_toConsumableArray(tablePath), [i, newCellIndex]);
|
|
@@ -455,12 +521,12 @@ var withTable = function withTable(editor) {
|
|
|
455
521
|
}
|
|
456
522
|
};
|
|
457
523
|
newEditor.removeTableElement = function (type) {
|
|
458
|
-
var
|
|
459
|
-
tablePath =
|
|
460
|
-
tableSize =
|
|
461
|
-
rowPath =
|
|
462
|
-
rowIndex =
|
|
463
|
-
cellIndex =
|
|
524
|
+
var _getSelectedInfo8 = getSelectedInfo(newEditor),
|
|
525
|
+
tablePath = _getSelectedInfo8.tablePath,
|
|
526
|
+
tableSize = _getSelectedInfo8.tableSize,
|
|
527
|
+
rowPath = _getSelectedInfo8.rowPath,
|
|
528
|
+
rowIndex = _getSelectedInfo8.rowIndex,
|
|
529
|
+
cellIndex = _getSelectedInfo8.cellIndex;
|
|
464
530
|
if (type === TABLE_ELEMENT.TABLE) {
|
|
465
531
|
removeTable(newEditor, tablePath);
|
|
466
532
|
return;
|
|
@@ -22,7 +22,7 @@ var Table = /*#__PURE__*/function (_Component) {
|
|
|
22
22
|
children = _this$props.children,
|
|
23
23
|
isSelected = _this$props.isSelected;
|
|
24
24
|
return /*#__PURE__*/React.createElement("div", Object.assign({}, attributes, {
|
|
25
|
-
className: classnames('sdoc-table', attributes.className, className, {
|
|
25
|
+
className: classnames('sdoc-table-wrapper', attributes.className, className, {
|
|
26
26
|
'sdoc-table-selected': isSelected
|
|
27
27
|
})
|
|
28
28
|
}), /*#__PURE__*/React.createElement("table", null, /*#__PURE__*/React.createElement("tbody", null, children)));
|