2022-02-07 22:34:53 +08:00
|
|
|
<script lang="ts">
|
2023-08-24 04:48:10 +08:00
|
|
|
import { afterUpdate } from "svelte";
|
|
|
|
import type { Gradio, SelectData } from "@gradio/utils";
|
2023-06-08 09:35:31 +08:00
|
|
|
import { Block } from "@gradio/atoms";
|
2023-08-04 06:01:18 +08:00
|
|
|
import Table from "../shared";
|
|
|
|
import { StatusTracker } from "@gradio/statustracker";
|
2023-08-16 02:21:41 +08:00
|
|
|
import type { LoadingStatus } from "@gradio/statustracker";
|
2022-04-14 04:53:35 +08:00
|
|
|
|
2023-08-04 06:01:18 +08:00
|
|
|
type Headers = string[];
|
|
|
|
type Data = (string | number)[][];
|
2022-07-04 17:27:48 +08:00
|
|
|
type Datatype = "str" | "markdown" | "html" | "number" | "bool" | "date";
|
2022-04-14 04:53:35 +08:00
|
|
|
|
|
|
|
export let headers: Headers = [];
|
2023-08-04 06:01:18 +08:00
|
|
|
export let elem_id = "";
|
|
|
|
export let elem_classes: string[] = [];
|
|
|
|
export let visible = true;
|
2022-08-02 06:57:31 +08:00
|
|
|
export let value: { data: Data; headers: Headers } = {
|
|
|
|
data: [["", "", ""]],
|
|
|
|
headers: ["1", "2", "3"]
|
|
|
|
};
|
2023-05-16 09:36:57 +08:00
|
|
|
let old_value: string = JSON.stringify(value);
|
2023-08-04 06:01:18 +08:00
|
|
|
export let value_is_output = false;
|
2022-05-09 12:55:02 +08:00
|
|
|
export let col_count: [number, "fixed" | "dynamic"];
|
|
|
|
export let row_count: [number, "fixed" | "dynamic"];
|
2022-05-19 06:14:12 +08:00
|
|
|
export let label: string | null = null;
|
2022-06-17 08:02:01 +08:00
|
|
|
export let wrap: boolean;
|
2023-08-04 06:01:18 +08:00
|
|
|
export let datatype: Datatype | Datatype[];
|
2023-06-22 03:34:12 +08:00
|
|
|
export let scale: number | null = null;
|
2023-06-08 09:35:31 +08:00
|
|
|
export let min_width: number | undefined = undefined;
|
2023-08-24 04:48:10 +08:00
|
|
|
export let gradio: Gradio<{
|
|
|
|
change: never;
|
|
|
|
select: SelectData;
|
|
|
|
input: never;
|
|
|
|
}>;
|
2023-08-21 21:54:20 +08:00
|
|
|
export let latex_delimiters: {
|
|
|
|
left: string;
|
|
|
|
right: string;
|
|
|
|
display: boolean;
|
|
|
|
}[];
|
2023-08-23 05:42:02 +08:00
|
|
|
export let height: number | undefined = undefined;
|
2022-03-24 21:08:13 +08:00
|
|
|
|
2022-05-06 03:05:05 +08:00
|
|
|
export let loading_status: LoadingStatus;
|
2022-04-26 22:48:39 +08:00
|
|
|
|
2023-08-04 06:01:18 +08:00
|
|
|
function handle_change(): void {
|
2023-08-24 04:48:10 +08:00
|
|
|
gradio.dispatch("change");
|
2023-05-16 09:36:57 +08:00
|
|
|
if (!value_is_output) {
|
2023-08-24 04:48:10 +08:00
|
|
|
gradio.dispatch("input");
|
2023-05-16 09:36:57 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
afterUpdate(() => {
|
|
|
|
value_is_output = false;
|
|
|
|
});
|
|
|
|
$: {
|
|
|
|
if (JSON.stringify(value) !== old_value) {
|
|
|
|
old_value = JSON.stringify(value);
|
|
|
|
handle_change();
|
|
|
|
}
|
2022-04-14 04:53:35 +08:00
|
|
|
}
|
2022-02-01 21:45:55 +08:00
|
|
|
</script>
|
|
|
|
|
2023-06-08 09:35:31 +08:00
|
|
|
<Block
|
|
|
|
{visible}
|
|
|
|
padding={false}
|
|
|
|
{elem_id}
|
|
|
|
{elem_classes}
|
|
|
|
container={false}
|
|
|
|
{scale}
|
|
|
|
{min_width}
|
|
|
|
allow_overflow={false}
|
|
|
|
>
|
2022-05-06 03:05:05 +08:00
|
|
|
<StatusTracker {...loading_status} />
|
2022-04-26 22:48:39 +08:00
|
|
|
<Table
|
2022-05-19 06:14:12 +08:00
|
|
|
{label}
|
2022-05-09 12:55:02 +08:00
|
|
|
{row_count}
|
|
|
|
{col_count}
|
2022-04-26 22:48:39 +08:00
|
|
|
values={value}
|
|
|
|
{headers}
|
2023-05-16 09:36:57 +08:00
|
|
|
on:change={({ detail }) => {
|
|
|
|
value = detail;
|
|
|
|
}}
|
2023-08-24 04:48:10 +08:00
|
|
|
on:select={(e) => gradio.dispatch("select", e.detail)}
|
2022-06-17 08:02:01 +08:00
|
|
|
{wrap}
|
2022-07-04 17:27:48 +08:00
|
|
|
{datatype}
|
2023-08-21 21:54:20 +08:00
|
|
|
{latex_delimiters}
|
2023-08-16 02:21:41 +08:00
|
|
|
editable={false}
|
2023-08-23 05:42:02 +08:00
|
|
|
{height}
|
2022-04-26 22:48:39 +08:00
|
|
|
/>
|
2023-06-08 09:35:31 +08:00
|
|
|
</Block>
|