Skip to content

feat(Copied): using replication in non-https environments #56

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion core/src/comps/Copied.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,28 @@ export const Copied = <T extends object, K extends TagType>(props: CopiedProps<T
}
onCopied && onCopied(copyText, value);
setCopied(true);
navigator.clipboard

const _clipboard = navigator.clipboard || {
writeText(text: string) {
return new Promise((reslove, reject) => {
const textarea = document.createElement('textarea');
textarea.style.position = 'absolute';
textarea.style.opacity = '0';
textarea.style.left = '-99999999px';
textarea.value = text;
document.body.appendChild(textarea);
textarea.select();
if (!document.execCommand('copy')) {
reject();
} else {
reslove();
}
textarea.remove();
});
},
};

_clipboard
.writeText(copyText)
.then(() => {
const timer = setTimeout(() => {
Expand Down