@seafile/sdoc-editor 0.1.52 → 0.1.54
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/editor.js +13 -2
- package/dist/basic-sdk/extension/constants/index.js +2 -1
- package/dist/basic-sdk/extension/menu/context-menu/index.js +2 -1
- package/dist/basic-sdk/extension/plugins/link/menu/hover-link-dialog.js +4 -4
- package/dist/basic-sdk/extension/plugins/table/constants/index.js +7 -1
- package/dist/basic-sdk/extension/plugins/table/helpers.js +216 -2
- package/dist/basic-sdk/extension/plugins/table/menu/active-table-menu/index.js +10 -10
- package/dist/basic-sdk/extension/plugins/table/menu/context-menu/index.js +18 -6
- package/dist/basic-sdk/extension/plugins/table/menu/context-menu/insert-table-element.js +1 -1
- package/dist/basic-sdk/extension/plugins/table/plugin.js +64 -256
- package/dist/basic-sdk/extension/plugins/table/render/context.js +5 -0
- package/dist/basic-sdk/extension/plugins/table/render/render-cell.js +35 -16
- package/dist/basic-sdk/extension/plugins/table/render/render-row.js +7 -16
- package/dist/basic-sdk/extension/plugins/table/render/render-table/index.css +34 -0
- package/dist/basic-sdk/extension/plugins/table/render/render-table/index.js +81 -28
- package/dist/basic-sdk/node-id/helpers.js +6 -9
- package/dist/constants/index.js +2 -1
- package/package.json +2 -1
- package/public/locales/en/sdoc-editor.json +3 -8
- package/public/locales/zh-CN/sdoc-editor.json +5 -5
- 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 +4 -0
package/dist/basic-sdk/editor.js
CHANGED
|
@@ -9,6 +9,9 @@ import withNodeId from './node-id';
|
|
|
9
9
|
import SDocOutline from './outline';
|
|
10
10
|
import EventProxy from './utils/event-handler';
|
|
11
11
|
import { useCursors } from './cursor/use-cursors';
|
|
12
|
+
import EventBus from './utils/event-bus';
|
|
13
|
+
import { EXTERNAL_EVENT } from '../constants';
|
|
14
|
+
import { isAllInTable } from './extension/plugins/table/helpers';
|
|
12
15
|
import './assets/css/layout.css';
|
|
13
16
|
import './assets/css/sdoc-editor-plugins.css';
|
|
14
17
|
var SDocEditor = function SDocEditor(_ref) {
|
|
@@ -45,6 +48,7 @@ var SDocEditor = function SDocEditor(_ref) {
|
|
|
45
48
|
var eventProxy = useMemo(function () {
|
|
46
49
|
return new EventProxy(editor);
|
|
47
50
|
}, []);
|
|
51
|
+
var eventBus = EventBus.getInstance();
|
|
48
52
|
|
|
49
53
|
// useMount: init socket connection
|
|
50
54
|
useEffect(function () {
|
|
@@ -64,7 +68,7 @@ var SDocEditor = function SDocEditor(_ref) {
|
|
|
64
68
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
65
69
|
}, []);
|
|
66
70
|
var onContextMenu = useCallback(function (event) {
|
|
67
|
-
if (
|
|
71
|
+
if (isAllInTable(editor)) {
|
|
68
72
|
event.preventDefault();
|
|
69
73
|
var contextMenuPosition = {
|
|
70
74
|
left: event.clientX,
|
|
@@ -80,6 +84,12 @@ var SDocEditor = function SDocEditor(_ref) {
|
|
|
80
84
|
setContextMenu(false);
|
|
81
85
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
82
86
|
}, []);
|
|
87
|
+
var onMouseDown = useCallback(function (event) {
|
|
88
|
+
if (event.button === 0) {
|
|
89
|
+
eventBus.dispatch(EXTERNAL_EVENT.CANCEL_TABLE_SELECT_RANGE);
|
|
90
|
+
}
|
|
91
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
92
|
+
}, []);
|
|
83
93
|
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
|
|
84
94
|
className: "sdoc-editor-container"
|
|
85
95
|
}, /*#__PURE__*/React.createElement(Toolbar, {
|
|
@@ -102,7 +112,8 @@ var SDocEditor = function SDocEditor(_ref) {
|
|
|
102
112
|
renderLeaf: renderLeaf,
|
|
103
113
|
onKeyDown: eventProxy.onKeyDown,
|
|
104
114
|
cursors: cursors,
|
|
105
|
-
onContextMenu: onContextMenu
|
|
115
|
+
onContextMenu: onContextMenu,
|
|
116
|
+
onMouseDown: onMouseDown
|
|
106
117
|
})))))), isShowContextMenu && /*#__PURE__*/React.createElement(ContextMenu, {
|
|
107
118
|
editor: editor,
|
|
108
119
|
contextMenuPosition: menuPosition
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
2
|
-
var _MENUS_CONFIG_MAP, _HEADER_TITLE_MAP;
|
|
2
|
+
var _MENUS_CONFIG_MAP, _HEADER_TITLE_MAP, _TABLE_ELEMENT_SPAN;
|
|
3
3
|
// extension plugin
|
|
4
4
|
import * as ELEMENT_TYPE from './element-type';
|
|
5
5
|
import { BLOCKQUOTE, HEADER, HEADER1, HEADER2, HEADER3, HEADER4, HEADER5, HEADER6, PARAGRAPH, BOLD, ITALIC, UNDERLINE, STRIKETHROUGH, ORDERED_LIST, UNORDERED_LIST, LIST_ITEM, LIST_LIC, CHECK_LIST, CHECK_LIST_ITEM, LINK, HTML, CODE_BLOCK, CODE_LINE, IMAGE, TABLE, TABLE_CELL, TABLE_ROW, FORMULA, COLUMN, TEXT_STYLE, BOLD_ITALIC } from './element-type';
|
|
@@ -96,6 +96,7 @@ export var TABLE_ELEMENT = {
|
|
|
96
96
|
COLUMN: 'column',
|
|
97
97
|
CELL: 'cell'
|
|
98
98
|
};
|
|
99
|
+
export var TABLE_ELEMENT_SPAN = (_TABLE_ELEMENT_SPAN = {}, _defineProperty(_TABLE_ELEMENT_SPAN, TABLE_ELEMENT.TABLE, 'table'), _defineProperty(_TABLE_ELEMENT_SPAN, TABLE_ELEMENT.ROW, 'tr'), _defineProperty(_TABLE_ELEMENT_SPAN, TABLE_ELEMENT.CELL, 'td'), _TABLE_ELEMENT_SPAN);
|
|
99
100
|
export var TABLE_ELEMENT_POSITION = {
|
|
100
101
|
AFTER: 'after',
|
|
101
102
|
BEFORE: 'before'
|
|
@@ -5,6 +5,7 @@ import _createSuper from "@babel/runtime/helpers/esm/createSuper";
|
|
|
5
5
|
import React, { Component } from 'react';
|
|
6
6
|
import ModalPortal from '../../../../components/modal-portal';
|
|
7
7
|
import { TablePlugin } from '../../plugins';
|
|
8
|
+
import { isAllInTable } from '../../plugins/table/helpers';
|
|
8
9
|
var ContextMenu = /*#__PURE__*/function (_Component) {
|
|
9
10
|
_inherits(ContextMenu, _Component);
|
|
10
11
|
var _super = _createSuper(ContextMenu);
|
|
@@ -17,7 +18,7 @@ var ContextMenu = /*#__PURE__*/function (_Component) {
|
|
|
17
18
|
_this = _super.call.apply(_super, [this].concat(args));
|
|
18
19
|
_this.renderContextMenu = function () {
|
|
19
20
|
var editor = _this.props.editor;
|
|
20
|
-
if (
|
|
21
|
+
if (isAllInTable(editor)) {
|
|
21
22
|
var ContextMenuComponent = TablePlugin.contextMenu;
|
|
22
23
|
return /*#__PURE__*/React.createElement(ContextMenuComponent, _this.props);
|
|
23
24
|
}
|
|
@@ -34,15 +34,15 @@ var LinkHoverComponent = /*#__PURE__*/function (_React$Component) {
|
|
|
34
34
|
}, /*#__PURE__*/React.createElement("span", {
|
|
35
35
|
role: "button",
|
|
36
36
|
className: "link-op-icon",
|
|
37
|
-
onClick: this.props.
|
|
37
|
+
onClick: this.props.onEditLink
|
|
38
38
|
}, /*#__PURE__*/React.createElement("i", {
|
|
39
|
-
className: "sdocfont sdoc-
|
|
39
|
+
className: "sdocfont sdoc-rename"
|
|
40
40
|
})), /*#__PURE__*/React.createElement("span", {
|
|
41
41
|
role: "button",
|
|
42
42
|
className: "link-op-icon",
|
|
43
|
-
onClick: this.props.
|
|
43
|
+
onClick: this.props.onDeleteLink
|
|
44
44
|
}, /*#__PURE__*/React.createElement("i", {
|
|
45
|
-
className: "sdocfont sdoc-
|
|
45
|
+
className: "sdocfont sdoc-unlink"
|
|
46
46
|
}))), /*#__PURE__*/React.createElement("span", {
|
|
47
47
|
className: "link-op-menu-triangle"
|
|
48
48
|
})), document.body));
|
|
@@ -1,8 +1,15 @@
|
|
|
1
|
+
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
|
2
|
+
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
1
3
|
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
2
4
|
import slugid from 'slugid';
|
|
3
5
|
import { Editor, Range, Transforms } from '@seafile/slate';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
+
import { getNodeType, getParentNode, getSelectedNodeByType, isTextNode, getSelectedElems, replaceNodeChildren, focusEditor } from '../../core';
|
|
7
|
+
import { getNodePathById } from '../../../socket/helpers';
|
|
8
|
+
import { ELEMENT_TYPE, TABLE_ELEMENT, TABLE_ELEMENT_POSITION } from '../../constants';
|
|
9
|
+
import { TABLE_MAX_ROWS, TABLE_MAX_COLUMNS, EMPTY_SELECTED_RANGE } from './constants';
|
|
10
|
+
import EventBus from '../../../utils/event-bus';
|
|
11
|
+
import { EXTERNAL_EVENT } from '../../../../constants';
|
|
12
|
+
import ObjectUtils from '../../../utils/object-utils';
|
|
6
13
|
export var isTableMenuDisabled = function isTableMenuDisabled(editor) {
|
|
7
14
|
var selection = editor.selection;
|
|
8
15
|
if (selection === null) return true;
|
|
@@ -78,4 +85,211 @@ export var insertTable = function insertTable(editor, size, selection) {
|
|
|
78
85
|
Transforms.insertNodes(editor, tableNode, {
|
|
79
86
|
at: selection
|
|
80
87
|
});
|
|
88
|
+
};
|
|
89
|
+
export var getSelectedInfo = function getSelectedInfo(editor) {
|
|
90
|
+
var currentTable = getSelectedNodeByType(editor, ELEMENT_TYPE.TABLE);
|
|
91
|
+
var currentRow = getSelectedNodeByType(editor, ELEMENT_TYPE.TABLE_ROW);
|
|
92
|
+
var currentCell = getSelectedNodeByType(editor, ELEMENT_TYPE.TABLE_CELL);
|
|
93
|
+
var currentCellPath = getNodePathById(editor, currentCell.id);
|
|
94
|
+
return {
|
|
95
|
+
table: currentTable,
|
|
96
|
+
tablePath: getNodePathById(editor, currentTable.id),
|
|
97
|
+
tableSize: [currentTable.children.length, currentRow.children.length],
|
|
98
|
+
row: currentRow,
|
|
99
|
+
rowPath: getNodePathById(editor, currentRow.id),
|
|
100
|
+
rowIndex: currentCellPath[currentCellPath.length - 2],
|
|
101
|
+
cell: currentCell,
|
|
102
|
+
cellPath: getNodePathById(editor, currentCell.id),
|
|
103
|
+
cellIndex: currentCellPath[currentCellPath.length - 1]
|
|
104
|
+
};
|
|
105
|
+
};
|
|
106
|
+
export var isInTable = function isInTable(editor) {
|
|
107
|
+
var selectedNodes = getSelectedElems(editor);
|
|
108
|
+
if (!selectedNodes.some(function (node) {
|
|
109
|
+
return node.type === ELEMENT_TYPE.TABLE;
|
|
110
|
+
})) return false;
|
|
111
|
+
var firstSelectedNode = selectedNodes[0];
|
|
112
|
+
return firstSelectedNode.type === ELEMENT_TYPE.TABLE;
|
|
113
|
+
};
|
|
114
|
+
export var isAllInTable = function isAllInTable(editor) {
|
|
115
|
+
var selectedNodes = getSelectedElems(editor);
|
|
116
|
+
if (!selectedNodes.some(function (node) {
|
|
117
|
+
return node.type === ELEMENT_TYPE.TABLE;
|
|
118
|
+
})) return false;
|
|
119
|
+
var firstSelectedNode = selectedNodes[0];
|
|
120
|
+
if (firstSelectedNode.type !== ELEMENT_TYPE.TABLE) return false;
|
|
121
|
+
return selectedNodes.slice(1).every(function (node) {
|
|
122
|
+
return [ELEMENT_TYPE.TABLE_ROW, ELEMENT_TYPE.TABLE_CELL].includes(node.type);
|
|
123
|
+
}); // same table element
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
export var setTextStyle = function setTextStyle(editor, style) {
|
|
127
|
+
var selectedNodes = getSelectedElems(editor);
|
|
128
|
+
var firstTableCellNodePath;
|
|
129
|
+
selectedNodes.forEach(function (node) {
|
|
130
|
+
if (node.type === ELEMENT_TYPE.TABLE_CELL) {
|
|
131
|
+
var targetNode = node.children[0];
|
|
132
|
+
var path = getNodePathById(editor, node.id);
|
|
133
|
+
firstTableCellNodePath = firstTableCellNodePath ? firstTableCellNodePath : path;
|
|
134
|
+
replaceNodeChildren(editor, {
|
|
135
|
+
at: path,
|
|
136
|
+
nodes: _objectSpread(_objectSpread({}, targetNode), style)
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
if (firstTableCellNodePath) {
|
|
141
|
+
var start = Editor.start(editor, firstTableCellNodePath);
|
|
142
|
+
var end = Editor.end(editor, firstTableCellNodePath);
|
|
143
|
+
var newSelection = {
|
|
144
|
+
anchor: start,
|
|
145
|
+
focus: end
|
|
146
|
+
};
|
|
147
|
+
Transforms.select(editor, newSelection);
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
export var insertTableElement = function insertTableElement(editor, type) {
|
|
151
|
+
var position = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : TABLE_ELEMENT_POSITION.AFTER;
|
|
152
|
+
var count = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 1;
|
|
153
|
+
var _getSelectedInfo = getSelectedInfo(editor),
|
|
154
|
+
tablePath = _getSelectedInfo.tablePath,
|
|
155
|
+
tableSize = _getSelectedInfo.tableSize,
|
|
156
|
+
rowIndex = _getSelectedInfo.rowIndex,
|
|
157
|
+
cellIndex = _getSelectedInfo.cellIndex;
|
|
158
|
+
var eventBus = EventBus.getInstance();
|
|
159
|
+
eventBus.dispatch(EXTERNAL_EVENT.CANCEL_TABLE_SELECT_RANGE);
|
|
160
|
+
if (type === TABLE_ELEMENT.ROW) {
|
|
161
|
+
if (tableSize[0] >= TABLE_MAX_ROWS) return;
|
|
162
|
+
var targetPath = position === TABLE_ELEMENT_POSITION.AFTER ? [].concat(_toConsumableArray(tablePath), [rowIndex + 1]) : [].concat(_toConsumableArray(tablePath), [rowIndex]);
|
|
163
|
+
var validCount = Math.min(TABLE_MAX_ROWS - tableSize[0], count);
|
|
164
|
+
for (var i = 0; i < validCount; i++) {
|
|
165
|
+
var row = generateTableRow(tableSize[1]);
|
|
166
|
+
Transforms.insertNodes(editor, row, {
|
|
167
|
+
at: targetPath
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
var focusPath = [].concat(_toConsumableArray(targetPath), [cellIndex]);
|
|
171
|
+
focusEditor(editor, focusPath);
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
if (type === TABLE_ELEMENT.COLUMN) {
|
|
175
|
+
if (tableSize[1] >= TABLE_MAX_COLUMNS) return;
|
|
176
|
+
var newCellIndex = position === TABLE_ELEMENT_POSITION.AFTER ? cellIndex + 1 : cellIndex;
|
|
177
|
+
var _validCount = Math.min(TABLE_MAX_COLUMNS - tableSize[1], count);
|
|
178
|
+
for (var j = 0; j < _validCount; j++) {
|
|
179
|
+
for (var _i = 0; _i < tableSize[0]; _i++) {
|
|
180
|
+
var newCellPath = [].concat(_toConsumableArray(tablePath), [_i, newCellIndex]);
|
|
181
|
+
var newCell = generateTableCell();
|
|
182
|
+
Transforms.insertNodes(editor, newCell, {
|
|
183
|
+
at: newCellPath
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
var _focusPath = [].concat(_toConsumableArray(tablePath), [rowIndex, cellIndex + 1, 0]);
|
|
188
|
+
focusEditor(editor, _focusPath);
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
var removeTable = function removeTable(editor, path) {
|
|
193
|
+
var validPath = path;
|
|
194
|
+
if (!validPath) {
|
|
195
|
+
var _getSelectedInfo2 = getSelectedInfo(editor),
|
|
196
|
+
tablePath = _getSelectedInfo2.tablePath;
|
|
197
|
+
validPath = tablePath;
|
|
198
|
+
}
|
|
199
|
+
var tableIndex = validPath[validPath.length - 1];
|
|
200
|
+
var tableParentPath = validPath.slice(0, validPath.length - 1);
|
|
201
|
+
var targetNodeIndex = tableIndex >= 1 ? tableIndex - 1 : 1;
|
|
202
|
+
var targetNodePath = [].concat(_toConsumableArray(tableParentPath), [targetNodeIndex]);
|
|
203
|
+
Transforms.removeNodes(editor, {
|
|
204
|
+
at: path
|
|
205
|
+
});
|
|
206
|
+
focusEditor(editor, targetNodePath);
|
|
207
|
+
};
|
|
208
|
+
export var removeTableElement = function removeTableElement(editor, type) {
|
|
209
|
+
var _getSelectedInfo3 = getSelectedInfo(editor),
|
|
210
|
+
tablePath = _getSelectedInfo3.tablePath,
|
|
211
|
+
tableSize = _getSelectedInfo3.tableSize,
|
|
212
|
+
rowPath = _getSelectedInfo3.rowPath,
|
|
213
|
+
rowIndex = _getSelectedInfo3.rowIndex,
|
|
214
|
+
cellIndex = _getSelectedInfo3.cellIndex;
|
|
215
|
+
var eventBus = EventBus.getInstance();
|
|
216
|
+
eventBus.dispatch(EXTERNAL_EVENT.CANCEL_TABLE_SELECT_RANGE);
|
|
217
|
+
if (type === TABLE_ELEMENT.TABLE) {
|
|
218
|
+
removeTable(editor, tablePath);
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
221
|
+
if (type === TABLE_ELEMENT.ROW) {
|
|
222
|
+
if (tableSize[0] === 1) {
|
|
223
|
+
removeTable(editor, tablePath);
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
226
|
+
if (!ObjectUtils.isSameObject(editor.tableSelectedRange, EMPTY_SELECTED_RANGE)) {
|
|
227
|
+
var _editor$tableSelected = editor.tableSelectedRange,
|
|
228
|
+
minRowIndex = _editor$tableSelected.minRowIndex,
|
|
229
|
+
maxRowIndex = _editor$tableSelected.maxRowIndex;
|
|
230
|
+
if (minRowIndex === 0 && maxRowIndex === tableSize[0] - 1) {
|
|
231
|
+
removeTable(editor, tablePath);
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
234
|
+
for (var i = minRowIndex; i <= maxRowIndex; i++) {
|
|
235
|
+
Transforms.removeNodes(editor, {
|
|
236
|
+
at: [].concat(_toConsumableArray(tablePath), [minRowIndex])
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
var _focusPath2 = [].concat(_toConsumableArray(tablePath), [minRowIndex === 0 ? 0 : minRowIndex - 1, cellIndex]);
|
|
240
|
+
focusEditor(editor, _focusPath2);
|
|
241
|
+
return;
|
|
242
|
+
}
|
|
243
|
+
Transforms.removeNodes(editor, {
|
|
244
|
+
at: rowPath
|
|
245
|
+
});
|
|
246
|
+
var focusRowIndex = rowIndex === tableSize[0] - 1 ? rowIndex - 1 : rowIndex;
|
|
247
|
+
var focusPath = [].concat(_toConsumableArray(tablePath), [focusRowIndex, cellIndex]);
|
|
248
|
+
focusEditor(editor, focusPath);
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
251
|
+
if (type === TABLE_ELEMENT.COLUMN) {
|
|
252
|
+
if (tableSize[1] === 1) {
|
|
253
|
+
removeTable(editor, tablePath);
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
if (!ObjectUtils.isSameObject(editor.tableSelectedRange, EMPTY_SELECTED_RANGE)) {
|
|
257
|
+
var _editor$tableSelected2 = editor.tableSelectedRange,
|
|
258
|
+
minColIndex = _editor$tableSelected2.minColIndex,
|
|
259
|
+
maxColIndex = _editor$tableSelected2.maxColIndex;
|
|
260
|
+
if (minColIndex === 0 && maxColIndex === tableSize[1] - 1) {
|
|
261
|
+
removeTable(editor, tablePath);
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
264
|
+
for (var _i2 = 0; _i2 < tableSize[0]; _i2++) {
|
|
265
|
+
for (var j = minColIndex; j <= maxColIndex; j++) {
|
|
266
|
+
// count
|
|
267
|
+
var cellPath = [].concat(_toConsumableArray(tablePath), [_i2, minColIndex]);
|
|
268
|
+
Transforms.removeNodes(editor, {
|
|
269
|
+
at: cellPath
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
var _focusPath3 = [].concat(_toConsumableArray(tablePath), [rowIndex, minColIndex === 0 ? 0 : minColIndex - 1]);
|
|
274
|
+
focusEditor(editor, _focusPath3);
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
277
|
+
for (var _i3 = 0; _i3 < tableSize[0]; _i3++) {
|
|
278
|
+
var _cellPath = [].concat(_toConsumableArray(tablePath), [_i3, cellIndex]);
|
|
279
|
+
Transforms.removeNodes(editor, {
|
|
280
|
+
at: _cellPath
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
var focusCellIndex = cellIndex === tableSize[1] - 1 ? cellIndex - 1 : cellIndex;
|
|
284
|
+
var _focusPath4 = [].concat(_toConsumableArray(tablePath), [rowIndex, focusCellIndex]);
|
|
285
|
+
focusEditor(editor, _focusPath4);
|
|
286
|
+
return;
|
|
287
|
+
}
|
|
288
|
+
};
|
|
289
|
+
export var setTableSelectedRange = function setTableSelectedRange(editor, range) {
|
|
290
|
+
if (range) {
|
|
291
|
+
editor.tableSelectedRange = range;
|
|
292
|
+
return;
|
|
293
|
+
}
|
|
294
|
+
editor.tableSelectedRange = EMPTY_SELECTED_RANGE;
|
|
81
295
|
};
|
|
@@ -9,6 +9,7 @@ import { withTranslation } from 'react-i18next';
|
|
|
9
9
|
import { MenuGroup, MenuItem } from '../../../../menu';
|
|
10
10
|
import CommonMenu from './common-menu';
|
|
11
11
|
import { TABLE_ELEMENT, MENUS_CONFIG_MAP, REMOVE_TABLE } from '../../../../constants';
|
|
12
|
+
import { setTextStyle, insertTableElement, removeTableElement, isAllInTable } from '../../helpers';
|
|
12
13
|
import './index.css';
|
|
13
14
|
var ActiveTableMenu = /*#__PURE__*/function (_Component) {
|
|
14
15
|
_inherits(ActiveTableMenu, _Component);
|
|
@@ -22,14 +23,14 @@ var ActiveTableMenu = /*#__PURE__*/function (_Component) {
|
|
|
22
23
|
_this = _super.call.apply(_super, [this].concat(args));
|
|
23
24
|
_this.setTextAlignStyle = function (textAlign) {
|
|
24
25
|
var editor = _this.props.editor;
|
|
25
|
-
|
|
26
|
+
setTextStyle(editor, {
|
|
26
27
|
textAlign: textAlign
|
|
27
28
|
});
|
|
28
29
|
_this.textAlignRef.hidePopover();
|
|
29
30
|
};
|
|
30
31
|
_this.insertTableElement = function (type) {
|
|
31
32
|
var editor = _this.props.editor;
|
|
32
|
-
|
|
33
|
+
insertTableElement(editor, type);
|
|
33
34
|
if (type === TABLE_ELEMENT.ROW) {
|
|
34
35
|
_this.tableRowRef.hidePopover();
|
|
35
36
|
return;
|
|
@@ -38,7 +39,7 @@ var ActiveTableMenu = /*#__PURE__*/function (_Component) {
|
|
|
38
39
|
};
|
|
39
40
|
_this.removeTableElement = function (type) {
|
|
40
41
|
var editor = _this.props.editor;
|
|
41
|
-
|
|
42
|
+
removeTableElement(editor, type);
|
|
42
43
|
if (type === TABLE_ELEMENT.ROW) {
|
|
43
44
|
_this.tableRowRef.hidePopover();
|
|
44
45
|
return;
|
|
@@ -47,7 +48,7 @@ var ActiveTableMenu = /*#__PURE__*/function (_Component) {
|
|
|
47
48
|
};
|
|
48
49
|
_this.removeTable = function () {
|
|
49
50
|
var editor = _this.props.editor;
|
|
50
|
-
|
|
51
|
+
removeTableElement(editor, TABLE_ELEMENT.TABLE);
|
|
51
52
|
};
|
|
52
53
|
_this.renderTextAlign = function () {
|
|
53
54
|
var t = _this.props.t;
|
|
@@ -85,10 +86,10 @@ var ActiveTableMenu = /*#__PURE__*/function (_Component) {
|
|
|
85
86
|
}, /*#__PURE__*/React.createElement("button", {
|
|
86
87
|
className: "dropdown-item",
|
|
87
88
|
onClick: _this.insertTableElement.bind(_assertThisInitialized(_this), TABLE_ELEMENT.COLUMN)
|
|
88
|
-
}, t('
|
|
89
|
+
}, t('Insert_column')), /*#__PURE__*/React.createElement("button", {
|
|
89
90
|
className: "dropdown-item",
|
|
90
91
|
onClick: _this.removeTableElement.bind(_assertThisInitialized(_this), TABLE_ELEMENT.COLUMN)
|
|
91
|
-
}, t('
|
|
92
|
+
}, t('Remove_column')));
|
|
92
93
|
};
|
|
93
94
|
_this.renderTableRow = function () {
|
|
94
95
|
var t = _this.props.t;
|
|
@@ -101,10 +102,10 @@ var ActiveTableMenu = /*#__PURE__*/function (_Component) {
|
|
|
101
102
|
}, /*#__PURE__*/React.createElement("button", {
|
|
102
103
|
className: "dropdown-item",
|
|
103
104
|
onClick: _this.insertTableElement.bind(_assertThisInitialized(_this), TABLE_ELEMENT.ROW)
|
|
104
|
-
}, t('
|
|
105
|
+
}, t('Insert_row')), /*#__PURE__*/React.createElement("button", {
|
|
105
106
|
className: "dropdown-item",
|
|
106
107
|
onClick: _this.removeTableElement.bind(_assertThisInitialized(_this), TABLE_ELEMENT.ROW)
|
|
107
|
-
}, t('
|
|
108
|
+
}, t('Remove_row')));
|
|
108
109
|
};
|
|
109
110
|
return _this;
|
|
110
111
|
}
|
|
@@ -115,8 +116,7 @@ var ActiveTableMenu = /*#__PURE__*/function (_Component) {
|
|
|
115
116
|
editor = _this$props.editor,
|
|
116
117
|
isRichEditor = _this$props.isRichEditor,
|
|
117
118
|
className = _this$props.className;
|
|
118
|
-
|
|
119
|
-
if (!isAllInTable) return null;
|
|
119
|
+
if (!isAllInTable(editor)) return null;
|
|
120
120
|
var menuConfig = MENUS_CONFIG_MAP[REMOVE_TABLE];
|
|
121
121
|
var props = _objectSpread(_objectSpread({
|
|
122
122
|
isRichEditor: isRichEditor,
|
|
@@ -9,6 +9,8 @@ import ObjectUtils from '../../../../../utils/object-utils';
|
|
|
9
9
|
import { TABLE_ELEMENT, TABLE_ELEMENT_POSITION, ELEMENT_TYPE } from '../../../../constants';
|
|
10
10
|
import InsertTableElement from './insert-table-element';
|
|
11
11
|
import { getSelectedNodeByType } from '../../../../core';
|
|
12
|
+
import { TABLE_MAX_COLUMNS, TABLE_MAX_ROWS } from '../../constants';
|
|
13
|
+
import { insertTableElement, removeTableElement } from '../../helpers';
|
|
12
14
|
import './index.css';
|
|
13
15
|
var ContextMenu = /*#__PURE__*/function (_React$Component) {
|
|
14
16
|
_inherits(ContextMenu, _React$Component);
|
|
@@ -21,9 +23,10 @@ var ContextMenu = /*#__PURE__*/function (_React$Component) {
|
|
|
21
23
|
var menuHeight = _this.menu.offsetHeight;
|
|
22
24
|
|
|
23
25
|
// get height of context menu when the menu is drawing completed in this page
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
26
|
+
if (menuHeight === 0) {
|
|
27
|
+
requestAnimationFrame(_this.updateMenuPosition);
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
27
30
|
var top = 0;
|
|
28
31
|
if (_this.position.top + menuHeight > document.body.clientHeight) {
|
|
29
32
|
top = document.body.clientHeight - menuHeight - 5;
|
|
@@ -40,11 +43,11 @@ var ContextMenu = /*#__PURE__*/function (_React$Component) {
|
|
|
40
43
|
};
|
|
41
44
|
_this.insertTableElement = function (type, position, count) {
|
|
42
45
|
var editor = _this.props.editor;
|
|
43
|
-
|
|
46
|
+
insertTableElement(editor, type, position, count);
|
|
44
47
|
};
|
|
45
48
|
_this.removeTableElement = function (type) {
|
|
46
49
|
var editor = _this.props.editor;
|
|
47
|
-
|
|
50
|
+
removeTableElement(editor, type);
|
|
48
51
|
};
|
|
49
52
|
_this.renderRemoveBtn = function (type, title) {
|
|
50
53
|
return /*#__PURE__*/React.createElement("button", {
|
|
@@ -88,6 +91,11 @@ var ContextMenu = /*#__PURE__*/function (_React$Component) {
|
|
|
88
91
|
var currentRow = getSelectedNodeByType(editor, ELEMENT_TYPE.TABLE_ROW);
|
|
89
92
|
var currentRowsCount = currentTable.children.length;
|
|
90
93
|
var currentColumnsCount = currentRow.children.length;
|
|
94
|
+
var tableSelectedRange = editor.tableSelectedRange;
|
|
95
|
+
var selectedRows = tableSelectedRange.maxRowIndex - tableSelectedRange.minRowIndex + 1;
|
|
96
|
+
var selectedCols = tableSelectedRange.maxColIndex - tableSelectedRange.minColIndex + 1;
|
|
97
|
+
var canAddRowsCount = currentRowsCount + selectedRows > TABLE_MAX_ROWS ? TABLE_MAX_ROWS - currentRowsCount : selectedRows;
|
|
98
|
+
var canAddColsCount = currentColumnsCount + selectedCols > TABLE_MAX_COLUMNS ? TABLE_MAX_COLUMNS - currentColumnsCount : selectedCols;
|
|
91
99
|
return /*#__PURE__*/React.createElement("div", {
|
|
92
100
|
style: contextStyle,
|
|
93
101
|
ref: function ref(_ref) {
|
|
@@ -96,27 +104,31 @@ var ContextMenu = /*#__PURE__*/function (_React$Component) {
|
|
|
96
104
|
className: "sdoc-table-context-menu dropdown-menu"
|
|
97
105
|
}, /*#__PURE__*/React.createElement(InsertTableElement, {
|
|
98
106
|
type: TABLE_ELEMENT.ROW,
|
|
107
|
+
count: canAddRowsCount,
|
|
99
108
|
currentCount: currentRowsCount,
|
|
100
109
|
position: TABLE_ELEMENT_POSITION.BEFORE,
|
|
101
110
|
insertTableElement: this.insertTableElement
|
|
102
111
|
}), /*#__PURE__*/React.createElement(InsertTableElement, {
|
|
103
112
|
type: TABLE_ELEMENT.ROW,
|
|
113
|
+
count: canAddRowsCount,
|
|
104
114
|
currentCount: currentRowsCount,
|
|
105
115
|
position: TABLE_ELEMENT_POSITION.AFTER,
|
|
106
116
|
insertTableElement: this.insertTableElement
|
|
107
117
|
}), /*#__PURE__*/React.createElement(InsertTableElement, {
|
|
108
118
|
type: TABLE_ELEMENT.COLUMN,
|
|
119
|
+
count: canAddColsCount,
|
|
109
120
|
currentCount: currentColumnsCount,
|
|
110
121
|
position: TABLE_ELEMENT_POSITION.BEFORE,
|
|
111
122
|
insertTableElement: this.insertTableElement
|
|
112
123
|
}), /*#__PURE__*/React.createElement(InsertTableElement, {
|
|
113
124
|
type: TABLE_ELEMENT.COLUMN,
|
|
125
|
+
count: canAddColsCount,
|
|
114
126
|
currentCount: currentColumnsCount,
|
|
115
127
|
position: TABLE_ELEMENT_POSITION.AFTER,
|
|
116
128
|
insertTableElement: this.insertTableElement
|
|
117
129
|
}), /*#__PURE__*/React.createElement("div", {
|
|
118
130
|
className: 'seafile-divider dropdown-divider'
|
|
119
|
-
}), this.renderRemoveBtn(TABLE_ELEMENT.ROW, '
|
|
131
|
+
}), this.renderRemoveBtn(TABLE_ELEMENT.ROW, 'Remove_row'), this.renderRemoveBtn(TABLE_ELEMENT.COLUMN, 'Remove_column'), this.renderRemoveBtn(TABLE_ELEMENT.TABLE, 'Remove_table'));
|
|
120
132
|
}
|
|
121
133
|
}]);
|
|
122
134
|
return ContextMenu;
|