File tree Expand file tree Collapse file tree 2 files changed +20
-15
lines changed
apps/repl/app/components/limber Expand file tree Collapse file tree 2 files changed +20
-15
lines changed Original file line number Diff line number Diff line change 11import Component from ' @glimmer/component' ;
22import { on } from ' @ember/modifier' ;
33
4- import { getSnippetElement , toClipboard , withExtraStyles } from ' ./copy-utils' ;
4+ import { copyToClipboard , getSnippetElement } from ' ./copy-utils' ;
55import Menu from ' ./menu' ;
66
77/**
@@ -17,7 +17,7 @@ export default class CopyMenu extends Component {
1717 copyAsImage = async (event : Event ) => {
1818 let code = getSnippetElement (event );
1919
20- await withExtraStyles (code , () => toClipboard ( code ) );
20+ await copyToClipboard (code );
2121 };
2222
2323 <template >
Original file line number Diff line number Diff line change 1+ import { assert } from '@ember/debug' ;
2+
13import { toBlob , toPng } from 'html-to-image' ;
24
35export function getSnippetElement ( event : Event ) {
@@ -39,22 +41,21 @@ export function getSnippetElement(event: Event) {
3941 throw new Error ( 'Could not find snippet element' ) ;
4042}
4143
42- export async function withExtraStyles ( target : HTMLElement , next : ( ) => Promise < void > ) {
43- let pre = target . querySelector ( 'pre' ) ;
44+ export async function copyToClipboard ( target : HTMLElement ) {
45+ /**
46+ * 1. clone
47+ * 2. remove extra styles
48+ * 3. image
49+ * 3. clipboard
50+ */
51+ let toCopy = ( target . querySelector ( 'pre' ) || target ) . cloneNode ( ) ;
4452
45- if ( ! pre ) {
46- return await next ( ) ;
47- }
53+ assert ( `Element to copy must be an HTMLElement` , toCopy instanceof HTMLElement ) ;
4854
49- pre . classList . add ( 'drop-shadow-lg' ) ;
50- pre . style . margin = '0' ;
55+ toCopy . classList . add ( 'drop-shadow-lg' ) ;
56+ toCopy . style . margin = '0' ;
5157
52- try {
53- await next ( ) ;
54- } finally {
55- pre . classList . remove ( 'drop-shadow-lg' ) ;
56- pre . setAttribute ( 'style' , '' ) ;
57- }
58+ await toClipboard ( toCopy ) ;
5859}
5960
6061export async function toClipboard ( target : HTMLElement ) {
@@ -67,6 +68,10 @@ export async function toClipboard(target: HTMLElement) {
6768 return false ;
6869 }
6970
71+ if ( node . classList . contains ( 'limber__menu__content' ) ) {
72+ return false ;
73+ }
74+
7075 return true ;
7176 } ;
7277
You can’t perform that action at this time.
0 commit comments