DEV Community

Discussion on: Making TinyMCE work with Rails, Turbolinks and Stimulus

Collapse
 
leastbad profile image
leastbad

Interesting!

Are all of the configurations that you've hard-coded actually necessary? It seems like most of them are likely TinyMCE defaults already, no?

Either way, perhaps it would make sense to expose the options via the Stimulus values API so that people could set their own options via data attributes?

One thing you most likely should consider adding if you're targeting Turbolinks is a check to make sure that Turbolinks is not in cache preview mode. Just add a getter, like so:

  get preview () {
    return (
      document.documentElement.hasAttribute('data-turbolinks-preview') ||
      document.documentElement.hasAttribute('data-turbo-preview')
    )
  }
Enter fullscreen mode Exit fullscreen mode

And then wrap your init and remove methods in a gate, eg:

disconnect () {
  if (!this.preview) tinymce.remove()
}
Enter fullscreen mode Exit fullscreen mode

Just a thought! If you do take these ideas forward, please do consider cutting an npm package and releasing it. I'd definitely list it on StimulusConnect.

Collapse
 
djchadderton profile image
djchadderton

Thanks for the suggestions, which I'll certainly try out.

The configuration is just a suggestion, showing the settings I've been using for a long time for all text boxes right across the site, so it's fine in my case to hardcode them, but exposing the settings would be a useful addition to make it more universally useful, I agree.

As far as I remember, all of the settings I've changed are different from the defaults, but I could be wrong.