mirror of
https://github.com/pheralb/svgl.git
synced 2025-02-06 06:58:04 +08:00
Merge pull request #14 from d3vcloud/fix-clipboard-safari
⚒️ fix: clipboard doesn't work on safari
This commit is contained in:
commit
9b4a8936ad
@ -27,14 +27,33 @@ const downloadSvg = (url?: string) => {
|
|||||||
download(url || "");
|
download(url || "");
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
const MIMETYPE = 'text/plain';
|
||||||
|
|
||||||
|
// Return content of svg as blob =>
|
||||||
|
const getSvgContent = async (url: string | undefined, isSupported: boolean) => {
|
||||||
|
const response = await fetch(url || "");
|
||||||
|
const content = await response.text();
|
||||||
|
|
||||||
|
// It was necessary to use blob because in chrome there were issues with the copy to clipboard
|
||||||
|
const blob = new Blob([content], { type: MIMETYPE });
|
||||||
|
return isSupported ? blob : content;
|
||||||
|
}
|
||||||
|
|
||||||
// Copy to clipboard =>
|
// Copy to clipboard =>
|
||||||
const copyToClipboard = (url?: string) => {
|
const copyToClipboard = async (url?: string) => {
|
||||||
fetch(url || "").then((response) => {
|
const data = {
|
||||||
response.text().then((content) => {
|
[MIMETYPE]: getSvgContent(url, true)
|
||||||
navigator.clipboard.writeText(content);
|
};
|
||||||
toast("Copied to clipboard", ToastTheme);
|
try {
|
||||||
});
|
const clipboardItem = new ClipboardItem(data);
|
||||||
});
|
await navigator.clipboard.write([clipboardItem]);
|
||||||
|
} catch (error) {
|
||||||
|
// This section works as a fallback on Firefox
|
||||||
|
const content = await getSvgContent(url, false) as string;
|
||||||
|
await navigator.clipboard.writeText(content);
|
||||||
|
}
|
||||||
|
toast("Copied to clipboard", ToastTheme);
|
||||||
};
|
};
|
||||||
|
|
||||||
const SVGInfo = (props: SVGCardProps) => {
|
const SVGInfo = (props: SVGCardProps) => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user