From 06e27b6395eea386c08bd276eeaffbd5d1822f22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Alves?= Date: Fri, 6 Sep 2024 20:17:09 +0100 Subject: [PATCH] feat: add colspan and colwidth to blocknote api --- docs/pages/docs/editor-basics/document-structure.mdx | 6 ++++-- packages/core/src/api/nodeConversions/nodeConversions.ts | 8 +++++++- packages/core/src/schema/blocks/types.ts | 4 ++++ 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/docs/pages/docs/editor-basics/document-structure.mdx b/docs/pages/docs/editor-basics/document-structure.mdx index 223b16ea16..df572d2e80 100644 --- a/docs/pages/docs/editor-basics/document-structure.mdx +++ b/docs/pages/docs/editor-basics/document-structure.mdx @@ -73,7 +73,7 @@ The `styles` property is explained below. While most blocks use an array of `InlineContent` objects to describe their content (e.g.: paragraphs, headings, list items). Some blocks, like [images](/docs/editor-basics/default-schema#image), don't contain any rich text content, so their `content` fields will be `undefined`. -[Tables](/docs/editor-basics/default-schema#table) are also different, as they contain `TableContent`. Here, each table cell is represented as an array of `InlineContent` objects with a width: +[Tables](/docs/editor-basics/default-schema#table) are also different, as they contain `TableContent`. Here, each table cell is represented as an array of `InlineContent` objects with a width, colspan and rowspan: ```typescript type TableContent = { @@ -81,7 +81,9 @@ type TableContent = { rows: { cells: { content: InlineContent, - width?: number + width?: number, + colspan?: number, + rowspan?: number }[][]; }[]; }; diff --git a/packages/core/src/api/nodeConversions/nodeConversions.ts b/packages/core/src/api/nodeConversions/nodeConversions.ts index 88a39145c0..3c1cbee6ad 100644 --- a/packages/core/src/api/nodeConversions/nodeConversions.ts +++ b/packages/core/src/api/nodeConversions/nodeConversions.ts @@ -186,7 +186,11 @@ export function tableContentToNodes< } const cellNode = schema.nodes["tableCell"].create( - { colwidth: [cell.width] || null }, + { + colwidth: [cell.width] || null, + colspan: cell.colspan || 1, + rowspan: cell.rowspan || 1 + }, pNode ); columnNodes.push(cellNode); @@ -299,6 +303,8 @@ function contentNodeToTableContent< cellNode.attrs.colwidth !== null ? cellNode.attrs.colwidth[0] : undefined, + colspan: cellNode.attrs.colspan || 1, + rowspan: cellNode.attrs.rowspan || 1 }); }); diff --git a/packages/core/src/schema/blocks/types.ts b/packages/core/src/schema/blocks/types.ts index d3d0ba3d4b..398c0547e5 100644 --- a/packages/core/src/schema/blocks/types.ts +++ b/packages/core/src/schema/blocks/types.ts @@ -158,6 +158,8 @@ export type CellContent< > = { content: InlineContent[]; width?: number; + colspan?: number; + rowspan?: number; }; // A BlockConfig has all the information to get the type of a Block (which is a specific instance of the BlockConfig. @@ -241,6 +243,8 @@ export type PartialCellContent< > = { content: PartialInlineContent; width?: number; + colspan?: number; + rowspan?: number; }; type PartialBlockFromConfigNoChildren<