In no time, we're here!
The editor is surely a part of the important piece of this project, the part that facilitates user's contribution; the dreamy 😊 interface where a user's can basically write/edit jargons and submit with the click of a button and boom that's a contribution to Open source that also gets a green square without interfacing with the GitHub UI or any code editor.
The Plan
Right from the initial commit, I had found and readied a library that I wanted to integrate for this Editor feature, this was a project that I found during my search for a visual editor tool that builds down to markdown — I needed this tool at a certain point to write some issue with some complex table structure on the Hearts repo.
It is MDXEditor
MDXEditor; quoting from the project website..
is an open-source React component that allows users to author markdown documents naturally. Just like in Google docs or Notion.
...and I'll add that it's a beautiful tool in itself, with their live demo being of great use to me.
So, MDXEditor had the finest selling point and trust me I was just sold 🤤.
Change of Plan
Unfortunately at the point of integration, I encountered an error; a commonJS related error in lexical — a text editor framework integrated in MDXEditor itself. I did some findings and documented source of error in the tweet below..
I tried a few workarounds to get it working; but in order for the workaround to work, the lexical's integration version in MDXEditor needs to be updated.
I also immediately sourced for alternatives, and I found some but I wasn't feeling them at all.
The Resolution
I ended resolving to make a custom minimal markdown editor
...and for a resolution to the error I encountered in my attempt to integrate MDXEditor, we still gotta do this for Open Source.
The Editor
I got working, with the goal of relying on little to no dependency to patch the feature; I ended up consuming just react-markdown as new dependency and I was able to conclude the very first iteration of the editor in a 6 stages step.
The Stages
- I added a new map type
$dictionaryEditorstate to thedictionarystore and a customuseDictionaryEditorhook which wraps around the store so I can use it in the next stage. - I added a boilerplate
word-editorisland with react integration. Integrated the island to withclient:loaddirective on a newly creatededitorpage/route. - I Implemented the
Editorcomponent within theword-editorisland withtextareaform element. I integrated theuseDictionaryEditorto set dictionary store value for editor. - I implemented the
Previewcomponent within theword-editorisland. Where I consumed areact-markdownas markdown converter to HTML for the preview purpose. - I created and integrated a
DummyPreviewNavbarcomponent into thePreviewcomponent to enable the preview tab of the editor look exactly like word looks like when seen in the word layout on the web app. - I implemented the editor
titlefield; added a non-functional "Publish" button.
The PR
feat: implement dictionary word editor
#6
This Pull Request implements the first iteration of the visual word editor for adding new or modifying existing words in the dictionary.
- Added a new page/route
/editor - Added a
word-editorisland with react integration and integrated this island on theeditorpage with aclient:loaddirective - Added a new map store
$wordEditortostores/dictionary - Implemented a custom hook
useWordEditorwhich serves as a wrapper to performgetandsetoperation on the$wordEditorstore - Implement 2 component to the
word-editorisland integrate within the main island default exported component-
Editor- the entry field component for editing word entry to the dictionary, it implements thetitlefield of input typetextand acontentfield oftextareawhich receives (Markdown) text content -
Preview- the preview UI that mimics the view of word as it's going to look on the dictionary live view;- this component also integrate another
DummyPreviewNavbarcomponent to enhance the live preview idea - it also implements the
Markdowncomponent fromreact-markdownnode module integration to parse of the Markdown content received from theEditor'scontenttohtml. - this component also uses the
proseutility class name from@tailwind/typographyplug-in to style the parsedhtmlcontent enhance the preview idea.
- this component also integrate another
-
- Implemented the
DummyPreviewNavbarcomponent in within theword-editorisland for integration in thePreviewcomponent - Implement a stateless/non-functional
Publishbutton oneditorpage - Extracted
navelement onlayout/baseto standaloneNavbarcomponent
📖
screencast-bpconcjcammlapcogcnnelfmaeghhagj-2024.03.28-16_14_26.webm
- Added new node module:
react-markdown
Top comments (0)