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

[lexical-html] Feature: support pasting empty block nodes #6392

Merged
merged 6 commits into from
Jul 12, 2024
Merged

Conversation

potatowagon
Copy link
Contributor

@potatowagon potatowagon commented Jul 11, 2024

Description

An empty block node (eg. <div></div>) in between 2 inline nodes in html places the next inline node on the next line, acting as a linebreak. lexical currently doesnt handle pasting empty block nodes, so there is a missing line break where the empty block node should be.

see test plan for demo.

test cases are added as unit tests

Test plan

<div>
  1
  <div></div>
  2
</div>

Screenshot 2024-07-12 at 11 56 58 AM

Before

Screenshot 2024-07-12 at 11 56 48 AM

After

Screenshot 2024-07-12 at 11 58 12 AM


<ol>
  <li>1
    <div></div>
    2
  </li>
  <li>
  </li>
  <li>3</li>
</ol>

Screenshot 2024-07-12 at 12 05 57 PM

Before

Screenshot 2024-07-12 at 12 09 06 PM

After

Screenshot 2024-07-12 at 12 09 00 PM

Copy link

vercel bot commented Jul 11, 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 Jul 12, 2024 5:33am
lexical-playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 12, 2024 5:33am

@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 Jul 11, 2024
@potatowagon potatowagon marked this pull request as draft July 11, 2024 12:07
Copy link

github-actions bot commented Jul 11, 2024

size-limit report 📦

Path Size
lexical - cjs 28.48 KB (0%)
lexical - esm 28.29 KB (0%)
@lexical/rich-text - cjs 36.9 KB (0%)
@lexical/rich-text - esm 28.14 KB (0%)
@lexical/plain-text - cjs 35.49 KB (0%)
@lexical/plain-text - esm 25.34 KB (0%)
@lexical/react - cjs 38.8 KB (0%)
@lexical/react - esm 29.31 KB (0%)

Comment on lines -54 to -72
{
expectedHTML: `<p dir="ltr"><span data-lexical-text="true">a</span></p><p dir="ltr"><span data-lexical-text="true">b b</span></p><p dir="ltr"><span data-lexical-text="true">c</span></p><p dir="ltr"><span data-lexical-text="true">z </span></p><p dir="ltr"><span data-lexical-text="true">d e </span></p><p dir="ltr"><span data-lexical-text="true">fg</span></p>`,
name: 'nested divs',
pastedHTML: `<div>
a
<div>
b b
<div>
c
<div>
<div></div>
z
</div>
</div>
d e
</div>
fg
</div>`,
},
Copy link
Contributor Author

@potatowagon potatowagon Jul 11, 2024

Choose a reason for hiding this comment

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

moved this to packages/lexical-utils/src/tests/unit/LexicalEventHelpers.test.tsx onPasteFromRichText

because an extra <br /> is introduced in this test setup which i cant repro on the playground or the onPasteFromRichText test env

Copy link
Contributor Author

Choose a reason for hiding this comment

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

codepen
Screenshot 2024-07-12 at 11 30 30 AM

lexical playground

Screenshot 2024-07-12 at 11 30 51 AM

@potatowagon potatowagon changed the title Empty dom [lexical-html] Feature: support pasting empty block nodes Jul 12, 2024
Copy link

@freddymeta freddymeta left a comment

Choose a reason for hiding this comment

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

lgtm

@potatowagon potatowagon added this pull request to the merge queue Jul 12, 2024
Merged via the queue into main with commit 2e26b74 Jul 12, 2024
42 checks passed
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