diff --git a/Gemfile b/Gemfile index 96ea455070b..685ccd1ac1e 100644 --- a/Gemfile +++ b/Gemfile @@ -74,6 +74,7 @@ gem "observer", "~> 0.1.2" # launchdarkly-server-sdk-8.0.0 # Assets gem "sprockets-rails", "~> 3.4" gem "importmap-rails", "~> 2.0" +gem "stimulus-rails", "~> 1.3" # this adds stimulus-loading.js so it must be available at runtime group :assets, :development do gem "tailwindcss-rails", "~> 2.3" diff --git a/Gemfile.lock b/Gemfile.lock index 523ad2d3c2d..8e10ed58e03 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -674,6 +674,8 @@ GEM activesupport (>= 5.2) sprockets (>= 3.0.0) statsd-instrument (3.6.1) + stimulus-rails (1.3.3) + railties (>= 6.0.0) stringio (3.1.0) strong_migrations (1.7.0) activerecord (>= 5.2) @@ -842,6 +844,7 @@ DEPENDENCIES simplecov-cobertura (~> 2.1) sprockets-rails (~> 3.4) statsd-instrument (~> 3.5) + stimulus-rails (~> 1.3) strong_migrations (~> 1.7) tailwindcss-rails (~> 2.3) terser (~> 1.2) @@ -1107,6 +1110,7 @@ CHECKSUMS sprockets (4.2.1) sha256=951b13dd2f2fcae840a7184722689a803e0ff9d2702d902bd844b196da773f97 sprockets-rails (3.4.2) sha256=36d6327757ccf7460a00d1d52b2d5ef0019a4670503046a129fa1fb1300931ad statsd-instrument (3.6.1) sha256=fdaf73665c9a4d99aeddcda2e70fc266935919225dc0bf01257234f59f8f55df + stimulus-rails (1.3.3) sha256=4d1f9ab1d64e605f4c9cdd4cc530a9538b510606d32d02249d106256845c562c stringio (3.1.0) sha256=c1f6263ae03a15025e51194ab19b06b15e06adcaaedb7f5f6c06ab60f5d67718 strong_migrations (1.7.0) sha256=c60e164ef24a80db2b5c40353a8f9225a636e8ab52be42a47cd1923b88c9829c swd (2.0.3) sha256=4cdbe2a4246c19f093fce22e967ec3ebdd4657d37673672e621bf0c7eb770655 diff --git a/app/javascript/application.js b/app/javascript/application.js index e833efc22be..866fd76d68f 100644 --- a/app/javascript/application.js +++ b/app/javascript/application.js @@ -1,6 +1,7 @@ // Configure your import map in config/importmap.rb. Read more: https://github.com/rails/importmap-rails import Rails from "@rails/ujs"; Rails.start(); +import "controllers" import "src/api_key_form"; import "src/autocomplete"; diff --git a/app/javascript/controllers/application.js b/app/javascript/controllers/application.js new file mode 100644 index 00000000000..1213e85c7ac --- /dev/null +++ b/app/javascript/controllers/application.js @@ -0,0 +1,9 @@ +import { Application } from "@hotwired/stimulus" + +const application = Application.start() + +// Configure Stimulus development experience +application.debug = false +window.Stimulus = application + +export { application } diff --git a/app/javascript/controllers/index.js b/app/javascript/controllers/index.js new file mode 100644 index 00000000000..54ad4cad4d4 --- /dev/null +++ b/app/javascript/controllers/index.js @@ -0,0 +1,11 @@ +// Import and register all your controllers from the importmap under controllers/* + +import { application } from "controllers/application" + +// Eager load all controllers defined in the import map under controllers/**/*_controller +import { eagerLoadControllersFrom } from "@hotwired/stimulus-loading" +eagerLoadControllersFrom("controllers", application) + +// Lazy load controllers as they appear in the DOM (remember not to preload controllers in import map!) +// import { lazyLoadControllersFrom } from "@hotwired/stimulus-loading" +// lazyLoadControllersFrom("controllers", application) diff --git a/config/importmap.rb b/config/importmap.rb index a2509da60da..62b988f63a4 100644 --- a/config/importmap.rb +++ b/config/importmap.rb @@ -1,13 +1,18 @@ # Pin npm packages by running ./bin/importmap -pin "application", preload: true +pin "jquery" # @3.7.1 +pin "@rails/ujs", to: "@rails--ujs.js" # @7.1.3 +pin "application" pin_all_from "app/javascript/src", under: "src" +pin "clipboard" # @2.0.11 +# stimulus.min.js is a compiled asset from stimulus-rails gem +pin "@hotwired/stimulus", to: "stimulus.min.js" +# stimulus-loading.js is a compiled asset only available from stimulus-rails gem +pin "@hotwired/stimulus-loading", to: "stimulus-loading.js" +pin_all_from "app/javascript/controllers", under: "controllers" + # vendored and adapted from https://github.com/mdo/github-buttons/blob/master/src/js.js pin "github-buttons" -# vendored from github in the before times +# vendored from github in the before times, not compatible with newest version without changes pin "webauthn-json" - -pin "jquery" # @3.7.1 -pin "@rails/ujs", to: "@rails--ujs.js" # @7.1.3 -pin "clipboard" # @2.0.11