fix(table): rowspan 解析错误

This commit is contained in:
yanmao 2022-01-19 21:00:31 +08:00
parent ccd01af421
commit 4ae53eae13
3 changed files with 32 additions and 21 deletions

View File

@ -102,7 +102,7 @@ class Helper implements HelperInterface {
const colCounts = model.map((trModel) => {
return trModel.length;
});
const MaxColCount = Math.max.apply(Math, [...colCounts]);
const MaxColCount = Math.max(...colCounts);
model.forEach((trModel) => {
if (trModel.length < MaxColCount) {
let addCount = MaxColCount - trModel.length;
@ -488,7 +488,7 @@ class Helper implements HelperInterface {
}
/**
* table
* table
* 1. number html tr
* 2.
* @param {NodeInterface} table Dom
@ -602,11 +602,11 @@ class Helper implements HelperInterface {
});
let shadowCount = shadow.length;
while (shadowCount--) {
if (r === 0) {
tableElement.rows[r].insertCell(0);
} else {
tableElement.rows[r].insertCell();
}
// if (r === 0) {
// tableElement.rows[r].insertCell(0);
// } else {
tableElement.rows[r].insertCell();
// }
}
});
// 修正行高

View File

@ -72,7 +72,6 @@ div[data-card-key="table"].card-selected .data-table, div[data-card-key="table"]
.table-wrapper.active {
margin-top: -42px;
width: 100%;
z-index: 1;
}
.table-wrapper.scrollbar-show {
@ -130,6 +129,7 @@ div[data-card-key="table"].card-selected .data-table, div[data-card-key="table"]
display: none;
width: 100%;
cursor: default;
z-index: 128;
}
.table-wrapper.active .table-cols-header {

View File

@ -283,6 +283,7 @@ class Table<T extends TableOptions = TableOptions> extends Plugin<T> {
width: '@length',
background: '@color',
'background-color': '@color',
display: '*',
},
};
schema.find((r) => r.name === 'td')[0].attributes = {
@ -374,6 +375,16 @@ class Table<T extends TableOptions = TableOptions> extends Plugin<T> {
clearTable(node);
return;
}
let trs = node.find('tr');
trs.each((child) => {
const tr = $(child);
const display = tr.css('display');
if (display === 'none') {
tr.remove();
} else {
tr.css('display', '');
}
});
node = helper.normalizeTable(node);
clearWH(node);
clearWH(node, 'height');
@ -419,29 +430,29 @@ class Table<T extends TableOptions = TableOptions> extends Plugin<T> {
node?.css('background') || node?.css('background-color');
if (background) tds.css('background', background);
const trs = node.find('tr');
trs = node.find('tr');
let rowSpan = 1;
trs.each((_, index) => {
const element = trs.eq(index);
trs.each((child) => {
const tr = $(child);
const tds = element?.find('td');
const tds = tr?.find('td');
if (tds?.length === 0 && rowSpan < 2) {
element?.remove();
tr?.remove();
}
if (tds && tds?.length > 0) {
rowSpan = (tds[0] as HTMLTableCellElement).rowSpan;
} else {
rowSpan = 1;
const spans = tds
.toArray()
.map((td) => (td[0] as HTMLTableCellElement).rowSpan);
rowSpan = Math.max(...spans);
}
if (element) {
clearWH(element);
clearWH(element, 'height');
if (tr) {
clearWH(tr);
clearWH(tr, 'height');
}
const background =
element?.css('background') ||
element?.css('background-color');
tr?.css('background') || tr?.css('background-color');
if (background) tds?.css('background', background);
});
this.editor.nodeId.generateAll(node, true);