-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[lexical-table][lexical-playground] Feature: Add column widths to TableNode #6625
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
size-limit report 📦
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall this seems like a great approach. There are going to be some issues with sharing of __colWidths
because node properties can not be shared across versions (unless they are effectively immutable). Removing the rest of the width support from TableCellNode would also make sense, and of course fixing the tests is going to be the big thing.
packages/lexical-playground/src/plugins/TableCellResizer/index.tsx
Outdated
Show resolved
Hide resolved
@etrepum thanks for the review!
Could you please expand on this? I'm not sure what this means I'll take a look at the tests |
So the way that Lexical works is that the first time you get a writable version of a node in an update cycle it will clone the node. The previous version of the node should be considered completely frozen and immutable. However, in this implementation you have a mutable array property that is returned and mutated in-place with slice, so any changes to that array would also affect all previous versions of that node. It breaks undo/redo and any history or rollback related feature in general because version B is using the identical array from version A and it gets mutated in-place. |
Thanks, I assume there's no other nodes that do this at the moment? Would it be enough to type the property as This worked well to flag an error in another place I had mutated it. |
Using the readonly type is probably sufficient, we don't do a lot of runtime enforcement of these kinds of constraints that the type checker can enforce especially in production. Copying it everywhere even when not necessary is something to be avoided (e.g. copying in the setter, getter and clone would be most robust but do unnecessary work pretty often). It's not done a lot in this codebase, I can't think of many properties that are a mutable type to begin with. It's normally primitive value types that don't have any sort of sharing issues. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suspect that there's more code & tests that should be written to handle when the column count of a table changes (both insert and remove) but this is looking great so far
70be009
to
2415c5b
Compare
It looks like the tests are passing, when you think it's ready for review (this PR is still in draft) and then we'll review it again and merge when ready |
There's a lot of noise from fixing the tests, but I've tried to keep the commits clean. I added one unit test that covers setting widths and inserting a column. The e2e tests have some resizing merged cells which verifies the colwidth output. Let me know if there's any other cases you'd like covered. As far as I can tell the remaining failures are due to flakes. |
I think the remaining failures are not just flaky, I gave the failed tests a couple additional runs. Some of it is HTML differences because of the added
|
Ah I see now, thank you. Fixed. As a side note, I wasn't able to run the collab e2e tests locally. With the server running
|
Ah that's interesting, it looks like there's a dev mode collab bug probably due to react strict mode. I think because the effects run twice the provider is disconnecting the websocket, I wonder when that started. The ci versions appear to work (although those also trigger a build which can be a bit slower to start). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for all your work on this!
Thanks! Keen to make use of this |
Ports over facebook/lexical#6625
Description
This PR adds an optional
colWidths
property to TableNode, which renders a<colgroup>
element within tables.Defining the column widths has 2 main advantages:
table-layout: fixed
If using
table-layout: fixed
, you must set a table width. Lexical playground usesmax-content
which masks some issues. If you want to truncate text within the table, the best way is to change the table width tofit-content
(and add css to truncate).However, without a
<col>
element, a table with layoutfixed
will use the first row to determine column widths for the rest of the table. If there are merged cells in the first row, this makes it impossible to correctly size (and resize) columns in the remaining rows.Adding
colWidths
to TableNode is the cleanest way to enable the ability to truncate text in tables and simplify resizing.Changes
colWidth
to TableNode (an array of pixel width numbers)createDOM
to render<colgroup>
and<col>
elements with widths, ifcolWidths
is set.TableCellResizerPlugin
to get and setcolWidths
for better resizingCloses #6623 #6624 (resize bugs)
Now it is also possible to truncate text in cells. This was not possible before and is the main motivation for this PR
Test plan
Since this changes the output of TableNode, it breaks many tests that expect specific HTML. I will update tests if maintainers are open to this approach.
Demo
🔉 narrated
https://github.com/user-attachments/assets/aa7902f2-df6f-4975-b83c-2a28e7f086c5