diff --git a/plugins/table/src/component/helper.ts b/plugins/table/src/component/helper.ts index 3cdd8895..8af6855a 100644 --- a/plugins/table/src/component/helper.ts +++ b/plugins/table/src/component/helper.ts @@ -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(); + // } } }); // 修正行高 diff --git a/plugins/table/src/index.css b/plugins/table/src/index.css index 7e7fbc82..6d4c977c 100644 --- a/plugins/table/src/index.css +++ b/plugins/table/src/index.css @@ -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 { diff --git a/plugins/table/src/index.ts b/plugins/table/src/index.ts index 18377cc3..1b9ef844 100644 --- a/plugins/table/src/index.ts +++ b/plugins/table/src/index.ts @@ -283,6 +283,7 @@ class Table extends Plugin { width: '@length', background: '@color', 'background-color': '@color', + display: '*', }, }; schema.find((r) => r.name === 'td')[0].attributes = { @@ -374,6 +375,16 @@ class Table extends Plugin { 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 extends Plugin { 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);