I use the Synchronous Clipboard API to implement copy/paste in my Elm note-taking app. As the clipboardData only is available during the event, I rely on Native code to do side effects:
Html.div
[ Html.Events.onWithOptions "copy"
preventDefault
(Decode.at [ "clipboardData" ] Decode.value
|> Decode.map
(\clipboard ->
let
_ =
Clipboard.setData "text/plain" selectionToText model clipboard
_ =
Clipboard.setData "text/x-rexpad-content" selectionContent model clipboard
in
NoAction
)
)
, ...
]
[ ... ]
Where Clipboard.setData has the type setData : String -> (a -> String) -> a -> Decode.Value -> Decode.Value with this JavaScript implementation:
function setData(mimeType, transformer, model, clipboardData) {
var data = transformer(model);
if (data !== "") {
clipboardData.setData(mimeType, data);
}
return clipboardData;
}
How could I do this without Native code on 0.18? Will 0.19 bring something that makes it possible?