Skip to content

Commit

Permalink
Allow different mimetypes on the clipboard
Browse files Browse the repository at this point in the history
  • Loading branch information
Madhu94 committed Sep 12, 2019
1 parent 1f59d9c commit a0f72a7
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions packages/apputils/src/clipboard.ts
Expand Up @@ -3,6 +3,9 @@

import { MimeData } from '@phosphor/coreutils';

// 'string' is allowed so as to make it non-breaking for any 1.x releases
export type ClipboardData = string | MimeData;

/**
* The clipboard interface.
*/
Expand All @@ -27,11 +30,17 @@ export namespace Clipboard {
* #### Notes
* This can only be called in response to a user input event.
*/
export function copyToSystem(text: string): void {
export function copyToSystem(clipboardData: ClipboardData): void {
let node = document.body;
let handler = (event: ClipboardEvent) => {
let data = event.clipboardData || (window as any).clipboardData;
data.setData('text', text);
if (typeof clipboardData === 'string') {
data.setData('text', clipboardData);
} else {
(clipboardData as MimeData).types().map((mimeType: string) => {
data.setData(mimeType, clipboardData.getData(mimeType));
});
}
event.preventDefault();
node.removeEventListener('copy', handler);
};
Expand Down

0 comments on commit a0f72a7

Please sign in to comment.