adf0d17497
publish / version_or_publish (push) Has been cancelled
storybook-build / changes (push) Has been cancelled
storybook-build / :storybook-build (push) Has been cancelled
Sync Gradio Skills to Hugging Face / sync-skills (push) Has been cancelled
functional / changes (push) Has been cancelled
functional / build-frontend (push) Has been cancelled
functional / functional-test-SSR=false (push) Has been cancelled
functional / functional-reload (push) Has been cancelled
js / changes (push) Has been cancelled
js / js-test (push) Has been cancelled
docs-build / changes (push) Has been cancelled
docs-build / docs-build (push) Has been cancelled
docs-build / website-build (push) Has been cancelled
functional / functional-test-SSR=true (push) Has been cancelled
hygiene / hygiene-test (push) Has been cancelled
python / changes (push) Has been cancelled
python / build (push) Has been cancelled
python / test-ubuntu-latest-flaky (push) Has been cancelled
python / test-ubuntu-latest-not-flaky (push) Has been cancelled
python / test-windows-latest-flaky (push) Has been cancelled
python / test-windows-latest-not-flaky (push) Has been cancelled
68 lines
1.3 KiB
Svelte
68 lines
1.3 KiB
Svelte
<script lang="ts">
|
|
import { onDestroy } from "svelte";
|
|
import { Download, Check } from "@gradio/icons";
|
|
import { DownloadLink } from "@gradio/atoms";
|
|
import { IconButton } from "@gradio/atoms";
|
|
|
|
interface Props {
|
|
value: string;
|
|
language: string;
|
|
}
|
|
|
|
let { value, language }: Props = $props();
|
|
|
|
let ext = $derived(get_ext_for_type(language));
|
|
|
|
function get_ext_for_type(type: string): string {
|
|
const exts: Record<string, string> = {
|
|
py: "py",
|
|
python: "py",
|
|
md: "md",
|
|
markdown: "md",
|
|
json: "json",
|
|
html: "html",
|
|
css: "css",
|
|
js: "js",
|
|
javascript: "js",
|
|
ts: "ts",
|
|
typescript: "ts",
|
|
yaml: "yaml",
|
|
yml: "yml",
|
|
dockerfile: "dockerfile",
|
|
sh: "sh",
|
|
shell: "sh",
|
|
r: "r",
|
|
c: "c",
|
|
cpp: "cpp",
|
|
latex: "tex"
|
|
};
|
|
|
|
return exts[type] || "txt";
|
|
}
|
|
|
|
let copied = $state(false);
|
|
let timer: NodeJS.Timeout;
|
|
|
|
function copy_feedback(): void {
|
|
copied = true;
|
|
if (timer) clearTimeout(timer);
|
|
timer = setTimeout(() => {
|
|
copied = false;
|
|
}, 2000);
|
|
}
|
|
|
|
let download_value = $derived(URL.createObjectURL(new Blob([value])));
|
|
|
|
onDestroy(() => {
|
|
if (timer) clearTimeout(timer);
|
|
});
|
|
</script>
|
|
|
|
<DownloadLink
|
|
download="file.{ext}"
|
|
href={download_value}
|
|
onclick={copy_feedback}
|
|
>
|
|
<IconButton Icon={copied ? Check : Download} label="Download" />
|
|
</DownloadLink>
|