@worktile/theia 16.3.2 → 16.3.3
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/editor.module.d.ts +2 -2
- package/esm2022/plugins/table/components/table.component.mjs +3 -2
- package/esm2022/plugins/table/components/toolbar/table-options.component.mjs +3 -3
- package/esm2022/plugins/table/components/toolbar/table-toolbar.component.mjs +6 -16
- package/esm2022/plugins/table/table.editor.mjs +92 -7
- package/esm2022/plugins/table/table.plugin.mjs +2 -2
- package/esm2022/plugins/table/table.store.mjs +1 -25
- package/esm2022/plugins/table/utils/remove-row-column.mjs +3 -4
- package/esm2022/services/table-contextmenu.service.mjs +6 -8
- package/esm2022/utils/copy-node.mjs +5 -2
- package/fesm2022/worktile-theia.mjs +248 -221
- package/fesm2022/worktile-theia.mjs.map +1 -1
- package/interfaces/editor.d.ts +2 -2
- package/package.json +1 -1
- package/plugins/table/table.editor.d.ts +10 -3
- package/plugins/table/table.store.d.ts +0 -3
- package/queries/is-range-across-blocks.d.ts +1 -1
- package/esm2022/plugins/table/utils/set-cells-background-color.mjs +0 -22
- package/esm2022/plugins/table/utils/set-node-options.mjs +0 -11
- package/plugins/table/utils/set-cells-background-color.d.ts +0 -3
- package/plugins/table/utils/set-node-options.d.ts +0 -3
|
@@ -2132,7 +2132,10 @@ function copyNode(editor, element, thyNotifyService, codeMirrorEditor) {
|
|
|
2132
2132
|
if (IS_SAFARI) {
|
|
2133
2133
|
copyNodeForSafari(editor, element);
|
|
2134
2134
|
}
|
|
2135
|
-
document.execCommand('copy')
|
|
2135
|
+
const isSuccess = document.execCommand('copy');
|
|
2136
|
+
if (thyNotifyService) {
|
|
2137
|
+
isSuccess ? thyNotifyService.success('复制成功') : thyNotifyService.error('复制失败');
|
|
2138
|
+
}
|
|
2136
2139
|
if (IS_SAFARI) {
|
|
2137
2140
|
window.getSelection().removeAllRanges();
|
|
2138
2141
|
}
|
|
@@ -6447,6 +6450,151 @@ function setCellIndent(editor, indentType, child, at) {
|
|
|
6447
6450
|
}
|
|
6448
6451
|
}
|
|
6449
6452
|
|
|
6453
|
+
function splitCell(editor) {
|
|
6454
|
+
const tablePosition = createTablePosition(editor);
|
|
6455
|
+
const { cell, table, cellEntry } = tablePosition;
|
|
6456
|
+
if ((!cell.rowspan && !cell.colspan) || (cell.rowspan === 1 && cell.colspan === 1))
|
|
6457
|
+
return editor;
|
|
6458
|
+
const cellRow = tablePosition.getRowIndex();
|
|
6459
|
+
const cellCol = tablePosition.getColumnIndex();
|
|
6460
|
+
resetTableCell(editor, table, cell, cellRow, cellCol);
|
|
6461
|
+
Transforms.select(editor, cellEntry[1]);
|
|
6462
|
+
Transforms.collapse(editor, { edge: 'end' });
|
|
6463
|
+
}
|
|
6464
|
+
function resetTableCell(editor, table, cell, cellRow, cellCol) {
|
|
6465
|
+
const rowSpanIndex = cellRow + (cell.rowspan || 1) - 1;
|
|
6466
|
+
const colSpanIndex = cellCol + (cell.colspan || 1) - 1;
|
|
6467
|
+
Editor.withoutNormalizing(editor, () => {
|
|
6468
|
+
table.children.map((row, rowIndex) => {
|
|
6469
|
+
row.children.map((col, colIndex) => {
|
|
6470
|
+
if (rowIndex >= cellRow && rowIndex <= rowSpanIndex && colIndex >= cellCol && colIndex <= colSpanIndex) {
|
|
6471
|
+
const path = findPath(editor, col);
|
|
6472
|
+
Transforms.setNodes(editor, { colspan: null, rowspan: null, hidden: null }, { at: path });
|
|
6473
|
+
}
|
|
6474
|
+
});
|
|
6475
|
+
});
|
|
6476
|
+
});
|
|
6477
|
+
}
|
|
6478
|
+
|
|
6479
|
+
const getTableEntry = (editor) => {
|
|
6480
|
+
const { tableEntry } = createTablePosition(editor);
|
|
6481
|
+
return tableEntry;
|
|
6482
|
+
};
|
|
6483
|
+
const getTablePath = (editor) => {
|
|
6484
|
+
const tableEntry = getTableEntry(editor);
|
|
6485
|
+
return tableEntry[1];
|
|
6486
|
+
};
|
|
6487
|
+
const getTable = (editor) => {
|
|
6488
|
+
const { tableEntry } = createTablePosition(editor);
|
|
6489
|
+
return tableEntry[0];
|
|
6490
|
+
};
|
|
6491
|
+
const getSelectedCell = (editor) => {
|
|
6492
|
+
if (editor && editor.selection) {
|
|
6493
|
+
const { cell } = createTablePosition(editor);
|
|
6494
|
+
return cell;
|
|
6495
|
+
}
|
|
6496
|
+
return null;
|
|
6497
|
+
};
|
|
6498
|
+
|
|
6499
|
+
function isSelectedCellMerged(editor) {
|
|
6500
|
+
if (editor && editor.selection) {
|
|
6501
|
+
const opts = new TableOptions();
|
|
6502
|
+
const { anchor } = editor.selection;
|
|
6503
|
+
const { cell } = TablePosition.create(opts, editor, anchor.path);
|
|
6504
|
+
if (cell) {
|
|
6505
|
+
return (cell.colspan && cell.colspan !== 1) || (cell.rowspan && cell.rowspan !== 1);
|
|
6506
|
+
}
|
|
6507
|
+
}
|
|
6508
|
+
return false;
|
|
6509
|
+
}
|
|
6510
|
+
function getLeftCellDict(selectCellNodes) {
|
|
6511
|
+
return selectCellNodes.reduce((dict, cell) => {
|
|
6512
|
+
if (!dict[cell.row]) {
|
|
6513
|
+
dict[cell.row] = cell;
|
|
6514
|
+
}
|
|
6515
|
+
return dict;
|
|
6516
|
+
}, {});
|
|
6517
|
+
}
|
|
6518
|
+
function calculateCellSpan(selectCellNodes, leftCellDict) {
|
|
6519
|
+
let rowspan = 0, colspan = 0, crossCount = -1;
|
|
6520
|
+
selectCellNodes
|
|
6521
|
+
.filter(item => !item.node.hidden)
|
|
6522
|
+
.forEach(item => {
|
|
6523
|
+
const { row } = item;
|
|
6524
|
+
if (item.row === selectCellNodes[0].row) {
|
|
6525
|
+
colspan += item.node.colspan || 1;
|
|
6526
|
+
}
|
|
6527
|
+
const maxRowSpan = leftCellDict[row].maxRowSpan || 1;
|
|
6528
|
+
leftCellDict[row].maxRowSpan = (item.node.rowspan || 1) > maxRowSpan ? item.node.rowspan : maxRowSpan;
|
|
6529
|
+
});
|
|
6530
|
+
Object.values(leftCellDict).forEach((item) => {
|
|
6531
|
+
const { row, maxRowSpan } = item;
|
|
6532
|
+
if (crossCount < row) {
|
|
6533
|
+
rowspan += maxRowSpan;
|
|
6534
|
+
crossCount = row + maxRowSpan - 1;
|
|
6535
|
+
}
|
|
6536
|
+
});
|
|
6537
|
+
return { rowspan, colspan };
|
|
6538
|
+
}
|
|
6539
|
+
function mergeCell(editor, selectedCells) {
|
|
6540
|
+
sortCell(selectedCells);
|
|
6541
|
+
const selectCellNodes = getSelectCellNode(editor, selectedCells);
|
|
6542
|
+
Editor.withoutNormalizing(editor, () => {
|
|
6543
|
+
let leftTopCellPath;
|
|
6544
|
+
const leftCellDict = getLeftCellDict(selectCellNodes);
|
|
6545
|
+
selectCellNodes.forEach((cell, index) => {
|
|
6546
|
+
const { row, node } = cell;
|
|
6547
|
+
if (node) {
|
|
6548
|
+
const cellPath = findPath(editor, node);
|
|
6549
|
+
if (index === 0) {
|
|
6550
|
+
leftTopCellPath = cellPath;
|
|
6551
|
+
}
|
|
6552
|
+
else {
|
|
6553
|
+
mergeCellContent(editor, leftTopCellPath, cellPath);
|
|
6554
|
+
Transforms.setNodes(editor, { colspan: null, rowspan: null, hidden: true }, { at: cellPath });
|
|
6555
|
+
}
|
|
6556
|
+
}
|
|
6557
|
+
});
|
|
6558
|
+
let { rowspan, colspan } = calculateCellSpan(selectCellNodes, leftCellDict);
|
|
6559
|
+
Transforms.setNodes(editor, { rowspan, colspan }, { at: leftTopCellPath });
|
|
6560
|
+
Transforms.select(editor, leftTopCellPath);
|
|
6561
|
+
Transforms.collapse(editor, { edge: 'end' });
|
|
6562
|
+
});
|
|
6563
|
+
}
|
|
6564
|
+
function mergeCellContent(editor, leftTopCellPath, cellPath) {
|
|
6565
|
+
Editor.withoutNormalizing(editor, () => {
|
|
6566
|
+
const { path } = Editor.end(editor, leftTopCellPath);
|
|
6567
|
+
const endRange = Editor.range(editor, Editor.start(editor, cellPath), Editor.end(editor, cellPath));
|
|
6568
|
+
let tableCell;
|
|
6569
|
+
path.pop();
|
|
6570
|
+
const nextPath = Path.next(path);
|
|
6571
|
+
Transforms.moveNodes(editor, {
|
|
6572
|
+
at: endRange,
|
|
6573
|
+
to: nextPath,
|
|
6574
|
+
match: node => {
|
|
6575
|
+
if (Element$1.isElement(node) && node.type === ElementKinds.tableCell) {
|
|
6576
|
+
tableCell = node;
|
|
6577
|
+
}
|
|
6578
|
+
if (Element$1.isElement(node) && node.type && tableCell && tableCell.children.includes(node)) {
|
|
6579
|
+
const isSingleEmptyParagraph = tableCell.children.length === 1 && Editor.isEmpty(editor, node) && node.type === ElementKinds.default;
|
|
6580
|
+
return !isSingleEmptyParagraph && true;
|
|
6581
|
+
}
|
|
6582
|
+
}
|
|
6583
|
+
});
|
|
6584
|
+
});
|
|
6585
|
+
}
|
|
6586
|
+
// 计算合并前的单元格
|
|
6587
|
+
function getCellPositionsBeforeMerge(editor, { row, col }) {
|
|
6588
|
+
const pos = createTablePosition(editor);
|
|
6589
|
+
const { rowspan, colspan } = pos.findCellByPath({ row, col });
|
|
6590
|
+
if (rowspan || colspan) {
|
|
6591
|
+
const colSpan = colspan ?? 1;
|
|
6592
|
+
const rowSpan = rowspan ?? 1;
|
|
6593
|
+
return getCellPositionsFromRange(row, col, row + rowSpan, col + colSpan);
|
|
6594
|
+
}
|
|
6595
|
+
return [{ row, col }];
|
|
6596
|
+
}
|
|
6597
|
+
|
|
6450
6598
|
const TableEditor = {
|
|
6451
6599
|
insertTable(editor, optionsParam) {
|
|
6452
6600
|
const opts = new TableOptions(optionsParam);
|
|
@@ -6476,11 +6624,84 @@ const TableEditor = {
|
|
|
6476
6624
|
const opts = new TableOptions(optionsParam);
|
|
6477
6625
|
clearCell(opts, editor, nodeEntry);
|
|
6478
6626
|
},
|
|
6627
|
+
setCellsBackgroundColor(editor, color, selectCells) {
|
|
6628
|
+
let cells = selectCells;
|
|
6629
|
+
if (!cells) {
|
|
6630
|
+
cells = TableEditor.getSelectedCells(editor) || [];
|
|
6631
|
+
}
|
|
6632
|
+
if (cells.length) {
|
|
6633
|
+
// 点击自定义颜色面板输入框设置颜色值时,会丢失焦点和选区(目前无法做到焦点同时存在于编辑器和输入框)
|
|
6634
|
+
let location;
|
|
6635
|
+
if (!editor.selection) {
|
|
6636
|
+
const { rangeRef } = THE_EDITOR_PREVIOUS_SELECTION.get(editor);
|
|
6637
|
+
location = rangeRef.current.anchor;
|
|
6638
|
+
}
|
|
6639
|
+
const isHeader = TableEditor.isActiveHeader(editor, location);
|
|
6640
|
+
if (color === 'transparent' ||
|
|
6641
|
+
(color === TableHeaderBackgroundColor && isHeader) ||
|
|
6642
|
+
(color === SpecialBackgroundColor && !isHeader)) {
|
|
6643
|
+
color = null;
|
|
6644
|
+
}
|
|
6645
|
+
Editor.withoutNormalizing(editor, () => {
|
|
6646
|
+
cells.map(cell => {
|
|
6647
|
+
const cellPath = AngularEditor.findPath(editor, cell);
|
|
6648
|
+
Transforms.setNodes(editor, { backgroundColor: color }, { at: cellPath });
|
|
6649
|
+
});
|
|
6650
|
+
});
|
|
6651
|
+
}
|
|
6652
|
+
},
|
|
6653
|
+
mergeCell(editor) {
|
|
6654
|
+
const selectedCellsPosition = TableEditor.getSelectedCellPositions(editor);
|
|
6655
|
+
selectedCellsPosition.length && mergeCell(editor, selectedCellsPosition);
|
|
6656
|
+
},
|
|
6657
|
+
splitCell(editor) {
|
|
6658
|
+
splitCell(editor);
|
|
6659
|
+
},
|
|
6660
|
+
setTableOptions(editor, newOptions) {
|
|
6661
|
+
const tablePosition = createTablePosition(editor);
|
|
6662
|
+
const tablePath = getTablePath(editor);
|
|
6663
|
+
const table = tablePosition.table;
|
|
6664
|
+
const options = { ...table.options, ...newOptions };
|
|
6665
|
+
Transforms.setNodes(editor, { options }, { at: tablePath });
|
|
6666
|
+
},
|
|
6667
|
+
setEquallyColumn(editor) {
|
|
6668
|
+
const [tableEntry] = Editor.nodes(editor, { at: editor.selection, match: (n) => n.type === ElementKinds.table });
|
|
6669
|
+
const tableElement = (tableEntry && tableEntry[0]);
|
|
6670
|
+
if (tableElement) {
|
|
6671
|
+
const columns = tableElement.columns;
|
|
6672
|
+
const sumWidth = columns.reduce((previousValue, currentValue) => {
|
|
6673
|
+
return previousValue + currentValue.width;
|
|
6674
|
+
}, 0);
|
|
6675
|
+
const equalColumns = columns.map(() => {
|
|
6676
|
+
return { width: sumWidth / columns.length };
|
|
6677
|
+
});
|
|
6678
|
+
setNode(editor, { columns: equalColumns }, tableElement);
|
|
6679
|
+
}
|
|
6680
|
+
},
|
|
6681
|
+
clearCellsContent(editor, selectCells) {
|
|
6682
|
+
let cells = selectCells;
|
|
6683
|
+
if (!cells) {
|
|
6684
|
+
cells = TableEditor.getSelectedCellPositions(editor) || [];
|
|
6685
|
+
}
|
|
6686
|
+
if (cells.length > 0) {
|
|
6687
|
+
const tablePosition = createTablePosition(editor);
|
|
6688
|
+
if (tablePosition.isInTable()) {
|
|
6689
|
+
Editor.withoutNormalizing(editor, () => {
|
|
6690
|
+
for (const { row, col } of cells) {
|
|
6691
|
+
const cellPath = [...tablePosition.tableEntry[1], row, col];
|
|
6692
|
+
const node = Node.get(editor, cellPath);
|
|
6693
|
+
TableEditor.clearCell(editor, [node, cellPath]);
|
|
6694
|
+
}
|
|
6695
|
+
});
|
|
6696
|
+
Transforms.select(editor, Editor.start(editor, tablePosition.cellEntry[1]));
|
|
6697
|
+
}
|
|
6698
|
+
}
|
|
6699
|
+
},
|
|
6479
6700
|
isActive(editor) {
|
|
6480
6701
|
const [table] = Editor.nodes(editor, { match: n => Element$1.isElement(n) && n.type === ElementKinds.table });
|
|
6481
6702
|
return !!table;
|
|
6482
6703
|
},
|
|
6483
|
-
|
|
6704
|
+
getSelectedCellPositions(editor) {
|
|
6484
6705
|
const tableNode = getAboveByType(editor, ElementKinds.table);
|
|
6485
6706
|
if (tableNode) {
|
|
6486
6707
|
const tableComponent = ELEMENT_TO_COMPONENT.get(tableNode[0]);
|
|
@@ -6491,6 +6712,14 @@ const TableEditor = {
|
|
|
6491
6712
|
}
|
|
6492
6713
|
return null;
|
|
6493
6714
|
},
|
|
6715
|
+
getSelectedCells(editor) {
|
|
6716
|
+
const tableNode = getAboveByType(editor, ElementKinds.table);
|
|
6717
|
+
if (tableNode) {
|
|
6718
|
+
const tableComponent = ELEMENT_TO_COMPONENT.get(tableNode[0]);
|
|
6719
|
+
return tableComponent?.tableStore?.selectedCells || null;
|
|
6720
|
+
}
|
|
6721
|
+
return null;
|
|
6722
|
+
},
|
|
6494
6723
|
setAlign(editor, alignment) {
|
|
6495
6724
|
return TableEditor.handleSelectedCells(editor, (_, cellRange) => {
|
|
6496
6725
|
Transforms.setNodes(editor, { align: alignment }, {
|
|
@@ -6518,7 +6747,7 @@ const TableEditor = {
|
|
|
6518
6747
|
return true;
|
|
6519
6748
|
},
|
|
6520
6749
|
isVerticalAlignActive(editor, alignment) {
|
|
6521
|
-
const cells = TableEditor.
|
|
6750
|
+
const cells = TableEditor.getSelectedCellPositions(editor);
|
|
6522
6751
|
if (cells) {
|
|
6523
6752
|
const lastCell = cells[cells.length - 1];
|
|
6524
6753
|
const tableNode = getAboveByType(editor, ElementKinds.table);
|
|
@@ -6575,7 +6804,7 @@ const TableEditor = {
|
|
|
6575
6804
|
});
|
|
6576
6805
|
},
|
|
6577
6806
|
handleSelectedCells(editor, handle) {
|
|
6578
|
-
const cells = TableEditor.
|
|
6807
|
+
const cells = TableEditor.getSelectedCellPositions(editor);
|
|
6579
6808
|
if (cells) {
|
|
6580
6809
|
const tableNode = getAboveByType(editor, ElementKinds.table);
|
|
6581
6810
|
Editor.withoutNormalizing(editor, () => {
|
|
@@ -6618,14 +6847,14 @@ const TableEditor = {
|
|
|
6618
6847
|
match: n => Element$1.isElement(n) &&
|
|
6619
6848
|
((n.type === ElementKinds.tableRow && n.header) || (n.type === ElementKinds.table && n.options?.headerRow))
|
|
6620
6849
|
});
|
|
6621
|
-
const selectedCells = TableEditor.
|
|
6850
|
+
const selectedCells = TableEditor.getSelectedCellPositions(editor) ?? [];
|
|
6622
6851
|
sortCell(selectedCells);
|
|
6623
6852
|
const isContainHeaderRow = !!selectedCells && selectedCells[0].row === 0;
|
|
6624
6853
|
return isHeaderRow && isContainHeaderRow;
|
|
6625
6854
|
},
|
|
6626
6855
|
hasHeaderColumnCell(editor) {
|
|
6627
6856
|
const table = getAboveByType(editor, ElementKinds.table);
|
|
6628
|
-
const selectedCells = TableEditor.
|
|
6857
|
+
const selectedCells = TableEditor.getSelectedCellPositions(editor) ?? [];
|
|
6629
6858
|
sortCell(selectedCells);
|
|
6630
6859
|
const isContainHeaderColumn = !!selectedCells && selectedCells[0].col === 0;
|
|
6631
6860
|
const isHeaderColumn = table && table[0] && table[0]?.options?.headerColumn;
|
|
@@ -11534,133 +11763,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.4", ngImpor
|
|
|
11534
11763
|
args: ['mousedown', ['$event']]
|
|
11535
11764
|
}] } });
|
|
11536
11765
|
|
|
11537
|
-
function isSelectedCellMerged(editor) {
|
|
11538
|
-
if (editor && editor.selection) {
|
|
11539
|
-
const opts = new TableOptions();
|
|
11540
|
-
const { anchor } = editor.selection;
|
|
11541
|
-
const { cell } = TablePosition.create(opts, editor, anchor.path);
|
|
11542
|
-
if (cell) {
|
|
11543
|
-
return (cell.colspan && cell.colspan !== 1) || (cell.rowspan && cell.rowspan !== 1);
|
|
11544
|
-
}
|
|
11545
|
-
}
|
|
11546
|
-
return false;
|
|
11547
|
-
}
|
|
11548
|
-
function getLeftCellDict(selectCellNodes) {
|
|
11549
|
-
return selectCellNodes.reduce((dict, cell) => {
|
|
11550
|
-
if (!dict[cell.row]) {
|
|
11551
|
-
dict[cell.row] = cell;
|
|
11552
|
-
}
|
|
11553
|
-
return dict;
|
|
11554
|
-
}, {});
|
|
11555
|
-
}
|
|
11556
|
-
function calculateCellSpan(selectCellNodes, leftCellDict) {
|
|
11557
|
-
let rowspan = 0, colspan = 0, crossCount = -1;
|
|
11558
|
-
selectCellNodes
|
|
11559
|
-
.filter(item => !item.node.hidden)
|
|
11560
|
-
.forEach(item => {
|
|
11561
|
-
const { row } = item;
|
|
11562
|
-
if (item.row === selectCellNodes[0].row) {
|
|
11563
|
-
colspan += item.node.colspan || 1;
|
|
11564
|
-
}
|
|
11565
|
-
const maxRowSpan = leftCellDict[row].maxRowSpan || 1;
|
|
11566
|
-
leftCellDict[row].maxRowSpan = (item.node.rowspan || 1) > maxRowSpan ? item.node.rowspan : maxRowSpan;
|
|
11567
|
-
});
|
|
11568
|
-
Object.values(leftCellDict).forEach((item) => {
|
|
11569
|
-
const { row, maxRowSpan } = item;
|
|
11570
|
-
if (crossCount < row) {
|
|
11571
|
-
rowspan += maxRowSpan;
|
|
11572
|
-
crossCount = row + maxRowSpan - 1;
|
|
11573
|
-
}
|
|
11574
|
-
});
|
|
11575
|
-
return { rowspan, colspan };
|
|
11576
|
-
}
|
|
11577
|
-
function mergeCell(editor, selectedCells) {
|
|
11578
|
-
sortCell(selectedCells);
|
|
11579
|
-
const selectCellNodes = getSelectCellNode(editor, selectedCells);
|
|
11580
|
-
Editor.withoutNormalizing(editor, () => {
|
|
11581
|
-
let leftTopCellPath;
|
|
11582
|
-
const leftCellDict = getLeftCellDict(selectCellNodes);
|
|
11583
|
-
selectCellNodes.forEach((cell, index) => {
|
|
11584
|
-
const { row, node } = cell;
|
|
11585
|
-
if (node) {
|
|
11586
|
-
const cellPath = findPath(editor, node);
|
|
11587
|
-
if (index === 0) {
|
|
11588
|
-
leftTopCellPath = cellPath;
|
|
11589
|
-
}
|
|
11590
|
-
else {
|
|
11591
|
-
mergeCellContent(editor, leftTopCellPath, cellPath);
|
|
11592
|
-
Transforms.setNodes(editor, { colspan: null, rowspan: null, hidden: true }, { at: cellPath });
|
|
11593
|
-
}
|
|
11594
|
-
}
|
|
11595
|
-
});
|
|
11596
|
-
let { rowspan, colspan } = calculateCellSpan(selectCellNodes, leftCellDict);
|
|
11597
|
-
Transforms.setNodes(editor, { rowspan, colspan }, { at: leftTopCellPath });
|
|
11598
|
-
Transforms.select(editor, leftTopCellPath);
|
|
11599
|
-
Transforms.collapse(editor, { edge: 'end' });
|
|
11600
|
-
});
|
|
11601
|
-
}
|
|
11602
|
-
function mergeCellContent(editor, leftTopCellPath, cellPath) {
|
|
11603
|
-
Editor.withoutNormalizing(editor, () => {
|
|
11604
|
-
const { path } = Editor.end(editor, leftTopCellPath);
|
|
11605
|
-
const endRange = Editor.range(editor, Editor.start(editor, cellPath), Editor.end(editor, cellPath));
|
|
11606
|
-
let tableCell;
|
|
11607
|
-
path.pop();
|
|
11608
|
-
const nextPath = Path.next(path);
|
|
11609
|
-
Transforms.moveNodes(editor, {
|
|
11610
|
-
at: endRange,
|
|
11611
|
-
to: nextPath,
|
|
11612
|
-
match: node => {
|
|
11613
|
-
if (Element$1.isElement(node) && node.type === ElementKinds.tableCell) {
|
|
11614
|
-
tableCell = node;
|
|
11615
|
-
}
|
|
11616
|
-
if (Element$1.isElement(node) && node.type && tableCell && tableCell.children.includes(node)) {
|
|
11617
|
-
const isSingleEmptyParagraph = tableCell.children.length === 1 && Editor.isEmpty(editor, node) && node.type === ElementKinds.default;
|
|
11618
|
-
return !isSingleEmptyParagraph && true;
|
|
11619
|
-
}
|
|
11620
|
-
}
|
|
11621
|
-
});
|
|
11622
|
-
});
|
|
11623
|
-
}
|
|
11624
|
-
// 计算合并前的单元格
|
|
11625
|
-
function getCellPositionsBeforeMerge(editor, { row, col }) {
|
|
11626
|
-
const pos = createTablePosition(editor);
|
|
11627
|
-
const { rowspan, colspan } = pos.findCellByPath({ row, col });
|
|
11628
|
-
if (rowspan || colspan) {
|
|
11629
|
-
const colSpan = colspan ?? 1;
|
|
11630
|
-
const rowSpan = rowspan ?? 1;
|
|
11631
|
-
return getCellPositionsFromRange(row, col, row + rowSpan, col + colSpan);
|
|
11632
|
-
}
|
|
11633
|
-
return [{ row, col }];
|
|
11634
|
-
}
|
|
11635
|
-
|
|
11636
|
-
const getTableEntry = (editor) => {
|
|
11637
|
-
const { tableEntry } = createTablePosition(editor);
|
|
11638
|
-
return tableEntry;
|
|
11639
|
-
};
|
|
11640
|
-
const getTablePath = (editor) => {
|
|
11641
|
-
const tableEntry = getTableEntry(editor);
|
|
11642
|
-
return tableEntry[1];
|
|
11643
|
-
};
|
|
11644
|
-
const getTable = (editor) => {
|
|
11645
|
-
const { tableEntry } = createTablePosition(editor);
|
|
11646
|
-
return tableEntry[0];
|
|
11647
|
-
};
|
|
11648
|
-
const getSelectedCell = (editor) => {
|
|
11649
|
-
if (editor && editor.selection) {
|
|
11650
|
-
const { cell } = createTablePosition(editor);
|
|
11651
|
-
return cell;
|
|
11652
|
-
}
|
|
11653
|
-
return null;
|
|
11654
|
-
};
|
|
11655
|
-
|
|
11656
|
-
function setTableOptions(editor, newOptions) {
|
|
11657
|
-
const tablePosition = createTablePosition(editor);
|
|
11658
|
-
const tablePath = getTablePath(editor);
|
|
11659
|
-
const table = tablePosition.table;
|
|
11660
|
-
const options = { ...table.options, ...newOptions };
|
|
11661
|
-
Transforms.setNodes(editor, { options }, { at: tablePath });
|
|
11662
|
-
}
|
|
11663
|
-
|
|
11664
11766
|
function removeColumnOrRows(editor, tableStore, options) {
|
|
11665
11767
|
const { isSelectedTable } = tableStore;
|
|
11666
11768
|
const selectedRowsIndex = options?.selectedRowsIndex || tableStore.selectedRowsIndex;
|
|
@@ -11674,7 +11776,7 @@ function removeColumnOrRows(editor, tableStore, options) {
|
|
|
11674
11776
|
if (selectedRowsIndex.length > 0 && selectedColumnsIndex.length === 0) {
|
|
11675
11777
|
// 删除行时取消标题行
|
|
11676
11778
|
if (tablePosition.table && tableComponent.headerRow && selectedRowsIndex.includes(0)) {
|
|
11677
|
-
setTableOptions(editor, { headerRow: false });
|
|
11779
|
+
TableEditor.setTableOptions(editor, { headerRow: false });
|
|
11678
11780
|
// headerRow 兼容代码, 取消标题行的时候同时设置 row 中的 header 属性
|
|
11679
11781
|
if (tablePosition.table.children[0].header) {
|
|
11680
11782
|
const rowPath = TheEditor.findPath(editor, tablePosition.table.children[0]);
|
|
@@ -11691,7 +11793,7 @@ function removeColumnOrRows(editor, tableStore, options) {
|
|
|
11691
11793
|
if (selectedColumnsIndex.length > 0 && selectedRowsIndex.length === 0) {
|
|
11692
11794
|
// 删除列时取消标题列
|
|
11693
11795
|
if (tablePosition.table && tablePosition.table.options?.headerColumn && selectedColumnsIndex.includes(0)) {
|
|
11694
|
-
setTableOptions(editor, { headerColumn: false });
|
|
11796
|
+
TableEditor.setTableOptions(editor, { headerColumn: false });
|
|
11695
11797
|
}
|
|
11696
11798
|
selectedColumnsIndex
|
|
11697
11799
|
.sort((a, b) => b - a)
|
|
@@ -11702,25 +11804,6 @@ function removeColumnOrRows(editor, tableStore, options) {
|
|
|
11702
11804
|
}
|
|
11703
11805
|
}
|
|
11704
11806
|
|
|
11705
|
-
const setSelectedCellsBackgroundColor = (editor, color, tableStore) => {
|
|
11706
|
-
// 点击自定义颜色面板输入框设置颜色值时,会丢失焦点和选区(目前无法做到焦点同时存在于编辑器和输入框)
|
|
11707
|
-
let location;
|
|
11708
|
-
if (!editor.selection) {
|
|
11709
|
-
const { rangeRef } = THE_EDITOR_PREVIOUS_SELECTION.get(editor);
|
|
11710
|
-
location = rangeRef.current.anchor;
|
|
11711
|
-
}
|
|
11712
|
-
const isHeader = TableEditor.isActiveHeader(editor, location);
|
|
11713
|
-
if (color === 'transparent') {
|
|
11714
|
-
color = null;
|
|
11715
|
-
}
|
|
11716
|
-
if ((color === TableHeaderBackgroundColor && isHeader) || (color === SpecialBackgroundColor && !isHeader)) {
|
|
11717
|
-
tableStore.setSelectedCellsBackgroundColor(null);
|
|
11718
|
-
}
|
|
11719
|
-
else {
|
|
11720
|
-
tableStore.setSelectedCellsBackgroundColor(color);
|
|
11721
|
-
}
|
|
11722
|
-
};
|
|
11723
|
-
|
|
11724
11807
|
function setCellMenuVisibility(editor, menuList, tableInfo) {
|
|
11725
11808
|
const { selectedCellPositions, isFullscreen, isSelectedTable, selectedRowsIndex, selectedColumnsIndex } = tableInfo;
|
|
11726
11809
|
const isCellMerged = isSelectedCellMerged(editor);
|
|
@@ -11761,32 +11844,6 @@ function setCellMenuVisibility(editor, menuList, tableInfo) {
|
|
|
11761
11844
|
});
|
|
11762
11845
|
}
|
|
11763
11846
|
|
|
11764
|
-
function splitCell(editor) {
|
|
11765
|
-
const tablePosition = createTablePosition(editor);
|
|
11766
|
-
const { cell, table, cellEntry } = tablePosition;
|
|
11767
|
-
if ((!cell.rowspan && !cell.colspan) || (cell.rowspan === 1 && cell.colspan === 1))
|
|
11768
|
-
return editor;
|
|
11769
|
-
const cellRow = tablePosition.getRowIndex();
|
|
11770
|
-
const cellCol = tablePosition.getColumnIndex();
|
|
11771
|
-
resetTableCell(editor, table, cell, cellRow, cellCol);
|
|
11772
|
-
Transforms.select(editor, cellEntry[1]);
|
|
11773
|
-
Transforms.collapse(editor, { edge: 'end' });
|
|
11774
|
-
}
|
|
11775
|
-
function resetTableCell(editor, table, cell, cellRow, cellCol) {
|
|
11776
|
-
const rowSpanIndex = cellRow + (cell.rowspan || 1) - 1;
|
|
11777
|
-
const colSpanIndex = cellCol + (cell.colspan || 1) - 1;
|
|
11778
|
-
Editor.withoutNormalizing(editor, () => {
|
|
11779
|
-
table.children.map((row, rowIndex) => {
|
|
11780
|
-
row.children.map((col, colIndex) => {
|
|
11781
|
-
if (rowIndex >= cellRow && rowIndex <= rowSpanIndex && colIndex >= cellCol && colIndex <= colSpanIndex) {
|
|
11782
|
-
const path = findPath(editor, col);
|
|
11783
|
-
Transforms.setNodes(editor, { colspan: null, rowspan: null, hidden: null }, { at: path });
|
|
11784
|
-
}
|
|
11785
|
-
});
|
|
11786
|
-
});
|
|
11787
|
-
});
|
|
11788
|
-
}
|
|
11789
|
-
|
|
11790
11847
|
const getMinAndMaxCellIndex = (editor, selectedCellPositions, maxRow, maxCol, minRow, minCol, table) => {
|
|
11791
11848
|
const beforeCols = [];
|
|
11792
11849
|
const beforeRows = [];
|
|
@@ -12166,29 +12223,6 @@ class TableStore {
|
|
|
12166
12223
|
this.dangerousColumnsIndex = [...Array(pos.getWidth())].map((_, i) => i);
|
|
12167
12224
|
this.dangerousCells$.next(cells);
|
|
12168
12225
|
}
|
|
12169
|
-
setSelectedCellsBackgroundColor(backgroundColor) {
|
|
12170
|
-
const cells = this.selectedCells$.getValue();
|
|
12171
|
-
Editor.withoutNormalizing(this.editor, () => {
|
|
12172
|
-
cells.map(cell => {
|
|
12173
|
-
const cellPath = AngularEditor.findPath(this.editor, cell);
|
|
12174
|
-
Transforms.setNodes(this.editor, { backgroundColor }, { at: cellPath });
|
|
12175
|
-
});
|
|
12176
|
-
});
|
|
12177
|
-
}
|
|
12178
|
-
clearSelectedCellsContent() {
|
|
12179
|
-
const cells = this.getSelectedCellPositions();
|
|
12180
|
-
const tablePosition = createTablePosition(this.editor);
|
|
12181
|
-
if (tablePosition.isInTable()) {
|
|
12182
|
-
Editor.withoutNormalizing(this.editor, () => {
|
|
12183
|
-
for (const { row, col } of cells) {
|
|
12184
|
-
const cellPath = [...tablePosition.tableEntry[1], row, col];
|
|
12185
|
-
const node = Node.get(this.editor, cellPath);
|
|
12186
|
-
TableEditor.clearCell(this.editor, [node, cellPath]);
|
|
12187
|
-
}
|
|
12188
|
-
});
|
|
12189
|
-
Transforms.select(this.editor, Editor.start(this.editor, tablePosition.cellEntry[1]));
|
|
12190
|
-
}
|
|
12191
|
-
}
|
|
12192
12226
|
/**
|
|
12193
12227
|
* 聚焦单元格并设置聚焦相关路径及元素
|
|
12194
12228
|
*/
|
|
@@ -12308,7 +12342,7 @@ class TheTableContextMenuService {
|
|
|
12308
12342
|
visibility: true,
|
|
12309
12343
|
actionHandle: () => { },
|
|
12310
12344
|
activeHandle: (event, item) => {
|
|
12311
|
-
|
|
12345
|
+
TableEditor.setCellsBackgroundColor(this.editor, item.backgroundColor);
|
|
12312
12346
|
},
|
|
12313
12347
|
deactivateHandle: (event) => {
|
|
12314
12348
|
if (event.relatedTarget instanceof HTMLElement) {
|
|
@@ -12378,7 +12412,7 @@ class TheTableContextMenuService {
|
|
|
12378
12412
|
name: '清空选中区域',
|
|
12379
12413
|
visibility: true,
|
|
12380
12414
|
actionHandle: () => {
|
|
12381
|
-
this.
|
|
12415
|
+
TableEditor.clearCellsContent(this.editor);
|
|
12382
12416
|
this.tableStore.selectFirstCell();
|
|
12383
12417
|
}
|
|
12384
12418
|
},
|
|
@@ -12388,7 +12422,7 @@ class TheTableContextMenuService {
|
|
|
12388
12422
|
name: '合并单元格',
|
|
12389
12423
|
visibility: true,
|
|
12390
12424
|
actionHandle: () => {
|
|
12391
|
-
mergeCell(this.editor
|
|
12425
|
+
TableEditor.mergeCell(this.editor);
|
|
12392
12426
|
}
|
|
12393
12427
|
},
|
|
12394
12428
|
{
|
|
@@ -12398,7 +12432,7 @@ class TheTableContextMenuService {
|
|
|
12398
12432
|
divider: true,
|
|
12399
12433
|
visibility: true,
|
|
12400
12434
|
actionHandle: () => {
|
|
12401
|
-
splitCell(this.editor);
|
|
12435
|
+
TableEditor.splitCell(this.editor);
|
|
12402
12436
|
}
|
|
12403
12437
|
},
|
|
12404
12438
|
{
|
|
@@ -12630,7 +12664,7 @@ class TheTableOptionsComponent {
|
|
|
12630
12664
|
currentOption.isActive = !option.isActive;
|
|
12631
12665
|
const tableOption = {};
|
|
12632
12666
|
tableOption[option.key] = currentOption.isActive || false;
|
|
12633
|
-
setTableOptions(this.editor, { ...tableOption });
|
|
12667
|
+
TableEditor.setTableOptions(this.editor, { ...tableOption });
|
|
12634
12668
|
// headerRow 兼容代码, 取消标题行的时候同时设置 row 中的 header 属性
|
|
12635
12669
|
if (option.key === TableOperations.headerRow && !tableOption[option.key] && this.table.children[0].header) {
|
|
12636
12670
|
const rowPath = TheEditor.findPath(this.editor, this.table.children[0]);
|
|
@@ -12697,7 +12731,7 @@ class TheTableToolbarComponent {
|
|
|
12697
12731
|
visibility: false,
|
|
12698
12732
|
icon: 'table-merge-cells',
|
|
12699
12733
|
actionHandle: () => {
|
|
12700
|
-
mergeCell(this.editor
|
|
12734
|
+
TableEditor.mergeCell(this.editor);
|
|
12701
12735
|
this.popoverRef.close();
|
|
12702
12736
|
this.tableStore.clearSelectedCells();
|
|
12703
12737
|
}
|
|
@@ -12708,7 +12742,7 @@ class TheTableToolbarComponent {
|
|
|
12708
12742
|
visibility: false,
|
|
12709
12743
|
icon: 'table-unmerge-cells',
|
|
12710
12744
|
actionHandle: () => {
|
|
12711
|
-
splitCell(this.editor);
|
|
12745
|
+
TableEditor.splitCell(this.editor);
|
|
12712
12746
|
this.popoverRef.close();
|
|
12713
12747
|
this.tableStore.clearSelectedCells();
|
|
12714
12748
|
}
|
|
@@ -12775,7 +12809,7 @@ class TheTableToolbarComponent {
|
|
|
12775
12809
|
e.stopPropagation();
|
|
12776
12810
|
}
|
|
12777
12811
|
changeColor(newColor) {
|
|
12778
|
-
|
|
12812
|
+
TableEditor.setCellsBackgroundColor(this.editor, newColor);
|
|
12779
12813
|
this.selectedColor = newColor;
|
|
12780
12814
|
}
|
|
12781
12815
|
setFullscreen(event) {
|
|
@@ -12792,14 +12826,7 @@ class TheTableToolbarComponent {
|
|
|
12792
12826
|
}
|
|
12793
12827
|
setEquallyColumnHandle(event) {
|
|
12794
12828
|
this.preventDefault(event);
|
|
12795
|
-
|
|
12796
|
-
const sumWidth = columns.reduce((previousValue, currentValue) => {
|
|
12797
|
-
return previousValue + currentValue.width;
|
|
12798
|
-
}, 0);
|
|
12799
|
-
const equalColumns = columns.map(() => {
|
|
12800
|
-
return { width: sumWidth / columns.length };
|
|
12801
|
-
});
|
|
12802
|
-
setNode(this.editor, { columns: equalColumns }, this.tableElement);
|
|
12829
|
+
TableEditor.setEquallyColumn(this.editor);
|
|
12803
12830
|
}
|
|
12804
12831
|
openTableOptionMenu(event) {
|
|
12805
12832
|
this.preventDefault(event);
|
|
@@ -13901,7 +13928,7 @@ class TheTableComponent extends TheBaseElementComponent {
|
|
|
13901
13928
|
}), takeUntil(this.destroy$))
|
|
13902
13929
|
.subscribe((e) => {
|
|
13903
13930
|
if (e.type === 'keydown') {
|
|
13904
|
-
this.
|
|
13931
|
+
TableEditor.clearCellsContent(this.editor);
|
|
13905
13932
|
}
|
|
13906
13933
|
const isCurrentTableElement = this.nativeElement.contains(e.target);
|
|
13907
13934
|
if (!isCurrentTableElement || (!this.tableStore.pointerSelection && !this.tableStore.areaSelection)) {
|
|
@@ -15681,7 +15708,7 @@ const withTable = (editor) => {
|
|
|
15681
15708
|
TableEditor.removeTable(editor);
|
|
15682
15709
|
}
|
|
15683
15710
|
else {
|
|
15684
|
-
|
|
15711
|
+
TableEditor.clearCellsContent(editor, selectedCellPositions);
|
|
15685
15712
|
}
|
|
15686
15713
|
tableComponent.tableService.closeToolbar();
|
|
15687
15714
|
});
|