fix setCellAttributes, fix linting errors in the TableView

This commit is contained in:
Hans Pagel
2021-01-22 23:25:13 +01:00
parent bcf441ea8a
commit 60305c10f6
3 changed files with 75 additions and 51 deletions

View File

@@ -1,45 +1,20 @@
// @ts-nocheck
export class TableView {
constructor(node, cellMinWidth) {
this.node = node
this.cellMinWidth = cellMinWidth
this.dom = document.createElement('div')
this.dom.className = 'tableWrapper'
this.table = this.dom.appendChild(document.createElement('table'))
this.colgroup = this.table.appendChild(document.createElement('colgroup'))
updateColumns(node, this.colgroup, this.table, cellMinWidth)
this.contentDOM = this.table.appendChild(document.createElement('tbody'))
}
update(node) {
if (node.type != this.node.type) return false
this.node = node
updateColumns(node, this.colgroup, this.table, this.cellMinWidth)
return true
}
ignoreMutation(record) {
return record.type == 'attributes' && (record.target == this.table || this.colgroup.contains(record.target))
}
}
export function updateColumns(node, colgroup, table, cellMinWidth, overrideCol, overrideValue) {
let totalWidth = 0; let
fixedWidth = true
let nextDOM = colgroup.firstChild; const
row = node.firstChild
for (let i = 0, col = 0; i < row.childCount; i++) {
for (let i = 0, col = 0; i < row.childCount; i += 1) {
const { colspan, colwidth } = row.child(i).attrs
for (let j = 0; j < colspan; j++, col++) {
const hasWidth = overrideCol == col ? overrideValue : colwidth && colwidth[j]
for (let j = 0; j < colspan; j += 1, col += 1) {
const hasWidth = overrideCol === col ? overrideValue : colwidth && colwidth[j]
const cssWidth = hasWidth ? `${hasWidth}px` : ''
totalWidth += hasWidth || cellMinWidth
if (!hasWidth) fixedWidth = false
if (!nextDOM) {
colgroup.appendChild(document.createElement('col')).style.width = cssWidth
} else {
if (nextDOM.style.width != cssWidth) nextDOM.style.width = cssWidth
if (nextDOM.style.width !== cssWidth) nextDOM.style.width = cssWidth
nextDOM = nextDOM.nextSibling
}
}
@@ -59,3 +34,27 @@ export function updateColumns(node, colgroup, table, cellMinWidth, overrideCol,
table.style.minWidth = `${totalWidth}px`
}
}
export class TableView {
constructor(node, cellMinWidth) {
this.node = node
this.cellMinWidth = cellMinWidth
this.dom = document.createElement('div')
this.dom.className = 'tableWrapper'
this.table = this.dom.appendChild(document.createElement('table'))
this.colgroup = this.table.appendChild(document.createElement('colgroup'))
updateColumns(node, this.colgroup, this.table, cellMinWidth)
this.contentDOM = this.table.appendChild(document.createElement('tbody'))
}
update(node) {
if (node.type !== this.node.type) return false
this.node = node
updateColumns(node, this.colgroup, this.table, this.cellMinWidth)
return true
}
ignoreMutation(record) {
return record.type === 'attributes' && (record.target === this.table || this.colgroup.contains(record.target))
}
}