duncanphillips

duncanphillips

Hi,

I’m looking at improving the text editing capabilities in our app and would like to introduce a rich text editor experience like tiptap, trix, slate.

There doesn’t seem to be a lot of content (blogs, forum posts, etc) out there from folks who have integrated. I’m keen to hear if anyone has experience adding any of these frameworks, and looking for some recommendations for which ones are simple to add, and work well within live view?

At the moment, I’m leaning towards Trix because I’ve found a couple examples of folks using it with live view [1][2]. TipTap seems to be gaining some popularity though.

thanks

[1] WYSIWIG HTML editors for Phoenix LiveView? - #10 by romenigld
[2] Trix Editor - ElixirCasts

Showing Posts 1 to 8

Eiji

Eiji

Well … if you are not interested in HTML editors then you could consider markdown ones. Even creating such should not be a problem. That’s just a couple of buttons that insert some text in the current selection.

https://caniuse.com/input-selection

The only problem with that is how LiveView treats textarea i.e. it’s always a source of truth and therefore assign does not affects it and you have to write some extra JavaScript code to workaround it which is a bit confusing:

I guess that every JavaScript editor is simple to add into LiveView as long as you understand how it works … In normal case you could simply put some JavaScript at the bottom of the body tag contents making it executable after other elements are rendered. Alternatively there are onload and other events you are interested in and you should find the information about all of it in the specific editor documentation.

The only difference here is that window load events != LiveView load. So what you should focus on are not editor-specific blog posts, but LiveView documentation like:

The only “easier” way are hex packages (if any) which does that for you, so you only have to import their JavaScript hooks and add them to your LiveView hooks.

Andre-Bryan

Andre-Bryan

recently implemented a Rich Text Editor with trix, then QuillJs and then TinyMCE all of which were easy to switch between to test the functionality and ease of use. Ended up settling on tinyMCE. It all depends on what functionality you are looking for though.

bottlenecked

bottlenecked

There’s also another step-by-step integration for Trix which I read the other day. An extra point in favor of Trix then How to handle file upload using Trix editor in a Phoenix application

katafrakt

katafrakt

I did it with Quill once or twice. I remember it was rather simple, but the integration also was not very deep. As for Trix, I always found it lacking in terms of customization options.

Joep

Joep

I use CkEditor 5, it has great documentation and lots of features if you want.
This is my js:

Hooks.LoadEditor = {
  mounted() {
    ClassicEditor
      .create(document.querySelector('#editor'), {
        toolbar: { items: ['heading', '|', 'bold', 'italic', 'link', 'bulletedList', 'numberedList', 'blockQuote', 'insertTable', 'undo', 'redo'] },  // 'imageUpload', 'mediaEmbed', 'insertTable', 'undo', 'redo')
        language: 'nl',
        table: { contentToolbar: ['tableColumn', 'tableRow', 'mergeTableCells'] },
        link: {
          defaultProtocol: 'http://',
          addTargetToExternalLinks: true,
          decorators: {
            addLiveviewAttrs: {
              mode: 'automatic',
              callback: url => url.startsWith('/'),
              attributes: {
                "data-phx-link": 'redirect',
                "data-phx-link-state": 'push'
              }
            }
          },
        }
      })
      .then(editor => {
        console.log(editor);
        editor.editing.view.change(writer => {
          writer.setAttribute('spellcheck', 'false', editor.editing.view.document.getRoot());
        });
        // Add a click event listener to the editor to prevent the click event from opening the links with addLiveviewAttrs decorator
        editor.editing.view.document.on('click', (evt, data) => {
          data.stopPropagation();
        });
        // We need to add the text back to the textarea so changes can be tracked by LiveView,
        // otherwise when we change anything in the rest of the form, the textarea will be reset.
        editor.model.document.on('change:data', () => {
          document.querySelector('#editor').value = editor.getData();
        },

        );
        // Deactivate the stickyPanel, we set it manually in the css
        editor.ui.view.stickyPanel.unbind('isActive');
        editor.ui.view.stickyPanel.isActive = false;
      })
      .catch(err => {
        console.error(err.stack);
      });
  },
   // This function runs when the element's parent LiveView has reconnected to the server
  reconnected() { },
  updated() {
    this.mounted();
  }
}; 

And this is the form field, calling the Hook:

<.field
   type="textarea"
   field={@form[:text]}
   label="Text field"
   id="editor"
   phx-hook="LoadEditor"
 />
SoKeY

SoKeY

I did it with TipTap and it works quite nice together with phoenix and ecto changesets. Here you can see it in action https://tiptap-phoenix.fly.dev/notebook

There you will also find the link to the GitHub Repo.

JacobAlexander

JacobAlexander

Mati365

Mati365

Hey, I built a CKEditor 5 integration for Phoenix. It handles sending data back and forth with the backend, works nicely with forms, and supports different modes + custom plugins. If anyone’s looking for something like that, here’s the repo: https://github.com/Mati365/ckeditor5-phoenix

— All posts loaded —

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
FlyingNoodle
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
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
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
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
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

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews