2023-08-04 06:01:18 +08:00
|
|
|
<script lang="ts">
|
2023-08-24 04:48:10 +08:00
|
|
|
import type { Gradio } from "@gradio/utils";
|
|
|
|
import { afterUpdate } from "svelte";
|
2023-08-04 06:01:18 +08:00
|
|
|
import { _ } from "svelte-i18n";
|
|
|
|
|
2023-08-16 02:21:41 +08:00
|
|
|
import type { LoadingStatus } from "@gradio/statustracker";
|
2023-08-04 06:01:18 +08:00
|
|
|
|
|
|
|
import Code, { Widget } from "../shared";
|
|
|
|
import { StatusTracker } from "@gradio/statustracker";
|
|
|
|
import { Block, BlockLabel, Empty } from "@gradio/atoms";
|
|
|
|
import { Code as CodeIcon } from "@gradio/icons";
|
|
|
|
|
|
|
|
export let value = "";
|
|
|
|
export let value_is_output = false;
|
|
|
|
export let language = "";
|
|
|
|
export let lines = 5;
|
|
|
|
export let target: HTMLElement;
|
|
|
|
export let elem_id = "";
|
|
|
|
export let elem_classes: string[] = [];
|
|
|
|
export let visible = true;
|
2023-08-18 19:36:52 +08:00
|
|
|
export let label = $_("code.code");
|
2023-08-04 06:01:18 +08:00
|
|
|
export let show_label = true;
|
|
|
|
export let loading_status: LoadingStatus;
|
2023-10-05 21:20:01 +08:00
|
|
|
export let scale: number | null = null;
|
2023-08-24 04:48:10 +08:00
|
|
|
export let gradio: Gradio<{
|
|
|
|
change: typeof value;
|
|
|
|
input: never;
|
|
|
|
}>;
|
2023-08-04 06:01:18 +08:00
|
|
|
|
|
|
|
let dark_mode = target.classList.contains("dark");
|
|
|
|
|
|
|
|
function handle_change(): void {
|
2023-08-24 04:48:10 +08:00
|
|
|
gradio.dispatch("change", value);
|
2023-08-04 06:01:18 +08:00
|
|
|
if (!value_is_output) {
|
2023-08-24 04:48:10 +08:00
|
|
|
gradio.dispatch("input");
|
2023-08-04 06:01:18 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
afterUpdate(() => {
|
|
|
|
value_is_output = false;
|
|
|
|
});
|
|
|
|
$: value, handle_change();
|
|
|
|
</script>
|
|
|
|
|
2023-10-05 21:20:01 +08:00
|
|
|
<Block
|
|
|
|
variant={"solid"}
|
|
|
|
padding={false}
|
|
|
|
{elem_id}
|
|
|
|
{elem_classes}
|
|
|
|
{visible}
|
|
|
|
{scale}
|
|
|
|
>
|
2023-08-04 06:01:18 +08:00
|
|
|
<StatusTracker {...loading_status} />
|
|
|
|
|
|
|
|
<BlockLabel Icon={CodeIcon} {show_label} {label} float={false} />
|
|
|
|
|
|
|
|
{#if !value}
|
|
|
|
<Empty unpadded_box={true} size="large">
|
|
|
|
<CodeIcon />
|
|
|
|
</Empty>
|
|
|
|
{:else}
|
|
|
|
<Widget {language} {value} />
|
|
|
|
|
|
|
|
<Code bind:value {language} {lines} {dark_mode} readonly />
|
|
|
|
{/if}
|
|
|
|
</Block>
|