Skip to content

feat(tables): overhaul table cells#1429

Merged
nperez0111 merged 78 commits into
mainfrom
tables
Feb 28, 2025
Merged

feat(tables): overhaul table cells#1429
nperez0111 merged 78 commits into
mainfrom
tables

Conversation

@nperez0111
Copy link
Copy Markdown
Contributor

@nperez0111 nperez0111 commented Feb 12, 2025

💖 This feature is sponsored by Agree.com

This PR is attempting to address the following for table cells:

  • Backgrounds
  • Text Color
  • Alignment
  • colspan & rowspan
  • header cells
Screen.Recording.2025-02-20.at.14.19.23.mp4

@vercel
Copy link
Copy Markdown

vercel Bot commented Feb 12, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
blocknote ✅ Ready (Inspect) Visit Preview Feb 28, 2025 6:15pm
blocknote-website ✅ Ready (Inspect) Visit Preview Feb 28, 2025 6:15pm

Comment thread packages/core/src/blocks/defaultBlocks.ts Outdated
Comment thread packages/core/src/api/blockManipulation/setupTestEnv.ts
* fix: table cell merging

* fix: better merging of styled text in table cells
* fix: table cell merging

* fix: better merging of styled text in table cells
Copy link
Copy Markdown
Collaborator

@matthewlipski matthewlipski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Left some comments - mostly questions and some small suggestions

Comment thread packages/react/src/editor/ComponentsContext.tsx Outdated
Comment thread packages/core/src/blocks/TableBlockContent/TableBlockContent.ts Outdated

.bn-editor [data-content-type="table"] th {
font-weight: bold;
text-align: left;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this still needs to be set as table headers default to center alignment, so they're still centered even when the text alignment is set to left

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this is a style thing, but table headers are usually centered.

Also, I didn't want this CSS to conflict with manually setting the text alignment on the cell level given it is a low specificity selector:

[data-text-alignment="right"] {
  justify-content: flex-end;
  text-align: right;
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, though I think it's still weird that currently changing text alignment on a header cell via the formatting toolbar has no effect between alignment left/center. I think if we want them to be centered by default, we should do it through the text alignment prop.

Comment thread packages/mantine/src/style.css Outdated
blockTypeSelectItems?: BlockTypeSelectItem[]
): JSX.Element[] => [
<BlockTypeSelect key={"blockTypeSelect"} items={blockTypeSelectItems} />,
<TableCellMergeButton key={"tableCellMergeButton"} />,
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would put this at the end of the formatting toolbar instead of at the start

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, not sure here. I want to make the feature more known since it only ever shows for table cells. I feel like that follows the existing pattern like the file specific buttons.

Comment thread packages/xl-pdf-exporter/src/pdf/util/table/Table.tsx Outdated
> = {
type: "tableContent";
columnWidths?: (number | undefined)[];
headerRows?: number;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How come these are numbers? Isn't it only possible to have 1 of each?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We discussed this here: #1425

But, the idea is that we could in the future support multiple headerRows and headerColumns, but for now we only expose in the UI a single toggle for this. Just gives us more room in the future to implement something more complex if needed

Comment thread packages/react/src/components/TableHandles/TableCellHandle.tsx Outdated
@matthewlipski
Copy link
Copy Markdown
Collaborator

I just noticed that after setting text alignment in a cell, the selection closes and formatting toolbar disappears. I don't think it's necessary to fix before merging, but smth we may want to look into next week

@nperez0111
Copy link
Copy Markdown
Contributor Author

I just noticed that after setting text alignment in a cell, the selection closes and formatting toolbar disappears. I don't think it's necessary to fix before merging, but smth we may want to look into next week

@matthewlipski I took a quick look into this to see what we can do here, and this is what is happening here:

editor.updateBlock(block, {
type: "table",
content: {
...(block.content as TableContent<any, any>),
type: "tableContent",
rows: newTable,
} as any,
});
// Have to reset text cursor position to the block as `updateBlock`
// moves the existing selection out of the block.
editor.setTextCursorPosition(block);

So, the updateBlock call is completely replacing the table content, which causes the selection to be lost in the replaceRange step. What I'd like out of this is 1 of two things, either make the selection more low-level so that we can set the position before & after to allow it to be in the same spot. Or, for the update block function to be smarter & not replace the whole range, just the "affected" porition, making a fine-grained update of the diff of the changes so that it knows it doesn't really need to mess with the selection at all. Maybe even both.

Definitely think it is out of scope for the moment

Copy link
Copy Markdown
Collaborator

@YousefED YousefED left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

had a quick glance at final state. two questions:

Also; enjoy the fun of closing all related issues 🙌🎉

@nperez0111
Copy link
Copy Markdown
Contributor Author

* example links to [blocknotejs.org/docs/editor-basics/tables](https://www.blocknotejs.org/docs/editor-basics/tables) which doesn't exist

Whoops, meant to link to advanced tables, I renamed it somewhere

* did you want to simplify the types (we discussed this last week) or keep as is for now?

Sorry, meant to write something about why I decided not to do this atm. Basically it came down to:

  • To make this change, I would have needed to de-couple the assumptions of the types that can be used for the initialContent vs. the partial (for updates) vs. the defined types. I didn't want to spend the time to work on this because it was only a reorganizing of the code that we've already validated here.
  • I took a look at what this would actually simplify, and it ended up only being like 5 callsites, so I felt like it was not worth the effort to literally get less functionality for only marginally simpler code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants