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

Cleanup ArtificialNode__DO_NOT_USE #5966

Open potatowagon opened 3 weeks ago

potatowagon commented 3 weeks ago

A followup task to #5857

During html pasting, ArtificialNode is a temp wrapper node to group nodes within block elements that should be separated by a linebreak (
). It is currently represented by a class extending ElementNode to be compatible with the typings in packages/lexical-html/src/index.ts.

A cleaner soln would be to not have ArtificialNode extend ElementNode so that it would not be confused as a LexicalNode. ArtificialNode is only used in the pasting logic and ideally should not need to be initialised in the Editor.

jaapvanblaaderen commented 1 day ago

Hi @potatowagon, when upgrading to Lexical to 0.15.0 I now get warnings in the console since ArtificialNode__DO_NOT_USE is not implementing methods required by ElementNode. I guess this is not be expected? Or am I maybe doing something wrong in the way I use Lexical?

ArtificialNode__DO_NOT_USE should implement "importJSON" method to ensure JSON and default HTML serialization works as expected
ArtificialNode__DO_NOT_USE should implement "exportJSON" method to ensure JSON and default HTML serialization works as expected
ArtificialNode__DO_NOT_USE must implement static "clone" method
potatowagon commented 1 day ago

@jaapvanblaaderen https://github.com/facebook/lexical/pull/6107 should fix the warnings

potatowagon commented 1 day ago

https://github.com/facebook/lexical/pull/6048 another fix