facebook / lexical

Lexical is an extensible text editor framework that provides excellent reliability, accessibility and performance.
https://lexical.dev
MIT License
17.5k stars 1.45k forks source link

[RFC][NO MERGE] flatten block nodes #5834

Closed potatowagon closed 2 weeks ago

potatowagon commented 1 month ago

draft only

see issue #4465

test case:

<div>
  a
  <div>
    b
    <div>
      c
      <div>
        <div>
        </div>
        z
      </div>
    </div>
    d
    e
  </div>
  fg
</div>

https://github.com/facebook/lexical/assets/19604232/29addc46-ce88-4477-b8e7-30209ad481f5


This will break nested block nodes like list nodes, because we are flattening them

fixed in commit a1f17f6db537f24146fbd53bb4eaf9ef72158fed which only limits the unnesting to block nodes in para nodes

test case

<ol class="PlaygroundEditorTheme__ol1"><li value="1" class="PlaygroundEditorTheme__listItem"><span style="white-space: pre-wrap;">ssvsdvs</span></li><li value="2" class="PlaygroundEditorTheme__listItem"><span style="white-space: pre-wrap;">vsvsvsv</span></li><li value="3" class="PlaygroundEditorTheme__listItem"><span style="white-space: pre-wrap;">svsvsvs</span></li><li value="4" class="PlaygroundEditorTheme__listItem PlaygroundEditorTheme__nestedListItem"><ol class="PlaygroundEditorTheme__ol2"><li value="1" class="PlaygroundEditorTheme__listItem"><span style="white-space: pre-wrap;">fvsdvsdv</span></li><li value="2" class="PlaygroundEditorTheme__listItem"><span style="white-space: pre-wrap;">sdvsvdsv</span></li><li value="3" class="PlaygroundEditorTheme__listItem"><span style="white-space: pre-wrap;">sdvsdvsd</span></li></ol></li><li value="4" class="PlaygroundEditorTheme__listItem"><span style="white-space: pre-wrap;">sdvsdvdsv</span></li><li value="5" class="PlaygroundEditorTheme__listItem"><span style="white-space: pre-wrap;">sdvsdvdsv</span></li><li value="6" class="PlaygroundEditorTheme__listItem"><span style="white-space: pre-wrap;">sdvsdvsdv</span></li></ol>

in codepen:

Screenshot 2024-04-05 at 4 38 29 PM

in lexical:

Screenshot 2024-04-05 at 4 38 47 PM

after a1f17f6db537f24146fbd53bb4eaf9ef72158fed fix

Screenshot 2024-04-05 at 6 08 48 PM

table in a div

test case:

<div>
<table class="PlaygroundEditorTheme__table"><colgroup><col><col></colgroup><tbody><tr><th class="PlaygroundEditorTheme__tableCell PlaygroundEditorTheme__tableCellHeader" style="border: 1px solid black; width: 350px; vertical-align: top; text-align: start; background-color: rgb(242, 243, 245);"><p class="PlaygroundEditorTheme__paragraph"><br></p></th><th class="PlaygroundEditorTheme__tableCell PlaygroundEditorTheme__tableCellHeader" style="width: 398px; border: 1px solid black; vertical-align: top; text-align: start; background-color: rgb(242, 243, 245);"><p class="PlaygroundEditorTheme__paragraph"><br></p></th></tr><tr><th class="PlaygroundEditorTheme__tableCell PlaygroundEditorTheme__tableCellHeader" style="border: 1px solid black; width: 350px; vertical-align: top; text-align: start; background-color: rgb(242, 243, 245);"><p class="PlaygroundEditorTheme__paragraph"><br></p></th><td class="PlaygroundEditorTheme__tableCell" style="width: 398px; border: 1px solid black; vertical-align: top; text-align: start;"><ol class="PlaygroundEditorTheme__ol1"><li value="1" class="PlaygroundEditorTheme__listItem"><span style="white-space: pre-wrap;">sdcsdcsccsc</span></li><li value="2" class="PlaygroundEditorTheme__listItem"><span style="white-space: pre-wrap;">dscsc</span></li><li value="3" class="PlaygroundEditorTheme__listItem"><span style="white-space: pre-wrap;">sdcsc</span></li><li value="4" class="PlaygroundEditorTheme__listItem"><span style="white-space: pre-wrap;">scscs</span></li><li value="5" class="PlaygroundEditorTheme__listItem"><span style="white-space: pre-wrap;">csdcs</span></li><li value="6" class="PlaygroundEditorTheme__listItem"><span style="white-space: pre-wrap;">dcscsc</span></li><li value="7" class="PlaygroundEditorTheme__listItem"><span style="white-space: pre-wrap;">vsdvsdv</span></li><li value="8" class="PlaygroundEditorTheme__listItem"><span style="white-space: pre-wrap;">sdsv</span></li><li value="9" class="PlaygroundEditorTheme__listItem"><span style="white-space: pre-wrap;">sdvsvsdv</span></li><li value="10" class="PlaygroundEditorTheme__listItem"><span style="white-space: pre-wrap;">svsdvds</span></li><li value="11" class="PlaygroundEditorTheme__listItem PlaygroundEditorTheme__nestedListItem"><ol class="PlaygroundEditorTheme__ol2"><li value="1" class="PlaygroundEditorTheme__listItem"><span style="white-space: pre-wrap;">svsdvsd</span></li><li value="2" class="PlaygroundEditorTheme__listItem"><span style="white-space: pre-wrap;">vsvdsv</span></li><li value="3" class="PlaygroundEditorTheme__listItem PlaygroundEditorTheme__nestedListItem"><ol class="PlaygroundEditorTheme__ol3"><li value="1" class="PlaygroundEditorTheme__listItem"><span style="white-space: pre-wrap;">dfdbfdb</span></li><li value="2" class="PlaygroundEditorTheme__listItem"><span style="white-space: pre-wrap;">dfbdfbdfb</span></li><li value="3" class="PlaygroundEditorTheme__listItem"><span style="white-space: pre-wrap;">f</span><br><span style="white-space: pre-wrap;">dfbdf</span><br><span style="white-space: pre-wrap;">dfbdfb</span><br><span style="white-space: pre-wrap;">dfbdfb</span></li><li value="4" class="PlaygroundEditorTheme__listItem"></li></ol></li></ol></li></ol><p class="PlaygroundEditorTheme__paragraph" dir="ltr"><br></p><p class="PlaygroundEditorTheme__paragraph"><br></p><p class="PlaygroundEditorTheme__paragraph"><br></p></td></tr></tbody></table>
</div>

codepen:

Screenshot 2024-04-05 at 5 57 40 PM

lexical:

Screenshot 2024-04-05 at 5 58 28 PM

handle divs in li

<ol>
  <li>
    <div>
      1
      <div>
        2
        <div>
          <div>
            <div>
              3
              <div>
  </li>
  <div>
    <li>
      <div>
        1
        <div>
          2
          <div>
            <div>
              <div>
                3
                <div>
    </li>
  </div>
</ol>
vercel[bot] commented 1 month ago

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

Name Status Preview Comments Updated (UTC)
lexical ❌ Failed (Inspect) Apr 5, 2024 10:49am
lexical-playground ❌ Failed (Inspect) Apr 5, 2024 10:49am
potatowagon commented 1 month ago
<ol>
  <li>
    1
    <div>
      2
    </div>
    3
  </li>
  <li>
    A
    <div>
      B
    </div>
    3
  </li>
</ol>