fix clipboard on safari

This commit is contained in:
Xavi Alfaro
2024-04-09 23:43:54 -05:00
parent e88e4e886d
commit 5009391f4a
5 changed files with 66 additions and 44 deletions
+15
View File
@@ -0,0 +1,15 @@
const MIMETYPE = 'text/plain';
export const clipboard = async (content: string) => {
try {
const clipboardItem = new ClipboardItem({
[MIMETYPE]: new Blob([content], { type: MIMETYPE })
});
setTimeout(async () => {
await navigator.clipboard.write([clipboardItem]);
}, 200);
} catch (error) {
await navigator.clipboard.writeText(content);
}
};
+23
View File
@@ -0,0 +1,23 @@
interface iComponentCode {
code: string;
name: string;
typescript: boolean;
}
export const getReactComponentCode = async (
params: iComponentCode
): Promise<{ data?: string; error?: string }> => {
try {
const getCode = await fetch('/api/svgs/svgr', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(params)
});
const data = await getCode.json();
return data;
} catch (error) {
return { error: 'An error has ocurred. Try again.' };
}
};
+5 -7
View File
@@ -1,7 +1,5 @@
export const MIMETYPE = 'text/plain';
export const getSvgContent = async (url: string | undefined, isSupported: boolean) => {
const response = await fetch(url || '');
const content = await response.text();
const blob = new Blob([content], { type: MIMETYPE });
return isSupported ? blob : content;
};
export const getSvgContent = async (url: string | undefined) => {
const response = await fetch(url || '');
const content = await response.text();
return content;
};