leandrocp

leandrocp

Hey everyone, live_monaco_editor is a new component to render the Monaco Editor in your app. Monaco is the editor that powers VSCode and is the editor we all use and love in Livebook.

It was created to be used on BeaconCMS Admin UI but it can be used in any app.

How it looks like

After installing the dep and adding its hook into live socket, you can have an editor as simple as:

<LiveMonacoEditor.code_editor value="# My Code Editor" />

And interact with it calling:

socket
|> LiveMonacoEditor.change_language("html")
|> LiveMonacoEditor.set_value("<h1>New File</h1>")

Check out all features. More to come.

How assets are loaded

It’s using monaco-loader to load assets dynamically at runtime keeping the bundle size really small. It may support importing local assets if that’s ever requested.

Is it ready for production?

It’s in the early stages but a new version to make it more stable will be released soon.

Roadmap

The top priority is delivering a great UX for editing Elixir and HEEx files with auto complete and features you’d expect from a code editor, similar to Livebook. Note that this project has no association with Livebook but that’s a source of inspiration thanks to Jonatan Kłosko.

Enjoy!

Showing Posts 1 to 9

Exadra37

Exadra37

Install cmark-gfm and execute the following to get a local server running:

Why requiring an external dependency to be installed in our operating system?

leandrocp

leandrocp OP

Hey @Exadra37 that’s for Beacon and not LiveMonacoEditor but it will be replaced soon. To give you some context, earmark was failing to parse a bunch of markdown files and it won’t be fixed, which is fine since parsing markdown is complex and not all libraries supports all edge cases, so I’ve been experimenting with alternatives and the end goal is to not require an external dependency.

Exadra37

Exadra37

I am using MD library:

https://github.com/am-kantox/md

The announcement:

What I am using it for:

leandrocp

leandrocp OP

MD library seems great for our use case and it’s on my radar since I saw your implementation parsing heex components. Cool idea and implementation btw. Here’s the issue on Beacon repo Editor: Extend markdown to support HEEx features · Issue #28 · BeaconCMS/beacon_live_admin · GitHub

How is your MD parser working? Have you found more issues or limitations?

Exadra37

Exadra37

For my use case its working fine, but as the library author says, my approach isn’t idiomatic for the library, because its not returning an AST representation of what is being parsed, instead I am returning HTML.. He says that he will think if he can address my use case in an idiomatic way for the library, thus maybe you also want to expose your use case to see what he as to say.

My project is pretty much parked since that post I made, but not because of the MD library, just because of lacking the time to work on it, thus I cannot tell if my approach will find issues/limitations as I try to do more with it.

leandrocp

leandrocp OP

my approach isn’t idiomatic for the library, because its not returning an AST representation of what is being parsed, instead I am returning HTML

It’s not much different than what I need so I may get into the same situation as you.

expose your use case to see what he as to say

I’m gonna reach out as soon as I get back to that :+1: We have 700+ pages written in Markdown for dockyard.com (blog posts) so that may be a good test for the library. Do you mind if I reach out to you as well when I get to implement that custom MD parser?

Exadra37

Exadra37

Feel free to reach out. I will try to help on what I can :slight_smile:

leandrocp

leandrocp OP

Hey :wave: quick update since the last post.

Improved look & feel by loading the JetBrains Mono font and OneDark theme by default. That’s how it looks like rendering Elixir code:

And HTML:

Enjoy! New features coming soon.

W3NDO

W3NDO

@leandrocp I am currently using this to build a collaborative text editor. I am running into an issue where when one user changes the text, I end up in a cascade of changes on all synced editors where the changes applied and un-applied.

I am using the #set_value/3 function to synchronise the changes as shown here

case socket.assigns.user_id == user_id do
      true ->
        {:noreply, socket}

      _ ->
        {:noreply,
         socket
         |> LiveMonacoEditor.set_value(new_code, to: "file_#{socket.assigns.collab_id}")}
    end

I tried to use user_id to prevent this cascade but it didn’t work.

this.handleEvent("sync_editor", (payload) => {
      if (this.editor.dataset.userId == payload.user_id) {
        if (this.editor.getValue() != payload.code) {
          this.editor.setValue(payload.code);
        }
      }
    });

This is my sync editor function in the JS hook.

I am reading that some solutions include using a CRDT to track the changes, but before I commit to doing that I wanted to know if there are any other options

— All posts loaded —

Where Next? Top

Trending in Announcing Top

woylie
Flop is an Elixir library that applies filtering, ordering and pagination parameters to your Ecto queries. offset-based pagination with...
New
MRdotB
I needed to reuse React components from my Chrome extension in my Phoenix/LiveView backend. I noticed that for Svelte/Vue, there are live...
New
woylie
I released Doggo, a collection of unstyled Phoenix components. https://github.com/woylie/doggo Features Unstyled Phoenix components....
New
JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
anuaralfetahe
Hello Published a new library - ProcessHub! ProcessHub is a library designed to manage process distribution within the Elixir cluster. ...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New
webofbits
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself. My main conc...
#ai
New
sergio
It’s not that it’s vocabulary is too advanced. It’s something worse. I get lost trying to follow even a paragraph written by Claude. It’...
New
AstonJ
This showed up on my feed.. anyone heard of it? Just hype? Ox Alpha is a reasoning model designed for coding, sustained ag...
New
bartblast
Hey folks, I just published a post about Hologram’s funding and where the project goes next - the short version: Curiosum as Main Spons...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews