code style

This commit is contained in:
Hans Pagel
2021-01-22 23:28:27 +01:00
parent 60305c10f6
commit 719eda2e5b

View File

@@ -1,20 +1,29 @@
// @ts-nocheck // @ts-nocheck
export function updateColumns(node, colgroup, table, cellMinWidth, overrideCol, overrideValue) { export function updateColumns(node, colgroup, table, cellMinWidth, overrideCol, overrideValue) {
let totalWidth = 0; let let totalWidth = 0
fixedWidth = true let fixedWidth = true
let nextDOM = colgroup.firstChild; const let nextDOM = colgroup.firstChild
row = node.firstChild const row = node.firstChild
for (let i = 0, col = 0; i < row.childCount; i += 1) { for (let i = 0, col = 0; i < row.childCount; i += 1) {
const { colspan, colwidth } = row.child(i).attrs const { colspan, colwidth } = row.child(i).attrs
for (let j = 0; j < colspan; j += 1, col += 1) { for (let j = 0; j < colspan; j += 1, col += 1) {
const hasWidth = overrideCol === col ? overrideValue : colwidth && colwidth[j] const hasWidth = overrideCol === col ? overrideValue : colwidth && colwidth[j]
const cssWidth = hasWidth ? `${hasWidth}px` : '' const cssWidth = hasWidth ? `${hasWidth}px` : ''
totalWidth += hasWidth || cellMinWidth totalWidth += hasWidth || cellMinWidth
if (!hasWidth) fixedWidth = false
if (!hasWidth) {
fixedWidth = false
}
if (!nextDOM) { if (!nextDOM) {
colgroup.appendChild(document.createElement('col')).style.width = cssWidth colgroup.appendChild(document.createElement('col')).style.width = cssWidth
} else { } else {
if (nextDOM.style.width !== cssWidth) nextDOM.style.width = cssWidth if (nextDOM.style.width !== cssWidth) {
nextDOM.style.width = cssWidth
}
nextDOM = nextDOM.nextSibling nextDOM = nextDOM.nextSibling
} }
} }
@@ -48,9 +57,13 @@ export class TableView {
} }
update(node) { update(node) {
if (node.type !== this.node.type) return false if (node.type !== this.node.type) {
return false
}
this.node = node this.node = node
updateColumns(node, this.colgroup, this.table, this.cellMinWidth) updateColumns(node, this.colgroup, this.table, this.cellMinWidth)
return true return true
} }