-
-
Notifications
You must be signed in to change notification settings - Fork 227
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for JS modules (+module for URLs handling) #1463
Conversation
umap/templates/umap/map_init.html
Outdated
<script type="text/javascript"> | ||
let MAP = new L.U.Map("map", {{ map_settings|notag|safe }}) | ||
<script defer type="text/javascript"> | ||
window.addEventListener('load', (event) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Had to add this, otherwise the objects wouldn't be exported to window
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As far as I understand:
defer
will not work for local script (i.e. without asrc
attribute)- module type scripts are executed in defer mode, which means after the DOM is ready
I guess this explain why you needed the load
event here. Maybe we could use DomContentLoaded
instead ?
One other option to consider (but not for this PR I'd say), is to have a dedicated script (/map/xxxx/load.js
), which could then make it work in defer mode, and could be an elegant way for other people to include a uMap map in their HTML ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting, defer
is not useful here then. DomContentLoaded
seems the way (if it works), and will allow us to run the script without having to wait for other resources to be ready (images, etc).
146f040
to
e124b3f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to pretend I know 🤓
f65b49c
to
c782a69
Compare
Great work, thanks!
About loading Leaflet twice, I guess the only way to prevent this is to make a full switch, and loading only the esm version. So that would mean either:
Given the later is more gradual and we use a lot of plugins we do not control, I'd be in favor of the second option. Thoughts ? |
WIP of plugin status:
|
This are the
|
And here is the full list, including those expected/set by the plugins:
|
Properties set by pluginsLeaflet.MarkerCluster
Leaflet.Editable
Leaflet.FormBuilder
Leaflet.Hash
Leaflet.Heat
Leaflet.Measurable
leaflet.path.drag
Leaflet.Photon
Leaflet.Toolbar
uMap
Leaflet.i18n
Properties from Leaflet
So, with my understanding, I'm expecting that exposing the global (Weird, it seems that this is the second comment that is created when I click on preview then write again…) |
It is not that simple: a |
umap/static/umap/js/modules/urls.js
Outdated
@@ -0,0 +1,29 @@ | |||
import { Util } from './vendors.js' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not fan of this import, as we lose the origin of the Util
variable in the process.
I'd suggest, either:
- loading
Util
(and such) frompath/to/leaflet.esm.js
everywhere - exposing namespace in vendors, not variables; so one would type
import L from './vendors
and then useL.Util
, just like in classic mode
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, I like the second one better, and I agree 👍
c782a69
to
05bf798
Compare
Also expose some vendorized libs as modules in `modules/vendors.js`
05bf798
to
a516d59
Compare
a516d59
to
7c697f7
Compare
db29170
to
4b34a7d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did we check that it still works fine with embedded maps?
Set a umap-fragment web component for lists
It seems we need to better escape the settings (
|
To me we're ready to introduce these changes! |
🎉 💣 🚀 |
Maybe we need a release with just that change 😅 😇 |
This is a test for how we could use JS modules in uMap.
Because modules are not used everywhere, we need to bind the loaded modules to
window
fr now. Also, the mocha test runner needs to be run inside a server, to avoid CORS limitations for local file systems.I'm not really sure it's the direction we should take, but I hope it could bring good discussions :-)