2022-02-07 22:34:53 +08:00
|
|
|
<script lang="ts">
|
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";
|
2022-04-14 04:53:35 +08:00
|
|
|
import { createEventDispatcher, tick } from "svelte";
|
|
|
|
|
|
|
|
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"]
|
|
|
|
};
|
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>;
|
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
|
|
|
|
2022-07-22 02:12:46 +08:00
|
|
|
async function handle_change(detail: {
|
|
|
|
data: Array<Array<string | number>>;
|
|
|
|
headers: Array<string>;
|
|
|
|
}) {
|
2022-04-14 04:53:35 +08:00
|
|
|
value = detail;
|
|
|
|
await tick();
|
|
|
|
dispatch("change", detail);
|
|
|
|
}
|
2022-02-01 21:45:55 +08:00
|
|
|
</script>
|
|
|
|
|
2023-03-16 05:01:53 +08:00
|
|
|
<div id={elem_id} class={elem_classes.join(" ")} class:hide={!visible}>
|
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}
|
2022-07-22 02:12:46 +08:00
|
|
|
on:change={({ detail }) => handle_change(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
|
|
|
/>
|
|
|
|
</div>
|
2023-01-18 04:47:40 +08:00
|
|
|
|
|
|
|
<style>
|
|
|
|
div {
|
|
|
|
position: relative;
|
|
|
|
overflow: hidden;
|
|
|
|
}
|
|
|
|
|
|
|
|
.hide {
|
|
|
|
display: none;
|
|
|
|
}
|
|
|
|
</style>
|