fix: copying table from numbers results in extra columns

This commit is contained in:
yanmao 2021-12-25 22:36:08 +08:00
parent 7659779169
commit bfe96d7713
2 changed files with 15 additions and 6 deletions

View File

@ -721,4 +721,4 @@ class TableComponent<V extends TableValue = TableValue>
export default TableComponent; export default TableComponent;
export { Template }; export { Template, Helper };

View File

@ -14,11 +14,10 @@ import {
decodeCardValue, decodeCardValue,
CARD_VALUE_KEY, CARD_VALUE_KEY,
} from '@aomao/engine'; } from '@aomao/engine';
import TableComponent, { Template } from './component'; import TableComponent, { Template, Helper } from './component';
import locales from './locale'; import locales from './locale';
import './index.css';
import { TableInterface, TableValue } from './types'; import { TableInterface, TableValue } from './types';
import './index.css';
export interface TableOptions extends PluginOptions { export interface TableOptions extends PluginOptions {
hotkey?: string | Array<string>; hotkey?: string | Array<string>;
overflow?: { overflow?: {
@ -295,9 +294,11 @@ class Table<T extends TableOptions> extends Plugin<T> {
if (width.endsWith('pt')) node.css(type, this.convertToPX(width)); if (width.endsWith('pt')) node.css(type, this.convertToPX(width));
}; };
const tables = root.find('table'); const tables = root.find('table');
const helper = new Helper();
tables.each((_, index) => { tables.each((_, index) => {
const node = tables.eq(index); let node = tables.eq(index);
if (!node) return; if (!node) return;
node = helper.normalizeTable(node);
clearWH(node); clearWH(node);
clearWH(node, 'height'); clearWH(node, 'height');
// 表头放在tbody最前面 // 表头放在tbody最前面
@ -343,11 +344,19 @@ class Table<T extends TableOptions> extends Plugin<T> {
if (background) tds.css('background', background); if (background) tds.css('background', background);
const trs = node.find('tr'); const trs = node.find('tr');
let rowSpan = 1;
trs.each((_, index) => { trs.each((_, index) => {
const element = trs.eq(index); const element = trs.eq(index);
const tds = element?.find('td'); const tds = element?.find('td');
if (tds?.length === 0) element?.remove(); if (tds?.length === 0 && rowSpan < 2) {
element?.remove();
}
if (tds && tds?.length > 0) {
rowSpan = (tds[0] as HTMLTableCellElement).rowSpan;
} else {
rowSpan = 1;
}
if (element) { if (element) {
clearWH(element); clearWH(element);