Skip to content

Commit 8375038

Browse files
Gao-pwgaopw5
and
gaopw5
authored
feat(Copied): using replication in non-https environments (#56)
Co-authored-by: gaopw5 <[email protected]>
1 parent cd4d825 commit 8375038

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

core/src/comps/Copied.tsx

+22-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,28 @@ export const Copied = <T extends object, K extends TagType>(props: CopiedProps<T
4141
}
4242
onCopied && onCopied(copyText, value);
4343
setCopied(true);
44-
navigator.clipboard
44+
45+
const _clipboard = navigator.clipboard || {
46+
writeText(text: string) {
47+
return new Promise((reslove, reject) => {
48+
const textarea = document.createElement('textarea');
49+
textarea.style.position = 'absolute';
50+
textarea.style.opacity = '0';
51+
textarea.style.left = '-99999999px';
52+
textarea.value = text;
53+
document.body.appendChild(textarea);
54+
textarea.select();
55+
if (!document.execCommand('copy')) {
56+
reject();
57+
} else {
58+
reslove();
59+
}
60+
textarea.remove();
61+
});
62+
},
63+
};
64+
65+
_clipboard
4566
.writeText(copyText)
4667
.then(() => {
4768
const timer = setTimeout(() => {

0 commit comments

Comments
 (0)