2022-02-07 22:34:53 +08:00
|
|
|
<script lang="ts">
|
2023-06-08 09:35:31 +08:00
|
|
|
import { Block } from "@gradio/atoms";
|
2022-03-08 21:35:42 +08:00
|
|
|
import { Table } from "@gradio/table";
|
2022-04-26 22:48:39 +08:00
|
|
|
import StatusTracker from "../StatusTracker/StatusTracker.svelte";
|
2022-05-06 03:05:05 +08:00
|
|
|
import type { LoadingStatus } from "../StatusTracker/types";
|
2023-05-16 09:36:57 +08:00
|
|
|
import { createEventDispatcher, afterUpdate } from "svelte";
|
2022-04-14 04:53:35 +08:00
|
|
|
|
|
|
|
type Headers = Array<string>;
|
|
|
|
type Data = Array<Array<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 = [];
|
2022-05-12 12:40:41 +08:00
|
|
|
export let elem_id: string = "";
|
2023-03-16 05:01:53 +08:00
|
|
|
export let elem_classes: Array<string> = [];
|
2022-06-17 07:49:54 +08:00
|
|
|
export let visible: boolean = 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);
|
|
|
|
export let value_is_output: boolean = false;
|
2022-04-14 22:12:30 +08:00
|
|
|
export let mode: "static" | "dynamic";
|
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;
|
2022-07-04 17:27:48 +08:00
|
|
|
export let datatype: Datatype | Array<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;
|
2022-03-24 21:08:13 +08:00
|
|
|
|
2022-04-14 04:53:35 +08:00
|
|
|
const dispatch = createEventDispatcher();
|
|
|
|
|
2022-05-06 03:05:05 +08:00
|
|
|
export let loading_status: LoadingStatus;
|
2022-04-26 22:48:39 +08:00
|
|
|
|
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;
|
|
|
|
});
|
|
|
|
$: {
|
|
|
|
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-03-14 08:12:41 +08:00
|
|
|
on:select
|
2022-04-26 22:48:39 +08:00
|
|
|
editable={mode === "dynamic"}
|
2022-06-17 08:02:01 +08:00
|
|
|
{wrap}
|
2022-07-04 17:27:48 +08:00
|
|
|
{datatype}
|
2022-04-26 22:48:39 +08:00
|
|
|
/>
|
2023-06-08 09:35:31 +08:00
|
|
|
</Block>
|