| Server IP : 34.87.99.72 / Your IP : 216.73.217.31 Web Server : Apache/2.4.46 (Unix) OpenSSL/1.1.1n System : Linux zlock-bitnami-lamp-prod-v2-vm 4.19.0-16-cloud-amd64 #1 SMP Debian 4.19.181-1 (2021-03-19) x86_64 User : bitnami ( 1000) PHP Version : 7.4.18 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : OFF Directory : /home/bitnami/htdocs/app/node_modules/prosemirror-tables/src/ |
Upload File : |
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, fixedWidth = true
let nextDOM = colgroup.firstChild, row = node.firstChild
for (let i = 0, col = 0; i < row.childCount; i++) {
let {colspan, colwidth} = row.child(i).attrs
for (let j = 0; j < colspan; j++, col++) {
let hasWidth = overrideCol == col ? overrideValue : colwidth && colwidth[j]
let 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
nextDOM = nextDOM.nextSibling
}
}
}
while (nextDOM) {
let after = nextDOM.nextSibling
nextDOM.parentNode.removeChild(nextDOM)
nextDOM = after
}
if (fixedWidth) {
table.style.width = totalWidth + "px"
table.style.minWidth = ""
} else {
table.style.width = ""
table.style.minWidth = totalWidth + "px"
}
}