Skip to content
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

Fix copying html table with unequal number of cells in a row #5824

Merged
merged 8 commits into from
Apr 17, 2024

Conversation

KatsiarynaDzibrova
Copy link
Contributor

Issue: when copying html table with not equal number of cells in row the pasted table is broken. The number of cells in each row is different and it breaks on selection.
Fix: adding empty cells on paste

Before:
old-copy-partial

After:
new-copy-partial

Copy link

vercel bot commented Apr 4, 2024

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

Name Status Preview Comments Updated (UTC)
lexical ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 17, 2024 10:28am
lexical-playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 17, 2024 10:28am

@facebook-github-bot
Copy link
Contributor

Hi @KatsiarynaDzibrova!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@KatsiarynaDzibrova KatsiarynaDzibrova changed the title Fix copying html table with unequal number of columns Fix copying html table with not equal number of cells in a row Apr 4, 2024
ivailop7
ivailop7 previously approved these changes Apr 4, 2024
Copy link
Collaborator

@ivailop7 ivailop7 left a comment

Choose a reason for hiding this comment

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

Fantastic! Thank you, Katsia!

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Apr 4, 2024
@facebook-github-bot
Copy link
Contributor

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

@ivailop7
Copy link
Collaborator

ivailop7 commented Apr 4, 2024

@KatsiarynaDzibrova tests are still failing

@KatsiarynaDzibrova
Copy link
Contributor Author

@KatsiarynaDzibrova tests are still failing

Looking into it

Copy link
Member

@zurfyx zurfyx left a comment

Choose a reason for hiding this comment

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

Thank you, have you considered having a transform for this at the plugin level? While I think this approach is correct ultimately we want to lean toward a $normalizer (aka Schemas) which would help mitigate bad structures originating from text input and plugins.

This might also help simplify the additional exported utilities introduced in this PR. WDYT?

@KatsiarynaDzibrova
Copy link
Contributor Author

Thank you, have you considered having a transform for this at the plugin level? While I think this approach is correct ultimately we want to lean toward a $normalizer (aka Schemas) which would help mitigate bad structures originating from text input and plugins.

This might also help simplify the additional exported utilities introduced in this PR. WDYT?

I thought about implementing it on plugin level, but I assumed that table plugin deals only with cells merging and background color logic.
Can you please explain what do you mean by $normalizer (aka Schemas)? I am not familiar with it

@ivailop7
Copy link
Collaborator

ping @zurfyx

@zurfyx
Copy link
Member

zurfyx commented Apr 11, 2024

The normalizer was an example, we definitely want to think about it further before we can propose something generic.

But you can still have the table plugin do these checks for you.

editor.registerTransform(TableCell, node => {
  // validate correct number of cells and rows
});

Because of the current implementation which relies on a full scan of rows and column this might not be very efficient for long tables so we may want to restrict to the paste event for now, you can control this via commands. In the future, we would ideally keep track of the previously explored columns and rows and resume the check from the position instead of scanning the full table.

@KatsiarynaDzibrova
Copy link
Contributor Author

The normalizer was an example, we definitely want to think about it further before we can propose something generic.

But you can still have the table plugin do these checks for you.

editor.registerTransform(TableCell, node => {
  // validate correct number of cells and rows
});

Because of the current implementation which relies on a full scan of rows and column this might not be very efficient for long tables so we may want to restrict to the paste event for now, you can control this via commands. In the future, we would ideally keep track of the previously explored columns and rows and resume the check from the position instead of scanning the full table.

I agree that it makes sense to trigger this logic only on paste.
But does it mean creating a new command, which will be dispatched in convertTableElement? Because PASTE_COMMAND can't be used here as it's called before the node is created and I don't think there is another existing command that can be used here.
I don't think it's worth creating a new command if we plan to remove it later. Maybe it's better to leave the logic on TableNode level and move it later if the normalizer is created?

zurfyx
zurfyx previously approved these changes Apr 15, 2024
Copy link
Member

@zurfyx zurfyx left a comment

Choose a reason for hiding this comment

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

Thanks for iterating on this and sorry for keeping you blocked for so long, stamping but please address the last comment before merging

packages/lexical-table/src/LexicalTableUtils.ts Outdated Show resolved Hide resolved
},
COMMAND_PRIORITY_EDITOR,
),
editor.registerNodeTransform(TableNode, (node) => {
Copy link
Member

Choose a reason for hiding this comment

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

Let's see how this perform, otherwise we may want to add a check that this only happens strictly on clipboard paste.

@Sahejkm this is the case we discussed offline, ideally this map is cached and future checks are O(1).

zurfyx
zurfyx previously approved these changes Apr 16, 2024
Comment on lines 717 to 720
export function $computeTableMapSkipCellCheck(grid: TableNode) {
const [tableMap] = $computeTableMapHelper(grid, null, null);
return tableMap;
}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
export function $computeTableMapSkipCellCheck(grid: TableNode) {
const [tableMap] = $computeTableMapHelper(grid, null, null);
return tableMap;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't see any changes here

Copy link
Collaborator

Choose a reason for hiding this comment

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

@zurfyx I don't see any changes either in the suggestion, did you mean something else here?

Copy link
Member

Choose a reason for hiding this comment

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

This function becomes redundant now that the other takes nullable values, doesn't it? Should we use the other function instead?

@ivailop7 ivailop7 changed the title Fix copying html table with not equal number of cells in a row Fix copying html table with unequal number of cells in a row Apr 17, 2024
@ivailop7 ivailop7 merged commit b0af574 into facebook:main Apr 17, 2024
45 checks passed
@zurfyx zurfyx mentioned this pull request May 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants