@worktile/theia 16.3.1 → 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.
@@ -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') ? thyNotifyService.success('复制成功') : thyNotifyService.error('复制失败');
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
  }
@@ -6018,7 +6021,9 @@ class ThePluginMenuComponent extends mixinUnsubscribe(MixinBase) {
6018
6021
  this.removeKeywords = () => {
6019
6022
  const node = Node.get(this.editor, this.editor.selection.anchor.path);
6020
6023
  const nodeString = Node.string(node);
6021
- if (node && nodeString.length > 0 && this.keyWords && nodeString.toLocaleLowerCase().trim().includes(this.keyWords)) {
6024
+ const isStartWithHotkey = nodeString.startsWith('/');
6025
+ const isIncludeKeywords = nodeString.toLocaleLowerCase().trim().includes(this.keyWords);
6026
+ if (node && nodeString.length > 0 && (isStartWithHotkey || isIncludeKeywords)) {
6022
6027
  Editor.deleteBackward(this.editor, { unit: 'block' });
6023
6028
  }
6024
6029
  };
@@ -6445,6 +6450,151 @@ function setCellIndent(editor, indentType, child, at) {
6445
6450
  }
6446
6451
  }
6447
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
+
6448
6598
  const TableEditor = {
6449
6599
  insertTable(editor, optionsParam) {
6450
6600
  const opts = new TableOptions(optionsParam);
@@ -6474,11 +6624,84 @@ const TableEditor = {
6474
6624
  const opts = new TableOptions(optionsParam);
6475
6625
  clearCell(opts, editor, nodeEntry);
6476
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
+ },
6477
6700
  isActive(editor) {
6478
6701
  const [table] = Editor.nodes(editor, { match: n => Element$1.isElement(n) && n.type === ElementKinds.table });
6479
6702
  return !!table;
6480
6703
  },
6481
- getSelectedCells(editor) {
6704
+ getSelectedCellPositions(editor) {
6482
6705
  const tableNode = getAboveByType(editor, ElementKinds.table);
6483
6706
  if (tableNode) {
6484
6707
  const tableComponent = ELEMENT_TO_COMPONENT.get(tableNode[0]);
@@ -6489,6 +6712,14 @@ const TableEditor = {
6489
6712
  }
6490
6713
  return null;
6491
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
+ },
6492
6723
  setAlign(editor, alignment) {
6493
6724
  return TableEditor.handleSelectedCells(editor, (_, cellRange) => {
6494
6725
  Transforms.setNodes(editor, { align: alignment }, {
@@ -6516,7 +6747,7 @@ const TableEditor = {
6516
6747
  return true;
6517
6748
  },
6518
6749
  isVerticalAlignActive(editor, alignment) {
6519
- const cells = TableEditor.getSelectedCells(editor);
6750
+ const cells = TableEditor.getSelectedCellPositions(editor);
6520
6751
  if (cells) {
6521
6752
  const lastCell = cells[cells.length - 1];
6522
6753
  const tableNode = getAboveByType(editor, ElementKinds.table);
@@ -6573,7 +6804,7 @@ const TableEditor = {
6573
6804
  });
6574
6805
  },
6575
6806
  handleSelectedCells(editor, handle) {
6576
- const cells = TableEditor.getSelectedCells(editor);
6807
+ const cells = TableEditor.getSelectedCellPositions(editor);
6577
6808
  if (cells) {
6578
6809
  const tableNode = getAboveByType(editor, ElementKinds.table);
6579
6810
  Editor.withoutNormalizing(editor, () => {
@@ -6616,14 +6847,14 @@ const TableEditor = {
6616
6847
  match: n => Element$1.isElement(n) &&
6617
6848
  ((n.type === ElementKinds.tableRow && n.header) || (n.type === ElementKinds.table && n.options?.headerRow))
6618
6849
  });
6619
- const selectedCells = TableEditor.getSelectedCells(editor) ?? [];
6850
+ const selectedCells = TableEditor.getSelectedCellPositions(editor) ?? [];
6620
6851
  sortCell(selectedCells);
6621
6852
  const isContainHeaderRow = !!selectedCells && selectedCells[0].row === 0;
6622
6853
  return isHeaderRow && isContainHeaderRow;
6623
6854
  },
6624
6855
  hasHeaderColumnCell(editor) {
6625
6856
  const table = getAboveByType(editor, ElementKinds.table);
6626
- const selectedCells = TableEditor.getSelectedCells(editor) ?? [];
6857
+ const selectedCells = TableEditor.getSelectedCellPositions(editor) ?? [];
6627
6858
  sortCell(selectedCells);
6628
6859
  const isContainHeaderColumn = !!selectedCells && selectedCells[0].col === 0;
6629
6860
  const isHeaderColumn = table && table[0] && table[0]?.options?.headerColumn;
@@ -11532,133 +11763,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.4", ngImpor
11532
11763
  args: ['mousedown', ['$event']]
11533
11764
  }] } });
11534
11765
 
11535
- function isSelectedCellMerged(editor) {
11536
- if (editor && editor.selection) {
11537
- const opts = new TableOptions();
11538
- const { anchor } = editor.selection;
11539
- const { cell } = TablePosition.create(opts, editor, anchor.path);
11540
- if (cell) {
11541
- return (cell.colspan && cell.colspan !== 1) || (cell.rowspan && cell.rowspan !== 1);
11542
- }
11543
- }
11544
- return false;
11545
- }
11546
- function getLeftCellDict(selectCellNodes) {
11547
- return selectCellNodes.reduce((dict, cell) => {
11548
- if (!dict[cell.row]) {
11549
- dict[cell.row] = cell;
11550
- }
11551
- return dict;
11552
- }, {});
11553
- }
11554
- function calculateCellSpan(selectCellNodes, leftCellDict) {
11555
- let rowspan = 0, colspan = 0, crossCount = -1;
11556
- selectCellNodes
11557
- .filter(item => !item.node.hidden)
11558
- .forEach(item => {
11559
- const { row } = item;
11560
- if (item.row === selectCellNodes[0].row) {
11561
- colspan += item.node.colspan || 1;
11562
- }
11563
- const maxRowSpan = leftCellDict[row].maxRowSpan || 1;
11564
- leftCellDict[row].maxRowSpan = (item.node.rowspan || 1) > maxRowSpan ? item.node.rowspan : maxRowSpan;
11565
- });
11566
- Object.values(leftCellDict).forEach((item) => {
11567
- const { row, maxRowSpan } = item;
11568
- if (crossCount < row) {
11569
- rowspan += maxRowSpan;
11570
- crossCount = row + maxRowSpan - 1;
11571
- }
11572
- });
11573
- return { rowspan, colspan };
11574
- }
11575
- function mergeCell(editor, selectedCells) {
11576
- sortCell(selectedCells);
11577
- const selectCellNodes = getSelectCellNode(editor, selectedCells);
11578
- Editor.withoutNormalizing(editor, () => {
11579
- let leftTopCellPath;
11580
- const leftCellDict = getLeftCellDict(selectCellNodes);
11581
- selectCellNodes.forEach((cell, index) => {
11582
- const { row, node } = cell;
11583
- if (node) {
11584
- const cellPath = findPath(editor, node);
11585
- if (index === 0) {
11586
- leftTopCellPath = cellPath;
11587
- }
11588
- else {
11589
- mergeCellContent(editor, leftTopCellPath, cellPath);
11590
- Transforms.setNodes(editor, { colspan: null, rowspan: null, hidden: true }, { at: cellPath });
11591
- }
11592
- }
11593
- });
11594
- let { rowspan, colspan } = calculateCellSpan(selectCellNodes, leftCellDict);
11595
- Transforms.setNodes(editor, { rowspan, colspan }, { at: leftTopCellPath });
11596
- Transforms.select(editor, leftTopCellPath);
11597
- Transforms.collapse(editor, { edge: 'end' });
11598
- });
11599
- }
11600
- function mergeCellContent(editor, leftTopCellPath, cellPath) {
11601
- Editor.withoutNormalizing(editor, () => {
11602
- const { path } = Editor.end(editor, leftTopCellPath);
11603
- const endRange = Editor.range(editor, Editor.start(editor, cellPath), Editor.end(editor, cellPath));
11604
- let tableCell;
11605
- path.pop();
11606
- const nextPath = Path.next(path);
11607
- Transforms.moveNodes(editor, {
11608
- at: endRange,
11609
- to: nextPath,
11610
- match: node => {
11611
- if (Element$1.isElement(node) && node.type === ElementKinds.tableCell) {
11612
- tableCell = node;
11613
- }
11614
- if (Element$1.isElement(node) && node.type && tableCell && tableCell.children.includes(node)) {
11615
- const isSingleEmptyParagraph = tableCell.children.length === 1 && Editor.isEmpty(editor, node) && node.type === ElementKinds.default;
11616
- return !isSingleEmptyParagraph && true;
11617
- }
11618
- }
11619
- });
11620
- });
11621
- }
11622
- // 计算合并前的单元格
11623
- function getCellPositionsBeforeMerge(editor, { row, col }) {
11624
- const pos = createTablePosition(editor);
11625
- const { rowspan, colspan } = pos.findCellByPath({ row, col });
11626
- if (rowspan || colspan) {
11627
- const colSpan = colspan ?? 1;
11628
- const rowSpan = rowspan ?? 1;
11629
- return getCellPositionsFromRange(row, col, row + rowSpan, col + colSpan);
11630
- }
11631
- return [{ row, col }];
11632
- }
11633
-
11634
- const getTableEntry = (editor) => {
11635
- const { tableEntry } = createTablePosition(editor);
11636
- return tableEntry;
11637
- };
11638
- const getTablePath = (editor) => {
11639
- const tableEntry = getTableEntry(editor);
11640
- return tableEntry[1];
11641
- };
11642
- const getTable = (editor) => {
11643
- const { tableEntry } = createTablePosition(editor);
11644
- return tableEntry[0];
11645
- };
11646
- const getSelectedCell = (editor) => {
11647
- if (editor && editor.selection) {
11648
- const { cell } = createTablePosition(editor);
11649
- return cell;
11650
- }
11651
- return null;
11652
- };
11653
-
11654
- function setTableOptions(editor, newOptions) {
11655
- const tablePosition = createTablePosition(editor);
11656
- const tablePath = getTablePath(editor);
11657
- const table = tablePosition.table;
11658
- const options = { ...table.options, ...newOptions };
11659
- Transforms.setNodes(editor, { options }, { at: tablePath });
11660
- }
11661
-
11662
11766
  function removeColumnOrRows(editor, tableStore, options) {
11663
11767
  const { isSelectedTable } = tableStore;
11664
11768
  const selectedRowsIndex = options?.selectedRowsIndex || tableStore.selectedRowsIndex;
@@ -11672,7 +11776,7 @@ function removeColumnOrRows(editor, tableStore, options) {
11672
11776
  if (selectedRowsIndex.length > 0 && selectedColumnsIndex.length === 0) {
11673
11777
  // 删除行时取消标题行
11674
11778
  if (tablePosition.table && tableComponent.headerRow && selectedRowsIndex.includes(0)) {
11675
- setTableOptions(editor, { headerRow: false });
11779
+ TableEditor.setTableOptions(editor, { headerRow: false });
11676
11780
  // headerRow 兼容代码, 取消标题行的时候同时设置 row 中的 header 属性
11677
11781
  if (tablePosition.table.children[0].header) {
11678
11782
  const rowPath = TheEditor.findPath(editor, tablePosition.table.children[0]);
@@ -11689,7 +11793,7 @@ function removeColumnOrRows(editor, tableStore, options) {
11689
11793
  if (selectedColumnsIndex.length > 0 && selectedRowsIndex.length === 0) {
11690
11794
  // 删除列时取消标题列
11691
11795
  if (tablePosition.table && tablePosition.table.options?.headerColumn && selectedColumnsIndex.includes(0)) {
11692
- setTableOptions(editor, { headerColumn: false });
11796
+ TableEditor.setTableOptions(editor, { headerColumn: false });
11693
11797
  }
11694
11798
  selectedColumnsIndex
11695
11799
  .sort((a, b) => b - a)
@@ -11700,25 +11804,6 @@ function removeColumnOrRows(editor, tableStore, options) {
11700
11804
  }
11701
11805
  }
11702
11806
 
11703
- const setSelectedCellsBackgroundColor = (editor, color, tableStore) => {
11704
- // 点击自定义颜色面板输入框设置颜色值时,会丢失焦点和选区(目前无法做到焦点同时存在于编辑器和输入框)
11705
- let location;
11706
- if (!editor.selection) {
11707
- const { rangeRef } = THE_EDITOR_PREVIOUS_SELECTION.get(editor);
11708
- location = rangeRef.current.anchor;
11709
- }
11710
- const isHeader = TableEditor.isActiveHeader(editor, location);
11711
- if (color === 'transparent') {
11712
- color = null;
11713
- }
11714
- if ((color === TableHeaderBackgroundColor && isHeader) || (color === SpecialBackgroundColor && !isHeader)) {
11715
- tableStore.setSelectedCellsBackgroundColor(null);
11716
- }
11717
- else {
11718
- tableStore.setSelectedCellsBackgroundColor(color);
11719
- }
11720
- };
11721
-
11722
11807
  function setCellMenuVisibility(editor, menuList, tableInfo) {
11723
11808
  const { selectedCellPositions, isFullscreen, isSelectedTable, selectedRowsIndex, selectedColumnsIndex } = tableInfo;
11724
11809
  const isCellMerged = isSelectedCellMerged(editor);
@@ -11759,32 +11844,6 @@ function setCellMenuVisibility(editor, menuList, tableInfo) {
11759
11844
  });
11760
11845
  }
11761
11846
 
11762
- function splitCell(editor) {
11763
- const tablePosition = createTablePosition(editor);
11764
- const { cell, table, cellEntry } = tablePosition;
11765
- if ((!cell.rowspan && !cell.colspan) || (cell.rowspan === 1 && cell.colspan === 1))
11766
- return editor;
11767
- const cellRow = tablePosition.getRowIndex();
11768
- const cellCol = tablePosition.getColumnIndex();
11769
- resetTableCell(editor, table, cell, cellRow, cellCol);
11770
- Transforms.select(editor, cellEntry[1]);
11771
- Transforms.collapse(editor, { edge: 'end' });
11772
- }
11773
- function resetTableCell(editor, table, cell, cellRow, cellCol) {
11774
- const rowSpanIndex = cellRow + (cell.rowspan || 1) - 1;
11775
- const colSpanIndex = cellCol + (cell.colspan || 1) - 1;
11776
- Editor.withoutNormalizing(editor, () => {
11777
- table.children.map((row, rowIndex) => {
11778
- row.children.map((col, colIndex) => {
11779
- if (rowIndex >= cellRow && rowIndex <= rowSpanIndex && colIndex >= cellCol && colIndex <= colSpanIndex) {
11780
- const path = findPath(editor, col);
11781
- Transforms.setNodes(editor, { colspan: null, rowspan: null, hidden: null }, { at: path });
11782
- }
11783
- });
11784
- });
11785
- });
11786
- }
11787
-
11788
11847
  const getMinAndMaxCellIndex = (editor, selectedCellPositions, maxRow, maxCol, minRow, minCol, table) => {
11789
11848
  const beforeCols = [];
11790
11849
  const beforeRows = [];
@@ -12164,29 +12223,6 @@ class TableStore {
12164
12223
  this.dangerousColumnsIndex = [...Array(pos.getWidth())].map((_, i) => i);
12165
12224
  this.dangerousCells$.next(cells);
12166
12225
  }
12167
- setSelectedCellsBackgroundColor(backgroundColor) {
12168
- const cells = this.selectedCells$.getValue();
12169
- Editor.withoutNormalizing(this.editor, () => {
12170
- cells.map(cell => {
12171
- const cellPath = AngularEditor.findPath(this.editor, cell);
12172
- Transforms.setNodes(this.editor, { backgroundColor }, { at: cellPath });
12173
- });
12174
- });
12175
- }
12176
- clearSelectedCellsContent() {
12177
- const cells = this.getSelectedCellPositions();
12178
- const tablePosition = createTablePosition(this.editor);
12179
- if (tablePosition.isInTable()) {
12180
- Editor.withoutNormalizing(this.editor, () => {
12181
- for (const { row, col } of cells) {
12182
- const cellPath = [...tablePosition.tableEntry[1], row, col];
12183
- const node = Node.get(this.editor, cellPath);
12184
- TableEditor.clearCell(this.editor, [node, cellPath]);
12185
- }
12186
- });
12187
- Transforms.select(this.editor, Editor.start(this.editor, tablePosition.cellEntry[1]));
12188
- }
12189
- }
12190
12226
  /**
12191
12227
  * 聚焦单元格并设置聚焦相关路径及元素
12192
12228
  */
@@ -12306,7 +12342,7 @@ class TheTableContextMenuService {
12306
12342
  visibility: true,
12307
12343
  actionHandle: () => { },
12308
12344
  activeHandle: (event, item) => {
12309
- setSelectedCellsBackgroundColor(this.editor, item.backgroundColor, this.tableStore);
12345
+ TableEditor.setCellsBackgroundColor(this.editor, item.backgroundColor);
12310
12346
  },
12311
12347
  deactivateHandle: (event) => {
12312
12348
  if (event.relatedTarget instanceof HTMLElement) {
@@ -12376,7 +12412,7 @@ class TheTableContextMenuService {
12376
12412
  name: '清空选中区域',
12377
12413
  visibility: true,
12378
12414
  actionHandle: () => {
12379
- this.tableStore.clearSelectedCellsContent();
12415
+ TableEditor.clearCellsContent(this.editor);
12380
12416
  this.tableStore.selectFirstCell();
12381
12417
  }
12382
12418
  },
@@ -12386,7 +12422,7 @@ class TheTableContextMenuService {
12386
12422
  name: '合并单元格',
12387
12423
  visibility: true,
12388
12424
  actionHandle: () => {
12389
- mergeCell(this.editor, this.tableStore.getSelectedCellPositions());
12425
+ TableEditor.mergeCell(this.editor);
12390
12426
  }
12391
12427
  },
12392
12428
  {
@@ -12396,7 +12432,7 @@ class TheTableContextMenuService {
12396
12432
  divider: true,
12397
12433
  visibility: true,
12398
12434
  actionHandle: () => {
12399
- splitCell(this.editor);
12435
+ TableEditor.splitCell(this.editor);
12400
12436
  }
12401
12437
  },
12402
12438
  {
@@ -12628,7 +12664,7 @@ class TheTableOptionsComponent {
12628
12664
  currentOption.isActive = !option.isActive;
12629
12665
  const tableOption = {};
12630
12666
  tableOption[option.key] = currentOption.isActive || false;
12631
- setTableOptions(this.editor, { ...tableOption });
12667
+ TableEditor.setTableOptions(this.editor, { ...tableOption });
12632
12668
  // headerRow 兼容代码, 取消标题行的时候同时设置 row 中的 header 属性
12633
12669
  if (option.key === TableOperations.headerRow && !tableOption[option.key] && this.table.children[0].header) {
12634
12670
  const rowPath = TheEditor.findPath(this.editor, this.table.children[0]);
@@ -12695,7 +12731,7 @@ class TheTableToolbarComponent {
12695
12731
  visibility: false,
12696
12732
  icon: 'table-merge-cells',
12697
12733
  actionHandle: () => {
12698
- mergeCell(this.editor, this.tableStore.getSelectedCellPositions());
12734
+ TableEditor.mergeCell(this.editor);
12699
12735
  this.popoverRef.close();
12700
12736
  this.tableStore.clearSelectedCells();
12701
12737
  }
@@ -12706,7 +12742,7 @@ class TheTableToolbarComponent {
12706
12742
  visibility: false,
12707
12743
  icon: 'table-unmerge-cells',
12708
12744
  actionHandle: () => {
12709
- splitCell(this.editor);
12745
+ TableEditor.splitCell(this.editor);
12710
12746
  this.popoverRef.close();
12711
12747
  this.tableStore.clearSelectedCells();
12712
12748
  }
@@ -12773,7 +12809,7 @@ class TheTableToolbarComponent {
12773
12809
  e.stopPropagation();
12774
12810
  }
12775
12811
  changeColor(newColor) {
12776
- setSelectedCellsBackgroundColor(this.editor, newColor, this.tableStore);
12812
+ TableEditor.setCellsBackgroundColor(this.editor, newColor);
12777
12813
  this.selectedColor = newColor;
12778
12814
  }
12779
12815
  setFullscreen(event) {
@@ -12790,14 +12826,7 @@ class TheTableToolbarComponent {
12790
12826
  }
12791
12827
  setEquallyColumnHandle(event) {
12792
12828
  this.preventDefault(event);
12793
- const columns = this.tableElement.columns;
12794
- const sumWidth = columns.reduce((previousValue, currentValue) => {
12795
- return previousValue + currentValue.width;
12796
- }, 0);
12797
- const equalColumns = columns.map(() => {
12798
- return { width: sumWidth / columns.length };
12799
- });
12800
- setNode(this.editor, { columns: equalColumns }, this.tableElement);
12829
+ TableEditor.setEquallyColumn(this.editor);
12801
12830
  }
12802
12831
  openTableOptionMenu(event) {
12803
12832
  this.preventDefault(event);
@@ -13899,7 +13928,7 @@ class TheTableComponent extends TheBaseElementComponent {
13899
13928
  }), takeUntil(this.destroy$))
13900
13929
  .subscribe((e) => {
13901
13930
  if (e.type === 'keydown') {
13902
- this.tableStore.clearSelectedCellsContent();
13931
+ TableEditor.clearCellsContent(this.editor);
13903
13932
  }
13904
13933
  const isCurrentTableElement = this.nativeElement.contains(e.target);
13905
13934
  if (!isCurrentTableElement || (!this.tableStore.pointerSelection && !this.tableStore.areaSelection)) {
@@ -15679,7 +15708,7 @@ const withTable = (editor) => {
15679
15708
  TableEditor.removeTable(editor);
15680
15709
  }
15681
15710
  else {
15682
- tableComponent.tableStore.clearSelectedCellsContent();
15711
+ TableEditor.clearCellsContent(editor, selectedCellPositions);
15683
15712
  }
15684
15713
  tableComponent.tableService.closeToolbar();
15685
15714
  });