I am considering fleshing out a proposal to expand the Html.Events.Options type to handle writing to the event object.
The context that triggered this proposal was my attempt to use the native HTML 5 Drag and Drop APIs in a simple project as an exercise in learning. The minimum implementation required I set data for the drag operation on the event.dataTransfer container due to a feature (bug?) in FireFox. ( See https://caniuse.com/#search=Drag )
I had looked through the available Elm packages that supported DnD to various degrees and concluded that they took one of two approaches:
- Ignore native DnD and simulate with Mouse events (which can only provide an incomplete solution)
- Leverage a soon-to-be-closed “back door” and use Html.Attributes.attribute to set custom event handlers to modify event.dataTransfer. ( See https://github.com/elm/virtual-dom/commit/56b5faa19fad198eb23e3c5f121c89b5dcbe7f3a )
In the short term, I went with #2. However, for a long-term, full-featured implementation of native DnD, neither of these will work. There is probably some way to leverage ports to make this happen, but that comes with its own disadvantages:
- Not supported on package.elm-lang.org
- Bypasses the Event architecture already established in Elm
- Higher complexity
I was thinking there might be a simple, generic, solution to this by opening up the Html.Events.Options type (which already allows us to modify the behavior of the event handler) to allow safely writing to the event object when the handler is executed. I haven’t done much research yet, but I’m guessing there are more native APIs that would benefit from this feature other than DnD.
Before I spent more time on this proposal, I wanted to throw this idea out to the community for your thoughts.