2023-03-11 01:52:17 +08:00
|
|
|
<script lang="ts">
|
|
|
|
import { createEventDispatcher } from "svelte";
|
|
|
|
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;
|
|
|
|
}>();
|
|
|
|
|
|
|
|
export let value: string = "";
|
|
|
|
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");
|
|
|
|
|
|
|
|
$: dispatch("change", value);
|
|
|
|
</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}
|
|
|
|
<Empty size="large" unpadded_box={true}>
|
|
|
|
<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>
|