From 15480e0d41d0f5300e215ec7be75e240d1160491 Mon Sep 17 00:00:00 2001 From: Max Date: Tue, 15 Mar 2022 15:56:06 +0100 Subject: fix: use tableRole `row` for headerRow Prosemirrors `goToNextCell` command checks for a node with tableRole `row`. Without this the command fails. Signed-off-by: Max --- src/nodes/Table.js | 35 +++++++---------------------------- src/nodes/TableHeadRow.js | 2 +- 2 files changed, 8 insertions(+), 29 deletions(-) diff --git a/src/nodes/Table.js b/src/nodes/Table.js index ac667eee0..d3bec5aa1 100644 --- a/src/nodes/Table.js +++ b/src/nodes/Table.js @@ -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({ diff --git a/src/nodes/TableHeadRow.js b/src/nodes/TableHeadRow.js index a0b9fedd0..f37e5530e 100644 --- a/src/nodes/TableHeadRow.js +++ b/src/nodes/TableHeadRow.js @@ -3,7 +3,7 @@ import { Node, mergeAttributes } from '@tiptap/core' export default Node.create({ name: 'tableHeadRow', content: 'tableHeader*', - tableRole: 'headRow', + tableRole: 'row', addOptions() { return { -- cgit v1.2.3