browser icon indicating copy to clipboard operation
browser copied to clipboard

Clipboard API support

Open mweiss opened this issue 5 years ago • 0 comments

Some clipboard functions require synchronous access to methods, like on the copy event using clipboardData.setData or the paste event and clipboardData.getData. If I handle the copy event in Elm and use a port from Elm to JS, it won't be handled synchronously by js. If I handle the copy event in a custom element in js, I run into the same issue trying to get the data back to JS (e.g. there's no two way synchronization technique that I know of). I think one workaround to this would be to add clipboard API support to the Browser.Events module and/or add specialized onCopy and onPaste functions to Html.Events module.

Note that one workaround for getting clipboard data on the paste event was to use a custom element to listen to the event, then using a custom event with the types of data I wanted (e.g. clipboardData.getData('text/html')), dispatching that, and then handling the event in Elm. You can see it here: https://github.com/mweiss/elm-rte-toolkit/blob/1.0.1/js/elmEditor.js#L303

However, I do not know of a corresponding solution to clipboardData.setData.

mweiss avatar Apr 09 '20 19:04 mweiss