Skip to content

Commit

Permalink
fix: use tableRole row for headerRow
Browse files Browse the repository at this point in the history
Prosemirrors `goToNextCell` command checks for a node with tableRole `row`.
Without this the command fails.

Signed-off-by: Max <max@nextcloud.com>
  • Loading branch information
max-nextcloud committed Mar 16, 2022
1 parent 406f6fb commit 6e969d5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 29 deletions.
35 changes: 7 additions & 28 deletions src/nodes/Table.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,48 +30,27 @@ const tableCaption = Node.create({

})

function getTableNodeTypes(schema) {
if (schema.cached.tableNodeTypes) {
return schema.cached.tableNodeTypes
}

const roles = {}

Object.keys(schema.nodes).forEach(type => {
const nodeType = schema.nodes[type]

if (nodeType.spec.tableRole) {
roles[nodeType.spec.tableRole] = nodeType
}
})

schema.cached.tableNodeTypes = roles

return roles
}

function createTable(schema, rowsCount, colsCount, cellContent) {
const types = getTableNodeTypes(schema)
const headerCells = []
const cells = []
for (let index = 0; index < colsCount; index += 1) {
const cell = types.cell.createAndFill()
const cell = schema.nodes.tableCell.createAndFill()
if (cell) {
cells.push(cell)
}
const headerCell = types.header_cell.createAndFill()
const headerCell = schema.nodes.tableHeader.createAndFill()
if (headerCell) {
headerCells.push(headerCell)
}
}
const headRow = types.headRow.createChecked(null, headerCells)
const headRow = schema.nodes.tableHeadRow.createChecked(null, headerCells)
const rows = []
for (let index = 1; index < rowsCount; index += 1) {
rows.push(types.row.createChecked(null, cells))
rows.push(schema.nodes.tableRow.createChecked(null, cells))
}
const head = types.head.createChecked(null, headRow)
const body = types.body.createChecked(null, rows)
return types.table.createChecked(null, [head, body])
const head = schema.nodes.tableHead.createChecked(null, headRow)
const body = schema.nodes.tableBody.createChecked(null, rows)
return schema.nodes.table.createChecked(null, [head, body])
}

export default Table.extend({
Expand Down
2 changes: 1 addition & 1 deletion src/nodes/TableHeadRow.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Node, mergeAttributes } from '@tiptap/core'
export default Node.create({
name: 'tableHeadRow',
content: 'tableHeader*',
tableRole: 'headRow',
tableRole: 'row',

addOptions() {
return {
Expand Down

0 comments on commit 6e969d5

Please sign in to comment.