javascriptruby-on-railsrubyruby-on-rails-7editorjs

How do you configure EditorJS in Rails 7 with importmap and Stimulus?


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:editor-js@0.1.1/src/js/editor.js"
pin "babel-runtime/core-js/weak-map", to: "https://ga.jspm.io/npm:babel-runtime@6.26.0/core-js/weak-map.js"
pin "babel-runtime/helpers/classCallCheck", to: "https://ga.jspm.io/npm:babel-runtime@6.26.0/helpers/classCallCheck.js"
pin "babel-runtime/helpers/createClass", to: "https://ga.jspm.io/npm:babel-runtime@6.26.0/helpers/createClass.js"
pin "browser-split", to: "https://ga.jspm.io/npm:browser-split@0.0.0/index.js"
pin "class-list", to: "https://ga.jspm.io/npm:class-list@0.1.1/index.js"
pin "core-js/library/fn/object/define-property", to: "https://ga.jspm.io/npm:core-js@2.6.12/library/fn/object/define-property.js"
pin "core-js/library/fn/weak-map", to: "https://ga.jspm.io/npm:core-js@2.6.12/library/fn/weak-map.js"
pin "editable", to: "https://ga.jspm.io/npm:editable@1.1.0/index.js"
pin "es6-event-emitter", to: "https://ga.jspm.io/npm:es6-event-emitter@1.10.2/dist/emitter.js"
pin "events", to: "https://ga.jspm.io/npm:@jspm/core@2.0.1/nodelibs/browser/events.js"
pin "html-element", to: "https://ga.jspm.io/npm:html-element@1.3.0/index.js"
pin "hyperscript", to: "https://ga.jspm.io/npm:hyperscript@1.4.7/index.js"
pin "indexof", to: "https://ga.jspm.io/npm:indexof@0.0.1/index.js"
pin "inherits", to: "https://ga.jspm.io/npm:inherits@2.0.4/inherits_browser.js"
pin "jquery", to: "https://ga.jspm.io/npm:jquery@3.7.0/dist/jquery.js"
pin "styles", to: "https://ga.jspm.io/npm:styles@0.2.1/Gruntfile.js"
pin "text-content", to: "https://ga.jspm.io/npm:text-content@0.0.2/index.js"
pin "toastr", to: "https://ga.jspm.io/npm:toastr@2.1.4/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?


Solution

  • I don't think editor-js is the package you're looking for. Insert Obi-wan gif here

    Try $ ./bin/importmap pin @editorjs/editorjs