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

Basic External Copy + Paste for Tables #1579

Merged
merged 3 commits into from
Apr 4, 2022

Conversation

tylerjbainbridge
Copy link
Contributor

This PR adds Copy + Paste support for Tables coming from Google Docs, Quip, and Google Sheets. There are tests to back it up.

The forChild function now returns a node which gives the developer the control to skip a child, replace the node, modify the node, or do nothing, for each child. This is useful for TableCells which should have all text wrapped in inner paragraph block, but some external sources (such as Quip) do not nest text in paragraphs.

There was also a small bug (?) where the forChild function would run for all children of the parent, not just immediate children. I changed the API to only run the forChild function from it's direct parent.

@vercel
Copy link

vercel bot commented Mar 30, 2022

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployments, click below or on the icon next to each commit.

lexical – ./packages/lexical-website

🔍 Inspect: https://vercel.com/fbopensource/lexical/6pTh45uXhr24RYGFowvTBoAncNtG
✅ Preview: https://lexical-git-tables-copy-paste-external-fbopensource.vercel.app

lexical-playground – ./packages/lexical-playground

🔍 Inspect: https://vercel.com/fbopensource/lexical-playground/8YLo3nwh4G4HURnxXww3jJzBXFEA
✅ Preview: https://lexical-playground-git-tables-copy-paste-external-fbopensource.vercel.app

lexical-website-new – ./packages/lexical-website-new

🔍 Inspect: https://vercel.com/fbopensource/lexical-website-new/ANwraFA6zwXE2G4LBnPZxvXHis7J
✅ Preview: https://lexical-website-new-git-tables-copy-paste-external-fbopensource.vercel.app

@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 Mar 30, 2022
lexicalNodes.push(currentLexicalNode);
for (const [, forChildFunction] of forChildMap) {
forChildFunction(currentLexicalNode);
const mapChildFunc = parentNode && forChildMap.get(parentNode.nodeName);
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it needs to run for all children because of things like <strong> where you want to apply some mutation to evert text node descendant (i.e., make them bold).

packages/lexical-table/src/LexicalTableCellNode.js Outdated Show resolved Hide resolved
packages/lexical-table/src/LexicalTableNode.js Outdated Show resolved Hide resolved
forChildFunction(currentLexicalNode);
currentLexicalNode = forChildFunction(
currentLexicalNode,
parentLexicalNode,
Copy link
Contributor

Choose a reason for hiding this comment

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

You need this because you can't derive the parent from the currentNode because it hasn't been appended yet?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, exactly. Do you think that's too confusing?

currentLexicalNode.getParent() evaluates to null, so there's no way to derive the hierarchy.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe we should have a special type for DetachedLexicalNode? That way you know certain methods won't work.

Copy link
Contributor

@acywatson acywatson left a comment

Choose a reason for hiding this comment

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

This looks good to me. Thanks!

@tylerjbainbridge tylerjbainbridge merged commit 8445055 into main Apr 4, 2022
@tylerjbainbridge tylerjbainbridge deleted the tables-copy-paste-external branch April 4, 2022 20:14
acywatson pushed a commit that referenced this pull request Apr 9, 2022
* Basic External Copy + Paste

* Fix paste CodeBlock

* Handle CodeBlock TableRows with noop conversion so core TableRows arent rendered instead
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.

3 participants