clipboard-apis icon indicating copy to clipboard operation
clipboard-apis copied to clipboard

Consider using DataTransferItemList instead of DataTransfer

Open bfgeek opened this issue 6 years ago • 1 comments

This was pointed out by @domenic - It seems like you might be able to avoid all of the barnacles on the DataTransfer object, by just using a DataTransferItemList directly. E.g.

const list = new DataTransferItemList(); // would need to expose a constructor?
list.add('text/plain', '\o/');
await navigator.clipboard.write(list);

Currently all the examples in the explainer would be covered by above, rather than the more generic DataTransfer.

The would above the awarkward questions, what does dataTransfer.setDragImage() do? etc.

It may (not sure about this) also be an opportunity to add convenience constructor for DataTransferItemList, e.g.

new DataTransferItemList([{type: 'text/plain', content: 'foo'}])

... or something :)

bfgeek avatar Mar 15 '18 23:03 bfgeek

The spec now uses ClipboardItem instead of DataTransfer, so that the API is also more promise-friendly (and many other things)

dway123 avatar Jun 13 '19 23:06 dway123