Skip to content

Commit

Permalink
Merge pull request #7202 from Madhu94/clipboard-multiple-mimes
Browse files Browse the repository at this point in the history
Allow different mimetypes for the clipboard data
  • Loading branch information
blink1073 committed Sep 16, 2019
2 parents 1c5175f + a0f72a7 commit 6bc9df5
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 6bc9df5

Please sign in to comment.