adrienpoly / stimulus-flatpickr

A modest, yet powerful wrapper of Flatpickr 📆 for Stimulus
MIT License
415 stars 30 forks source link

Can this be used with the upcoming rails default of import maps? #88

Closed salex closed 3 years ago

salex commented 3 years ago

This is not an issue, (at least at this point) - but more of a question.

I've spent quit a bit of time over the last few week looking at rails 7 alpha trying to gauge how hard it's going to be to move my 3 puny apps forward and what approach will cause the least amount of pain. I've tried both new rails 7 apps and trying to add the gems (cssbundling-rails, jsbundling-rails, import maps-rails) to a branch on an existing app.

Since the esbuild approach is more or less using node packages without webpacker, I have managed to get most stuff working in an existing app (or a new rails 6 demo/test app). My apps are mainly pure Rails with some stimulus.js.

I do use two stimulus wrapper apps. Stimulus-flatpickr and Stimulus-autocomplete. I haven't tried real hard, but I can't get either of them to work with the import maps option. There are configuration option that I have not tried (maybe a little over my head at this time) that may get it to work (preload??)

Since stimulus also exists outside of the rails world, maybe someone has the answer (will it work with import maps?). I don't think the flatpickr controller is registering/firing, but can't think of a way to verify that. Then there is the flatpickr.css dependency that has caused some problems if not set up right.

My importmap.rb file

# Pin npm packages by running ./bin/importmap

pin "application", preload: true
pin "@hotwired/stimulus", to: "https://ga.jspm.io/npm:@hotwired/stimulus@3.0.1/dist/stimulus.js"
pin "@hotwired/stimulus-loading", to: "stimulus-loading.js"
pin_all_from "app/javascript/controllers", under: "controllers"
pin "stimulus-flatpickr", to: "https://ga.jspm.io/npm:stimulus-flatpickr@1.4.0/dist/index.js"
pin "flatpickr", to: "https://ga.jspm.io/npm:flatpickr@4.6.9/dist/flatpickr.js"
# pin "stimulus", to: "https://ga.jspm.io/npm:stimulus@3.0.1/dist/stimulus.js"

Hopefully Rails will have some upgrade procedures to lessen the pain, but this is a big jump (back to before webpacker!)

If someone can point me so some example/document, I'd be grateful.

Edit

Tried a few more things with no results just a different error

Exception with thrown value: Error: Unable to resolve specifier 'stimulus' from https://ga.jspm.io/npm:stimulus-flatpickr@1.4.0/dist/index.js

Guss it want @hotwire/stimulus

salex commented 3 years ago

Well I was a little confused seeing the note about stimulus 3.0.1 supported.

I then saw the note in stimulus-use to use hotwire/stimulus-use to use @beta in yarn.

I then tried bin/importmap pin stimulus-flatpickr@beta and after adding a <link rel="stylesheet" href="https://ga.jspm.io/npm:flatpickr@4.6.9/dist/flatpickr.min.css"> tag I got it to work.

I'll close this but maybe you should make you install instructions a little more clear for different versions.