Skip to content

Commit

Permalink
fix(table): 'row' is possibly 'null'
Browse files Browse the repository at this point in the history
  • Loading branch information
Ragnar-Oock committed Aug 12, 2024
1 parent 4fee3cf commit 0f8f082
Showing 1 changed file with 21 additions and 19 deletions.
40 changes: 21 additions & 19 deletions packages/extension-table/src/TableView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,38 +16,40 @@ export function updateColumns(
let nextDOM = colgroup.firstChild
const row = node.firstChild

for (let i = 0, col = 0; i < row.childCount; i += 1) {
const { colspan, colwidth } = row.child(i).attrs
if (row !== null) {
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 += 1, col += 1) {
const hasWidth = overrideCol === col ? overrideValue : (colwidth && colwidth[j]) as number | undefined
const cssWidth = hasWidth ? `${hasWidth}px` : ''
for (let j = 0; j < colspan; j += 1, col += 1) {
const hasWidth = overrideCol === col ? overrideValue : (colwidth && colwidth[j]) as number | undefined
const cssWidth = hasWidth ? `${hasWidth}px` : ''

totalWidth += hasWidth || cellMinWidth
totalWidth += hasWidth || cellMinWidth

if (!hasWidth) {
fixedWidth = false
}
if (!hasWidth) {
fixedWidth = false
}

if (nextDOM === null) {
const colElement = document.createElement('col')
if (nextDOM === null) {
const colElement = document.createElement('col')

colElement.style.setProperty(...getColStyleDeclaration(cellMinWidth, hasWidth))
colgroup.appendChild(colElement)
} else {
if ((nextDOM as HTMLTableColElement).style.width !== cssWidth) {
(nextDOM as HTMLTableColElement).style.setProperty(...getColStyleDeclaration(cellMinWidth, hasWidth))
}
colElement.style.setProperty(...getColStyleDeclaration(cellMinWidth, hasWidth))
colgroup.appendChild(colElement)
} else {
if ((nextDOM as HTMLTableColElement).style.width !== cssWidth) {
(nextDOM as HTMLTableColElement).style.setProperty(...getColStyleDeclaration(cellMinWidth, hasWidth))
}

nextDOM = nextDOM.nextSibling
nextDOM = nextDOM.nextSibling
}
}
}
}

while (nextDOM) {
const after = nextDOM.nextSibling

nextDOM.parentNode!.removeChild(nextDOM)
nextDOM.parentNode?.removeChild(nextDOM)
nextDOM = after
}

Expand Down

0 comments on commit 0f8f082

Please sign in to comment.