I’m trying to set up EditorJS as my content editor in my Rails 7 application using importmaps but running in to a few errors.
To pin EditorJS I ran ./bin/importmap pin editor-js
in my terminal. This gave me the following in my importmap.rb
pin "editor-js", to: "https://ga.jspm.io/npm:[email protected]/src/js/editor.js"
pin "babel-runtime/core-js/weak-map", to: "https://ga.jspm.io/npm:[email protected]/core-js/weak-map.js"
pin "babel-runtime/helpers/classCallCheck", to: "https://ga.jspm.io/npm:[email protected]/helpers/classCallCheck.js"
pin "babel-runtime/helpers/createClass", to: "https://ga.jspm.io/npm:[email protected]/helpers/createClass.js"
pin "browser-split", to: "https://ga.jspm.io/npm:[email protected]/index.js"
pin "class-list", to: "https://ga.jspm.io/npm:[email protected]/index.js"
pin "core-js/library/fn/object/define-property", to: "https://ga.jspm.io/npm:[email protected]/library/fn/object/define-property.js"
pin "core-js/library/fn/weak-map", to: "https://ga.jspm.io/npm:[email protected]/library/fn/weak-map.js"
pin "editable", to: "https://ga.jspm.io/npm:[email protected]/index.js"
pin "es6-event-emitter", to: "https://ga.jspm.io/npm:[email protected]/dist/emitter.js"
pin "events", to: "https://ga.jspm.io/npm:@jspm/[email protected]/nodelibs/browser/events.js"
pin "html-element", to: "https://ga.jspm.io/npm:[email protected]/index.js"
pin "hyperscript", to: "https://ga.jspm.io/npm:[email protected]/index.js"
pin "indexof", to: "https://ga.jspm.io/npm:[email protected]/index.js"
pin "inherits", to: "https://ga.jspm.io/npm:[email protected]/inherits_browser.js"
pin "jquery", to: "https://ga.jspm.io/npm:[email protected]/dist/jquery.js"
pin "styles", to: "https://ga.jspm.io/npm:[email protected]/Gruntfile.js"
pin "text-content", to: "https://ga.jspm.io/npm:[email protected]/index.js"
pin "toastr", to: "https://ga.jspm.io/npm:[email protected]/toastr.js"
I then tried importing all these dependencies in my stiumulus controller along with editor-js
but I am still getting console errors. This also feels like I’m just implementing it wrong.
Does anyone have any experience of configuring EditorJS in Rails 7 with importmaps and Stimulus?
2
Answers
I don’t think
editor-js
is the package you’re looking for. Insert Obi-wan gif hereTry
$ ./bin/importmap pin @editorjs/editorjs
Configuring EditorJS in Rails 7 with importmaps and Stimulus should be a straightforward process. Here are the steps you can follow:
Install EditorJS via importmap: You’ve already pinned the EditorJS and its dependencies in your
importmap.rb
, which is a good start.Create a Stimulus controller: Create a Stimulus controller to handle the initialization and interaction with EditorJS.
Import EditorJS and its dependencies in the Stimulus controller: In your Stimulus controller file (e.g.,
editorjs_controller.js
), import EditorJS and its dependencies using ES6 module imports.Here’s an example of how your Stimulus controller may look like: