@seafile/sdoc-editor 0.3.21 → 0.3.22
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/sdoc-editor-plugins.css +4 -0
- package/dist/basic-sdk/extension/plugins/list/render-elem.js +5 -1
- package/dist/basic-sdk/extension/plugins/table/constants/index.js +3 -1
- package/dist/basic-sdk/extension/plugins/table/helpers.js +106 -34
- package/dist/basic-sdk/extension/plugins/table/menu/table-context-menu/index.js +13 -2
- package/dist/basic-sdk/extension/plugins/table/menu/table-menu/index.js +3 -2
- package/dist/basic-sdk/extension/plugins/table/plugin.js +0 -1
- package/dist/basic-sdk/extension/plugins/table/render/render-cell.js +4 -1
- package/dist/components/tooltip/index.css +4 -0
- package/package.json +1 -1
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
+
import classnames from 'classnames';
|
|
2
3
|
import { ORDERED_LIST } from '../../constants';
|
|
3
4
|
const renderList = (props, editor) => {
|
|
4
5
|
const {
|
|
@@ -33,11 +34,14 @@ const renderListItem = (props, editor) => {
|
|
|
33
34
|
default:
|
|
34
35
|
className = '';
|
|
35
36
|
}
|
|
37
|
+
const isBlod = element.children[0].children.every(item => item.bold === true);
|
|
36
38
|
return /*#__PURE__*/React.createElement("li", Object.assign({
|
|
37
39
|
"data-id": element.id,
|
|
38
40
|
"data-root": "true"
|
|
39
41
|
}, attributes, {
|
|
40
|
-
className: className
|
|
42
|
+
className: classnames(className, {
|
|
43
|
+
'sdoc-li-blod': isBlod
|
|
44
|
+
})
|
|
41
45
|
}), children);
|
|
42
46
|
};
|
|
43
47
|
const renderListLic = (props, editor) => {
|
|
@@ -36,4 +36,6 @@ export const TABLE_ALTERNATE_HIGHLIGHT_CLASS_MAP = {
|
|
|
36
36
|
'#2367f2': 'sdoc-table-2367f2',
|
|
37
37
|
'#f77d21': 'sdoc-table-f77d21',
|
|
38
38
|
'#0099f4': 'sdoc-table-0099f4'
|
|
39
|
-
};
|
|
39
|
+
};
|
|
40
|
+
export const INHERIT_CELL_STYLE_WHEN_SELECT_SINGLE = ['background_color'];
|
|
41
|
+
export const INHERIT_CELL_STYLE_WHEN_SELECT_MULTIPLE = ['background_color', 'text_align'];
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
2
2
|
import slugid from 'slugid';
|
|
3
|
-
import { Editor, Range, Transforms, Point, Node } from '@seafile/slate';
|
|
3
|
+
import { Editor, Range, Transforms, Point, Node, Path } from '@seafile/slate';
|
|
4
4
|
import { ReactEditor } from '@seafile/slate-react';
|
|
5
5
|
import deepCopy from 'deep-copy';
|
|
6
|
-
import { getNodeType, getParentNode, getSelectedNodeByType, isTextNode, getSelectedElems, focusEditor, getNode, findPath, replaceNodeChildren, replaceNode } from '../../core';
|
|
6
|
+
import { getNodeType, getParentNode, getSelectedNodeByType, isTextNode, getSelectedElems, focusEditor, getNode, findPath, replaceNodeChildren, replaceNode, getSelectedNodeEntryByType, getAboveBlockNode } from '../../core';
|
|
7
7
|
import { ELEMENT_TYPE, KEYBOARD, CLIPBOARD_FORMAT_KEY, INSERT_POSITION } from '../../constants';
|
|
8
|
-
import { TABLE_MAX_ROWS, TABLE_MAX_COLUMNS, EMPTY_SELECTED_RANGE, TABLE_ROW_MIN_HEIGHT, TABLE_CELL_MIN_WIDTH, TABLE_ELEMENT, TABLE_ELEMENT_POSITION, TABLE_ROW_STYLE } from './constants';
|
|
8
|
+
import { TABLE_MAX_ROWS, TABLE_MAX_COLUMNS, EMPTY_SELECTED_RANGE, TABLE_ROW_MIN_HEIGHT, TABLE_CELL_MIN_WIDTH, TABLE_ELEMENT, TABLE_ELEMENT_POSITION, TABLE_ROW_STYLE, INHERIT_CELL_STYLE_WHEN_SELECT_MULTIPLE, INHERIT_CELL_STYLE_WHEN_SELECT_SINGLE } from './constants';
|
|
9
9
|
import EventBus from '../../../utils/event-bus';
|
|
10
10
|
import { INTERNAL_EVENT, PAGE_EDIT_AREA_WIDTH } from '../../../constants';
|
|
11
11
|
import ObjectUtils from '../../../utils/object-utils';
|
|
@@ -54,20 +54,28 @@ export const isCombineCellsDisabled = (editor, readonly) => {
|
|
|
54
54
|
}
|
|
55
55
|
return true;
|
|
56
56
|
};
|
|
57
|
-
export const generateTableCell = () => {
|
|
57
|
+
export const generateTableCell = (editor, rowIndex, cellIndex) => {
|
|
58
|
+
let style = {};
|
|
59
|
+
const tableNodeEntry = getSelectedNodeEntryByType(editor, ELEMENT_TYPE.TABLE);
|
|
60
|
+
if (tableNodeEntry && rowIndex !== undefined && cellIndex !== undefined) {
|
|
61
|
+
const [, tablePath] = tableNodeEntry;
|
|
62
|
+
style = getCellInheritStyles(editor, tablePath, rowIndex, cellIndex);
|
|
63
|
+
}
|
|
58
64
|
return {
|
|
59
65
|
id: slugid.nice(),
|
|
60
66
|
type: ELEMENT_TYPE.TABLE_CELL,
|
|
61
67
|
children: [{
|
|
62
68
|
text: '',
|
|
63
69
|
id: slugid.nice()
|
|
64
|
-
}]
|
|
70
|
+
}],
|
|
71
|
+
style,
|
|
72
|
+
inherit_style: style
|
|
65
73
|
};
|
|
66
74
|
};
|
|
67
|
-
export const generateTableRow = colsCount => {
|
|
75
|
+
export const generateTableRow = (editor, colsCount, rowIndex) => {
|
|
68
76
|
let children = [];
|
|
69
77
|
for (let i = 0; i < colsCount; i++) {
|
|
70
|
-
const tableCell = generateTableCell();
|
|
78
|
+
const tableCell = generateTableCell(editor, rowIndex, i);
|
|
71
79
|
children.push(tableCell);
|
|
72
80
|
}
|
|
73
81
|
return {
|
|
@@ -97,7 +105,7 @@ export const generateEmptyTable = (editor, tableProps) => {
|
|
|
97
105
|
const colsCount = size[1];
|
|
98
106
|
let children = [];
|
|
99
107
|
for (let i = 0; i < rowsCount; i++) {
|
|
100
|
-
const tableRow = generateTableRow(colsCount);
|
|
108
|
+
const tableRow = generateTableRow(editor, colsCount, i);
|
|
101
109
|
children.push(tableRow);
|
|
102
110
|
}
|
|
103
111
|
const columnWidth = Math.max(TABLE_CELL_MIN_WIDTH, parseInt(editor.width / colsCount));
|
|
@@ -133,16 +141,10 @@ export const insertTable = function (editor, size, selection) {
|
|
|
133
141
|
});
|
|
134
142
|
const validSelection = selection || editor.selection;
|
|
135
143
|
const path = Editor.path(editor, validSelection);
|
|
136
|
-
|
|
137
|
-
Transforms.insertNodes(editor, tableNode, {
|
|
138
|
-
at: [path[0] + 1]
|
|
139
|
-
});
|
|
140
|
-
return;
|
|
141
|
-
}
|
|
142
|
-
Transforms.insertNodes(editor, tableNode, {
|
|
143
|
-
at: [path[0]]
|
|
144
|
-
});
|
|
144
|
+
handleInsertTable(editor, position, path, tableNode);
|
|
145
145
|
};
|
|
146
|
+
|
|
147
|
+
// tableSize [tableHeight, tableWidth]
|
|
146
148
|
export const getSelectedInfo = editor => {
|
|
147
149
|
const currentTable = getSelectedNodeByType(editor, ELEMENT_TYPE.TABLE);
|
|
148
150
|
const currentRow = getSelectedNodeByType(editor, ELEMENT_TYPE.TABLE_ROW);
|
|
@@ -175,6 +177,7 @@ export const isAllInTable = editor => {
|
|
|
175
177
|
};
|
|
176
178
|
|
|
177
179
|
export const setCellStyle = (editor, style) => {
|
|
180
|
+
// Select single cell
|
|
178
181
|
if (ObjectUtils.isSameObject(editor.tableSelectedRange, EMPTY_SELECTED_RANGE)) {
|
|
179
182
|
const selectedNodes = getSelectedElems(editor);
|
|
180
183
|
let firstTableCellNodePath;
|
|
@@ -184,7 +187,8 @@ export const setCellStyle = (editor, style) => {
|
|
|
184
187
|
if (path) {
|
|
185
188
|
firstTableCellNodePath = firstTableCellNodePath ? firstTableCellNodePath : path;
|
|
186
189
|
Transforms.setNodes(editor, {
|
|
187
|
-
style: _objectSpread(_objectSpread({}, node.style), style)
|
|
190
|
+
style: _objectSpread(_objectSpread({}, node.style), style),
|
|
191
|
+
inherit_style: generateInheritStyle(INHERIT_CELL_STYLE_WHEN_SELECT_SINGLE, style, node)
|
|
188
192
|
}, {
|
|
189
193
|
at: path
|
|
190
194
|
});
|
|
@@ -202,6 +206,7 @@ export const setCellStyle = (editor, style) => {
|
|
|
202
206
|
}
|
|
203
207
|
return;
|
|
204
208
|
}
|
|
209
|
+
// Select multiple cells
|
|
205
210
|
const {
|
|
206
211
|
minColIndex,
|
|
207
212
|
maxColIndex,
|
|
@@ -216,7 +221,8 @@ export const setCellStyle = (editor, style) => {
|
|
|
216
221
|
const path = [...tablePath, i, j];
|
|
217
222
|
const node = getNode(editor, path);
|
|
218
223
|
Transforms.setNodes(editor, {
|
|
219
|
-
style: _objectSpread(_objectSpread({}, node.style), style)
|
|
224
|
+
style: _objectSpread(_objectSpread({}, node.style), style),
|
|
225
|
+
inherit_style: generateInheritStyle(INHERIT_CELL_STYLE_WHEN_SELECT_MULTIPLE, style, node)
|
|
220
226
|
}, {
|
|
221
227
|
at: path
|
|
222
228
|
});
|
|
@@ -228,7 +234,7 @@ export const insertTableRow = function (editor, table, rowIndex) {
|
|
|
228
234
|
const tableRowCount = table.children.length;
|
|
229
235
|
if (tableRowCount >= TABLE_MAX_ROWS) return;
|
|
230
236
|
const tableColumnCount = table.children[0].children.length;
|
|
231
|
-
const row = generateTableRow(tableColumnCount);
|
|
237
|
+
const row = generateTableRow(editor, tableColumnCount, rowIndex);
|
|
232
238
|
const tablePath = findPath(editor, table);
|
|
233
239
|
const targetPath = position === TABLE_ELEMENT_POSITION.AFTER ? [...tablePath, rowIndex + 1] : [...tablePath, rowIndex];
|
|
234
240
|
Transforms.insertNodes(editor, row, {
|
|
@@ -303,7 +309,7 @@ export const insertTableColumn = function (editor, table, columnIndex) {
|
|
|
303
309
|
const tableRowCount = table.children.length;
|
|
304
310
|
for (let i = 0; i < tableRowCount; i++) {
|
|
305
311
|
const newCellPath = [...tablePath, i, newCellIndex];
|
|
306
|
-
const newCell = generateTableCell();
|
|
312
|
+
const newCell = generateTableCell(editor, i, columnIndex);
|
|
307
313
|
Transforms.insertNodes(editor, newCell, {
|
|
308
314
|
at: newCellPath
|
|
309
315
|
});
|
|
@@ -382,7 +388,7 @@ export const insertTableElement = function (editor, type) {
|
|
|
382
388
|
const targetPath = position === TABLE_ELEMENT_POSITION.AFTER ? [...tablePath, rowIndex + 1] : [...tablePath, rowIndex];
|
|
383
389
|
const validCount = Math.min(TABLE_MAX_ROWS - tableSize[0], count);
|
|
384
390
|
for (let i = 0; i < validCount; i++) {
|
|
385
|
-
const row = generateTableRow(tableSize[1]);
|
|
391
|
+
const row = generateTableRow(editor, tableSize[1], rowIndex);
|
|
386
392
|
Transforms.insertNodes(editor, row, {
|
|
387
393
|
at: targetPath
|
|
388
394
|
});
|
|
@@ -406,7 +412,7 @@ export const insertTableElement = function (editor, type) {
|
|
|
406
412
|
for (let j = 0; j < validCount; j++) {
|
|
407
413
|
for (let i = 0; i < tableSize[0]; i++) {
|
|
408
414
|
const newCellPath = [...tablePath, i, newCellIndex];
|
|
409
|
-
const newCell = generateTableCell();
|
|
415
|
+
const newCell = generateTableCell(editor, i, cellIndex);
|
|
410
416
|
Transforms.insertNodes(editor, newCell, {
|
|
411
417
|
at: newCellPath
|
|
412
418
|
});
|
|
@@ -450,7 +456,7 @@ export const combineCells = editor => {
|
|
|
450
456
|
}
|
|
451
457
|
}
|
|
452
458
|
const targetCellPath = [...tablePath, minRowIndex, minColIndex];
|
|
453
|
-
const newCell = generateTableCell();
|
|
459
|
+
const newCell = generateTableCell(editor);
|
|
454
460
|
newCell.children = newCellContent;
|
|
455
461
|
newCell.rowspan = maxRowIndex - minRowIndex + 1;
|
|
456
462
|
newCell.colspan = maxColIndex - minColIndex + 1;
|
|
@@ -494,7 +500,7 @@ export const splitCell = (editor, rowNumber, columnNumber) => {
|
|
|
494
500
|
let newRowSpan = rowspanBase + (i + 1 <= rowspanLeft ? 1 : 0);
|
|
495
501
|
let colspanSum = 0;
|
|
496
502
|
for (let j = 0; j < columnNumber; j++) {
|
|
497
|
-
const newCell = generateTableCell();
|
|
503
|
+
const newCell = generateTableCell(editor);
|
|
498
504
|
let startIndex = (i * columnNumber + j) * dataBlockNumber;
|
|
499
505
|
if (startIndex < cell.children.length) {
|
|
500
506
|
let endIndex = Math.min(startIndex + dataBlockNumber, cell.children.length);
|
|
@@ -661,7 +667,7 @@ export const handleCombinedCellsBeforeDeleteTableRow = (editor, tablePath, table
|
|
|
661
667
|
} else {
|
|
662
668
|
if (rowspan > 1) {
|
|
663
669
|
const targetCellPath = [...tablePath, rowIndex + 1, i];
|
|
664
|
-
const newCell = generateTableCell();
|
|
670
|
+
const newCell = generateTableCell(editor);
|
|
665
671
|
newCell.rowspan = rowspan - 1;
|
|
666
672
|
newCell.colspan = colspan;
|
|
667
673
|
Transforms.removeNodes(editor, {
|
|
@@ -701,7 +707,7 @@ export const handleCombinedCellsBeforeDeleteTableColumn = (editor, tablePath, ta
|
|
|
701
707
|
} else {
|
|
702
708
|
if (colspan > 1) {
|
|
703
709
|
const targetCellPath = [...tablePath, i, columnIndex + 1];
|
|
704
|
-
const newCell = generateTableCell();
|
|
710
|
+
const newCell = generateTableCell(editor);
|
|
705
711
|
newCell.rowspan = rowspan;
|
|
706
712
|
newCell.colspan = colspan - 1;
|
|
707
713
|
Transforms.removeNodes(editor, {
|
|
@@ -878,7 +884,7 @@ export const insertMultipleRowsAndColumns = (editor, rows, columns) => {
|
|
|
878
884
|
const validInsertColumns = insertColumns.slice(0, Math.min(TABLE_MAX_COLUMNS - tableSize[1], columns.length));
|
|
879
885
|
for (let i = 0; i < validInsertRows.length; i++) {
|
|
880
886
|
const insertRow = validInsertRows[i];
|
|
881
|
-
const row = generateTableRow(tableSize[1]);
|
|
887
|
+
const row = generateTableRow(editor, tableSize[1], rowIndex);
|
|
882
888
|
row.style = insertRow.style;
|
|
883
889
|
newTable.children.push(row);
|
|
884
890
|
}
|
|
@@ -887,7 +893,7 @@ export const insertMultipleRowsAndColumns = (editor, rows, columns) => {
|
|
|
887
893
|
}
|
|
888
894
|
for (let j = 0; j < validInsertColumns.length; j++) {
|
|
889
895
|
for (let i = 0; i < tableSize[0] + validInsertRows.length; i++) {
|
|
890
|
-
const newCell = generateTableCell();
|
|
896
|
+
const newCell = generateTableCell(editor);
|
|
891
897
|
newTable.children[i].children.push(newCell);
|
|
892
898
|
}
|
|
893
899
|
}
|
|
@@ -1244,8 +1250,8 @@ export const getRowHeight = (element, rowIndex) => {
|
|
|
1244
1250
|
const rowHeight = style[TABLE_ROW_STYLE.MIN_HEIGHT] || TABLE_ROW_MIN_HEIGHT;
|
|
1245
1251
|
return rowIndex === 0 ? rowHeight + 1 : rowHeight;
|
|
1246
1252
|
};
|
|
1247
|
-
const normalizeTableCell = cell => {
|
|
1248
|
-
if (!cell) return generateTableCell();
|
|
1253
|
+
const normalizeTableCell = (editor, cell) => {
|
|
1254
|
+
if (!cell) return generateTableCell(editor);
|
|
1249
1255
|
let newCell = _objectSpread({
|
|
1250
1256
|
children: [{
|
|
1251
1257
|
text: '',
|
|
@@ -1300,7 +1306,7 @@ export const normalizeTableELement = (editor, element) => {
|
|
|
1300
1306
|
for (let i = 0; i < element.children.length; i++) {
|
|
1301
1307
|
const row = newElement.children[i];
|
|
1302
1308
|
for (let j = 0; j < row.children.length; j++) {
|
|
1303
|
-
row.children[j] = normalizeTableCell(row.children[j]);
|
|
1309
|
+
row.children[j] = normalizeTableCell(editor, row.children[j]);
|
|
1304
1310
|
}
|
|
1305
1311
|
newElement.children[i] = row;
|
|
1306
1312
|
}
|
|
@@ -1314,7 +1320,73 @@ export const insertTableByTemplate = (editor, alternateColor) => {
|
|
|
1314
1320
|
alternate_highlight: true
|
|
1315
1321
|
});
|
|
1316
1322
|
const path = Editor.path(editor, editor.selection);
|
|
1317
|
-
|
|
1318
|
-
|
|
1323
|
+
const insertPosition = getInsertPosition(editor);
|
|
1324
|
+
handleInsertTable(editor, insertPosition, path, tableNode);
|
|
1325
|
+
};
|
|
1326
|
+
|
|
1327
|
+
/**
|
|
1328
|
+
* @param {Editor} editor
|
|
1329
|
+
* @param {InsertPosition} insertPosition
|
|
1330
|
+
* @param {Path} path
|
|
1331
|
+
* @param {Node} tableNode
|
|
1332
|
+
* Insert table by insertPosition
|
|
1333
|
+
*/
|
|
1334
|
+
export const handleInsertTable = (editor, insertPosition, path, tableNode) => {
|
|
1335
|
+
const {
|
|
1336
|
+
selection
|
|
1337
|
+
} = editor;
|
|
1338
|
+
if (insertPosition === INSERT_POSITION.BEFORE) {
|
|
1339
|
+
const insertPath = [path[0]];
|
|
1340
|
+
Transforms.insertNodes(editor, tableNode, {
|
|
1341
|
+
at: insertPath
|
|
1342
|
+
});
|
|
1343
|
+
} else if (insertPosition === INSERT_POSITION.AFTER) {
|
|
1344
|
+
const insertPath = [path[0] + 1];
|
|
1345
|
+
Transforms.insertNodes(editor, tableNode, {
|
|
1346
|
+
at: insertPath
|
|
1347
|
+
});
|
|
1348
|
+
} else if (insertPosition === INSERT_POSITION.CURRENT) {
|
|
1349
|
+
Transforms.splitNodes(editor, {
|
|
1350
|
+
at: selection,
|
|
1351
|
+
always: true
|
|
1352
|
+
});
|
|
1353
|
+
Transforms.insertNodes(editor, tableNode, {
|
|
1354
|
+
at: selection.anchor
|
|
1355
|
+
});
|
|
1356
|
+
}
|
|
1357
|
+
};
|
|
1358
|
+
export const getInsertPosition = editor => {
|
|
1359
|
+
const {
|
|
1360
|
+
selection
|
|
1361
|
+
} = editor;
|
|
1362
|
+
if (!selection) return INSERT_POSITION.CURRENT;
|
|
1363
|
+
if (!Range.isCollapsed(selection)) return INSERT_POSITION.CURRENT;
|
|
1364
|
+
const aboveNodeEntry = getAboveBlockNode(editor);
|
|
1365
|
+
if (!aboveNodeEntry) return INSERT_POSITION.CURRENT;
|
|
1366
|
+
const isAtStart = Editor.isStart(editor, selection.anchor, aboveNodeEntry[1]);
|
|
1367
|
+
if (isAtStart) return INSERT_POSITION.BEFORE;
|
|
1368
|
+
const isAtEnd = Editor.isEnd(editor, selection.anchor, aboveNodeEntry[1]);
|
|
1369
|
+
if (isAtEnd) return INSERT_POSITION.AFTER;
|
|
1370
|
+
return INSERT_POSITION.CURRENT;
|
|
1371
|
+
};
|
|
1372
|
+
export const generateInheritStyle = (allowedInheritStyleList, style, cell) => {
|
|
1373
|
+
const inheritStyle = _objectSpread({}, cell['inherit_style']) || {};
|
|
1374
|
+
for (const key in style) {
|
|
1375
|
+
if (Object.hasOwnProperty.call(style, key) && allowedInheritStyleList.includes(key)) {
|
|
1376
|
+
inheritStyle[key] = style[key];
|
|
1377
|
+
}
|
|
1378
|
+
}
|
|
1379
|
+
return inheritStyle;
|
|
1380
|
+
};
|
|
1381
|
+
export const getCellInheritStyles = (editor, tablePath, rowIndex, colIndex) => {
|
|
1382
|
+
var _table$children$rowIn, _tableCell$inherit_st;
|
|
1383
|
+
const [tableNodeEntry] = Editor.nodes(editor, {
|
|
1384
|
+
match: n => n.type === ELEMENT_TYPE.TABLE,
|
|
1385
|
+
at: tablePath
|
|
1319
1386
|
});
|
|
1387
|
+
if (!tableNodeEntry) return {};
|
|
1388
|
+
const table = tableNodeEntry[0];
|
|
1389
|
+
const tableCell = (_table$children$rowIn = table.children[rowIndex]) === null || _table$children$rowIn === void 0 ? void 0 : _table$children$rowIn.children[colIndex];
|
|
1390
|
+
if (!tableCell) return {};
|
|
1391
|
+
return (_tableCell$inherit_st = tableCell['inherit_style']) !== null && _tableCell$inherit_st !== void 0 ? _tableCell$inherit_st : {};
|
|
1320
1392
|
};
|
|
@@ -5,7 +5,7 @@ import { ElementPopover } from '../../../../commons';
|
|
|
5
5
|
import { ELEMENT_TYPE } from '../../../../constants';
|
|
6
6
|
import { getSelectedNodeByType } from '../../../../core';
|
|
7
7
|
import { TABLE_MAX_COLUMNS, TABLE_MAX_ROWS, TABLE_ELEMENT, TABLE_ELEMENT_POSITION, EMPTY_SELECTED_RANGE } from '../../constants';
|
|
8
|
-
import { insertTableElement, removeTableElement,
|
|
8
|
+
import { insertTableElement, removeTableElement, combineCells } from '../../helpers';
|
|
9
9
|
import InsertTableElement from './insert-table-element';
|
|
10
10
|
import EventBus from '../../../../../utils/event-bus';
|
|
11
11
|
import { INTERNAL_EVENT } from '../../../../../constants';
|
|
@@ -84,6 +84,16 @@ class TableContextMenu extends React.Component {
|
|
|
84
84
|
componentWillUnmount() {
|
|
85
85
|
this.menu = null;
|
|
86
86
|
}
|
|
87
|
+
isMergedCell() {
|
|
88
|
+
const {
|
|
89
|
+
editor
|
|
90
|
+
} = this.props;
|
|
91
|
+
const {
|
|
92
|
+
colspan,
|
|
93
|
+
rowspan
|
|
94
|
+
} = getSelectedNodeByType(editor, ELEMENT_TYPE.TABLE_CELL);
|
|
95
|
+
return colspan > 1 || rowspan > 1;
|
|
96
|
+
}
|
|
87
97
|
render() {
|
|
88
98
|
const {
|
|
89
99
|
contextStyle
|
|
@@ -106,6 +116,7 @@ class TableContextMenu extends React.Component {
|
|
|
106
116
|
const canAddColsCount = currentColumnsCount + selectedCols > TABLE_MAX_COLUMNS ? TABLE_MAX_COLUMNS - currentColumnsCount : selectedCols;
|
|
107
117
|
const enableCombineCell = !ObjectUtils.isSameObject(tableSelectedRange, EMPTY_SELECTED_RANGE);
|
|
108
118
|
const enableSplitCell = !enableCombineCell;
|
|
119
|
+
const isMergedCell = this.isMergedCell();
|
|
109
120
|
return /*#__PURE__*/React.createElement(ElementPopover, {
|
|
110
121
|
className: "sdoc-context-menu"
|
|
111
122
|
}, /*#__PURE__*/React.createElement("div", {
|
|
@@ -146,7 +157,7 @@ class TableContextMenu extends React.Component {
|
|
|
146
157
|
onMouseDown: this.combineCells
|
|
147
158
|
}, t('Combine_cell')), /*#__PURE__*/React.createElement("button", {
|
|
148
159
|
className: "dropdown-item",
|
|
149
|
-
disabled: !enableSplitCell,
|
|
160
|
+
disabled: !isMergedCell || !enableSplitCell,
|
|
150
161
|
onMouseDown: this.toggleSplitCellSettingDialog
|
|
151
162
|
}, t('Split_cell'))));
|
|
152
163
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React, { useCallback } from 'react';
|
|
2
2
|
import { withTranslation } from 'react-i18next';
|
|
3
|
-
import { insertTable, isTableMenuDisabled } from '../../helpers';
|
|
3
|
+
import { getInsertPosition, insertTable, isTableMenuDisabled } from '../../helpers';
|
|
4
4
|
import { MENUS_CONFIG_MAP, ELEMENT_TYPE, INSERT_POSITION } from '../../../../constants';
|
|
5
5
|
import TableSizePopover from '../../popover/table-size-popover';
|
|
6
6
|
import ElementDropdownMenuItem from '../../../../commons/dropdown-menu-item';
|
|
@@ -13,7 +13,8 @@ const TableMenu = _ref => {
|
|
|
13
13
|
const disabled = isTableMenuDisabled(editor, readonly);
|
|
14
14
|
const menuConfig = MENUS_CONFIG_MAP[ELEMENT_TYPE.TABLE];
|
|
15
15
|
const createTable = useCallback(size => {
|
|
16
|
-
|
|
16
|
+
const insertPosition = getInsertPosition(editor, INSERT_POSITION.AFTER);
|
|
17
|
+
insertTable(editor, size, editor.selection, insertPosition);
|
|
17
18
|
}, [editor]);
|
|
18
19
|
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(ElementDropdownMenuItem, {
|
|
19
20
|
disabled: disabled,
|
|
@@ -7,7 +7,7 @@ import ObjectUtils from '../../../../utils/object-utils';
|
|
|
7
7
|
import { findPath, focusEditor } from '../../../core';
|
|
8
8
|
import { useResizeHandlersContext, useTableSelectedRangeContext } from './hooks';
|
|
9
9
|
import { EMPTY_SELECTED_RANGE, SELECTED_TABLE_CELL_BACKGROUND_COLOR, TABLE_CELL_STYLE } from '../constants';
|
|
10
|
-
import { getTableColumns,
|
|
10
|
+
import { getTableColumns, colorBlend } from '../helpers';
|
|
11
11
|
const TableCell = _ref => {
|
|
12
12
|
let {
|
|
13
13
|
attributes,
|
|
@@ -67,6 +67,9 @@ const TableCell = _ref => {
|
|
|
67
67
|
colspan = 1
|
|
68
68
|
} = element;
|
|
69
69
|
style.gridArea = "".concat(rowIndex + 1, " / ").concat(cellIndex + 1, " / span ").concat(rowspan, " / span ").concat(colspan);
|
|
70
|
+
if (element.style) {
|
|
71
|
+
style = _objectSpread(_objectSpread({}, element.style), style);
|
|
72
|
+
}
|
|
70
73
|
return /*#__PURE__*/React.createElement("div", Object.assign({}, attributes, {
|
|
71
74
|
style: _objectSpread(_objectSpread({}, element.style), style),
|
|
72
75
|
className: classnames('table-cell', attributes.className, {
|