leandrocp

leandrocp

LiveMonacoEditor - Monaco Editor component for Phoenix LiveView

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!

Most Liked

leandrocp

leandrocp

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.

Exadra37

Exadra37

I am using MD library:

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

The announcement:

What I am using it for:

leandrocp

leandrocp

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.

Last Post!

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

Where Next?

Popular in Announcing Top

bryanjos
Hi, I just published version 0.23.0 of Elixirscript. https://github.com/bryanjos/elixirscript/blob/master/CHANGELOG.md Most of the chan...
New
grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 54006 488
New
mspanc
I am pleased to announce an initial release of the Membrane Framework - an Elixir-based framework with special focus on processing multim...
New
kevinlang
Hey all, We have made an Ecto3 Adapter for SQLite3, ecto_sqlite3! We have successfully on-boarded the full suite of integration tests (...
New
kip
Image is an image processing library for Elixir. It is based upon the fabulous vix library that provides a libvips wrapper for Elixir. I...
622 19460 194
New
woylie
Flop is an Elixir library that applies filtering, ordering and pagination parameters to your Ecto queries. offset-based pagination with...
New
restlessronin
The repo is at GitHub - cyberchitta/openai_ex: Community maintained Elixir library for OpenAI API · GitHub. Docs are at OpenaiEx User Gu...
152 10719 134
New

Other popular topics Top

vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 54006 488
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
JakeBecker
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
1144 54921 245
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New

We're in Beta

About us Mission Statement