Design an Editor with a plain-rich text mode toggle #7734
Unanswered
pavel-karpovich
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi guys, appretiate your attention!
I would like to get an expert advise on how to better implement one not-so-ordinary editor feature.
I have a task to create an editor which will have a toggle control to switch between plain and rich text modes.
The simplest implementation would be to switch between
RichTextPlugin
andPlainTextPlugin
and by rich-to-plain mode transition to clear editor and insert the previous content stripped of all tags. This solution is no brainer, but it will have too many drawbacks and I want to acheive more.Look at what I want to achieve with plain-rich mode transition:
Let me explain it with an example:
Given editor is set to rich text mode and we entered such content:
So there is an image and bullet list.
Then I toggle rich text mode into plain text mode and my editor content changes to:
Basically all nodes HTML content turned into plain text. Alt text instead of pictue, dashes instead of bullets.
After that I want to edit plain text, say, like that:
I removed image alt text and modified list items.
And now I want to switch my editor back to rich text mode.
And I get the bullet list displayed as a bullet list again with modified text. And no image as I deleted corresponding alt text.
Let's assume that my last action in the plain mode editor was removal of "image.jpg" line. And now in the rich text mode I will press Undo action:
There it is - I restore deleted image while it was deleted in the plain text mode being displayed as alt text.
It is how I want it to work.
It seems not an ordinary behavior and I would like to get some advise on implementation from experienced lexical developers.
As I see it right now, I will have to replace ALL default lexical nodes with extended classes with custom
createDOM
implemenation which will look at some globalmode
parameter and return either rich text DOM element or plain text node.One thing which I'm not sure to understand is where to define global
mode
parameter so it will be accessible from every node and how to make the editor to react onmode
change and reset DOM for all displayed nodes.Any advice and suggestions will be appreciated!
Beta Was this translation helpful? Give feedback.
All reactions