mirror of
https://github.com/pheralb/svgl.git
synced 2025-12-29 08:01:36 +08:00
fix clipboard on safari
This commit is contained in:
@@ -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);
|
||||
}
|
||||
};
|
||||
@@ -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.' };
|
||||
}
|
||||
};
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user