Coder Social home page Coder Social logo

developius / lexical-actiontext Goto Github PK

View Code? Open in Web Editor NEW
4.0 1.0 0.0 51 KB

Demonstration of using the Lexical editor with Rails/ActionText

Home Page: https://lexical-actiontext-demo.onrender.com/

Ruby 64.21% JavaScript 2.66% CSS 3.76% TypeScript 11.37% HTML 17.68% Shell 0.32%
actiontext lexical rails

lexical-actiontext's Introduction

README

This is a bare Rails 7 app with esbuild.

It includes an example controller which can be used to replace Trix with Lexical for an ActionText rich text field.

The HTML generated by Lexical is stored in a hidden input field (same approach as Trix). We then persist this to the database and render it when we show the article. This part works without any changes.

View controller & form partial.

Live demo or see video.

Intentions

I wanted to package this Stimulus controller up into a more reusable format and share make it available on NPM. Something like this which could then be extended by a subclass like that. So, imagine for this that the LexicalBaseController is a package bundled up nicely. Our app would implement the subclass.

This would make it super easy to extend without the Stimulus package needing to include all of the plugins and setup, which might not be needed for all consumers.

Sadly I ran into some issues. My knowledge of the internals of JS, bundles and other such things is limited, but hopefully I can convey the primary issues properly:

  1. Lexical uses a Map for storing event listeners (click, cut, copy, etc). This is fine, but the keys of the map are objects. This means we can't register plugins from the subclass as our copy of registerRichText doesn't have access to the same objects that the bundled version in the LexicalBaseController has. This means the calls to map.get() won't find the correct event listeners. This could be patched by using the strings instead of the objects.
  2. There are a few globals baked into the Lexical package itself. This makes it impossible to interact with the Lexical methods from outside of the bundle it's included in. Our subclass is in a different bundle, so we can't. Particularly, editorState is a global and $getSelection() depends on it. This means that even after (1) is resolved, an exception is raised when triggering the command (click, cut, paste, etc) as the editorState global is defined in the other bundle.

For now, the included Stimulus controller can be copied into your own application.

See blog post for more info.

lexical-actiontext's People

Contributors

developius avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.