clipboard-apis
clipboard-apis copied to clipboard
Consider using DataTransferItemList instead of DataTransfer
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 :)
The spec now uses ClipboardItem
instead of DataTransfer
, so that the API is also more promise-friendly (and many other things)