From 26ebc4689cb3250a9a926d777dbade50ef63365c Mon Sep 17 00:00:00 2001 From: hanzhenfeng Date: Wed, 26 Oct 2022 09:33:12 +0800 Subject: [PATCH] Copy png to clipboard: test for safari copy by button --- src/components/ContentWrap.jsx | 64 +++++----------------------------- 1 file changed, 9 insertions(+), 55 deletions(-) diff --git a/src/components/ContentWrap.jsx b/src/components/ContentWrap.jsx index fe36a5be..246140b2 100644 --- a/src/components/ContentWrap.jsx +++ b/src/components/ContentWrap.jsx @@ -469,38 +469,6 @@ export default class ContentWrap extends Component { trackEvent('ui', 'copyPng'); } - async copyPngClickHandlerBySafari1(e) { - console.log(e); - navigator.clipboard.write([ - new ClipboardItem({ - "image/png": new Promise(async resolve => { - const response = await fetch("https://upload.wikimedia.org/wikipedia/commons/4/47/PNG_transparency_demonstration_1.png"); - resolve(await response.blob()); - }) - }) - ]).then( - r => console.log("success", r), - reason => console.log("failed", reason) - ); - } - - async copyPngClickHandlerBySafari2(e) { - console.log(e); - const mountingPoint = this.frame.contentWindow.document.getElementById('diagram'); - // eslint-disable-next-line - const png = await mountingPoint.getElementsByClassName('frame')[0].parentElement.__vue__.toBlob(); - navigator.clipboard.write([ - new ClipboardItem({ - "image/png": new Promise(async resolve => { - resolve(png); - }) - }) - ]).then( - r => console.log("success", r), - reason => console.log("failed", reason) - ); - } - async copyPngClickHandlerBySafari3(e) { console.log(e); const mountingPoint = this.frame.contentWindow.document.getElementById('diagram'); @@ -516,23 +484,7 @@ export default class ContentWrap extends Component { r => console.log("success", r), reason => console.log("failed", reason) ); - } - - async copyPngClickHandlerBySafari4(e) { - console.log(e); - const mountingPoint = this.frame.contentWindow.document.getElementById('diagram'); - // eslint-disable-next-line - navigator.clipboard.write([ - new ClipboardItem({ - "image/png": new Promise(async resolve => { - const png = await mountingPoint.getElementsByClassName('frame')[0].parentElement.__vue__.toBlob(); - resolve(await png); - }) - }) - ]).then( - r => console.log("success", r), - reason => console.log("failed", reason) - ); + trackEvent('ui', 'copyPng'); } copyPngToClipboard(imageData) { @@ -1142,16 +1094,18 @@ export default class ContentWrap extends Component { + - test1 - test2 - test3 - test4 - just-a )}