hicommonwealth / commonwealth

A platform for decentralized communities
https://commonwealth.im
GNU General Public License v3.0
67 stars 42 forks source link

Spike to investigate using lexical for our editor #7482

Closed burtonator closed 4 months ago

burtonator commented 5 months ago

I think we should investigate using Lexical directly and just bypass MDXEditor.

@ForestMars

Here are the main things I need to investigate in the next spike:

... 14h total but it will probably be less than that. I'm mostly worried about the markdown functionality and I want to really investigate this to make sure we're not missing something.

The other issue is that there's no real plugin support for codemirror or mermaid.js or any other GFM extensions so we either:

  1. Just accept that we NEVER implement anything like this.
  2. Investigate it now but I think it will add significantly more time to the spike
  3. Just risk it and move on. I should note that MDXEditor implements codemirror for source code highlighting so it's definitely possible.

There's also the issue with Github Flavored Markdown (GFM) and other extensions that we might need to support.

What I'm worried about with this issue is that unless we really support all these extensions in our editor that we might paint ourselves into a corner in the future because we standardize on Lexical. I think what MDXEditor does is implement some of this via micromark and mdast but I need to investigate.

image

burtonator commented 5 months ago

Quick status update. I have the first step done. I have a repo where I can work with lexical.

The next step is to figure out how to make it do BASIC markdown import and export. Lexical has support for this natively I think.

I think we could break this out into two spikes. This first is just lexical with BASIC markdown support. Then I can look at more advance exports later.

burtonator commented 5 months ago

Another thing I realized is that if we go down this path to support Lexical directly, I think we can implement @ mentions where we popup and autocomplete widget and / (slash commands) where we can supports commands ALA Notion or github.

I think this could give us like 90% of an advanced editor but internally I'd prefer it not just be one contenteditable.

I'm still working through this though and trying to understand Lexical's model.

burtonator commented 5 months ago

Other things we have to test for v1 (basic editor)

Issues:

Notes:

burtonator commented 5 months ago

We also need to discuss which features/plugins from Lexical and MDEditor we should adopt and we also need to make sure they are supported in markdown.

Lexical Playground

Link Popup

image

Code blocks

image

Draggable blocks ALA notion

CleanShot 2024-04-18 at 12 55 41@2x

Latex / Math support

CleanShot 2024-04-18 at 12 57 07@2x

OEmbed and Youtube Embed

We could consider adding support for oembed but this would be more work in the future.

https://oembed.com/

image

@ mentions

image

hashtags

image

hover toolbar on desktop

image
burtonator commented 5 months ago

UPDATE: This is how we would build our own editor. I have a potential solution for how to use MDXEditor directly. See below.

I'm pretty much completed the research on this spike. I still want to read a bit more about the internals of lexical to help make a better decision but here is where we stand so far.

I think there are two paths we can go moving forward.

Plan A: Fork MDXEditor and port it to our UI/UX framework.

Basically we would fork the MDXEditor and customize it internally to do what we want it to do but just deal with the idiosyncrasies of that framework. We'd have to port it from RadixUI to our own UI and then figure out what to do with their store.

I don't understand how their store works and they use a proprietary store called GuruX.

pros:

cons:

Plan B: Implement our own editor on top of Lexical

I would prefer this plan. I think the main challenges here involved:

pros:

cons:

burtonator commented 5 months ago

There are other issues here including:

burtonator commented 5 months ago

We can fit 9-10 buttons on mobile...

burtonator commented 5 months ago

I think we might be able to use MDXEditor for now if:

I think we only need to following buttons on mobile: