2023-03-11 01:52:17 +08:00
|
|
|
<script lang="ts">
|
2023-05-16 09:36:57 +08:00
|
|
|
import { createEventDispatcher, afterUpdate } from "svelte";
|
2023-03-11 01:52:17 +08:00
|
|
|
import { _ } from "svelte-i18n";
|
|
|
|
|
|
|
|
import type { LoadingStatus } from "../app/src/components/StatusTracker/types";
|
|
|
|
|
|
|
|
import Code from "./interactive/Code.svelte";
|
|
|
|
import StatusTracker from "../app/src/components/StatusTracker/StatusTracker.svelte";
|
|
|
|
import { Block, BlockLabel, Empty } from "@gradio/atoms";
|
|
|
|
import { Code as CodeIcon } from "@gradio/icons";
|
|
|
|
|
|
|
|
import Widget from "./interactive/Widgets.svelte";
|
|
|
|
|
|
|
|
const dispatch = createEventDispatcher<{
|
|
|
|
change: typeof value;
|
2023-05-16 09:36:57 +08:00
|
|
|
input: undefined;
|
2023-03-11 01:52:17 +08:00
|
|
|
}>();
|
|
|
|
|
|
|
|
export let value: string = "";
|
2023-05-16 09:36:57 +08:00
|
|
|
export let value_is_output: boolean = false;
|
2023-03-11 01:52:17 +08:00
|
|
|
export let language: string = "";
|
2023-04-06 22:52:57 +08:00
|
|
|
export let lines: number = 5;
|
2023-03-11 01:52:17 +08:00
|
|
|
export let target: HTMLElement;
|
|
|
|
export let elem_id: string = "";
|
2023-03-16 05:01:53 +08:00
|
|
|
export let elem_classes: Array<string> = [];
|
2023-03-11 01:52:17 +08:00
|
|
|
export let visible: boolean = true;
|
|
|
|
export let mode: "static" | "dynamic";
|
|
|
|
export let label: string = "Code";
|
2023-03-14 04:59:23 +08:00
|
|
|
export let show_label: boolean = true;
|
2023-03-11 01:52:17 +08:00
|
|
|
export let loading_status: LoadingStatus;
|
|
|
|
|
|
|
|
let dark_mode = target.classList.contains("dark");
|
|
|
|
|
2023-05-16 09:36:57 +08:00
|
|
|
function handle_change() {
|
|
|
|
dispatch("change", value);
|
|
|
|
if (!value_is_output) {
|
|
|
|
dispatch("input");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
afterUpdate(() => {
|
|
|
|
value_is_output = false;
|
|
|
|
});
|
|
|
|
$: value, handle_change();
|
2023-03-11 01:52:17 +08:00
|
|
|
</script>
|
|
|
|
|
|
|
|
{#if mode === "static"}
|
2023-03-16 05:01:53 +08:00
|
|
|
<Block variant={"solid"} padding={false} {elem_id} {elem_classes} {visible}>
|
2023-03-11 01:52:17 +08:00
|
|
|
<StatusTracker {...loading_status} />
|
|
|
|
|
2023-03-31 02:20:34 +08:00
|
|
|
<BlockLabel Icon={CodeIcon} {show_label} {label} float={false} />
|
2023-03-11 01:52:17 +08:00
|
|
|
|
|
|
|
{#if !value}
|
2023-06-08 20:24:13 +08:00
|
|
|
<Empty unpadded_box={true} size="large">
|
2023-03-11 01:52:17 +08:00
|
|
|
<CodeIcon />
|
|
|
|
</Empty>
|
|
|
|
{:else}
|
|
|
|
<Widget {language} {value} />
|
|
|
|
|
2023-04-06 22:52:57 +08:00
|
|
|
<Code bind:value {language} {lines} {dark_mode} readonly />
|
2023-03-11 01:52:17 +08:00
|
|
|
{/if}
|
|
|
|
</Block>
|
|
|
|
{:else}
|
2023-03-16 05:01:53 +08:00
|
|
|
<Block variant={"solid"} padding={false} {elem_id} {elem_classes} {visible}>
|
2023-03-11 01:52:17 +08:00
|
|
|
<StatusTracker {...loading_status} />
|
|
|
|
|
2023-03-31 02:20:34 +08:00
|
|
|
<BlockLabel Icon={CodeIcon} {show_label} {label} float={false} />
|
2023-03-11 01:52:17 +08:00
|
|
|
|
2023-04-06 22:52:57 +08:00
|
|
|
<Code bind:value {language} {lines} {dark_mode} />
|
2023-03-11 01:52:17 +08:00
|
|
|
</Block>
|
|
|
|
{/if}
|
|
|
|
|
|
|
|
<style>
|
|
|
|
</style>
|