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>>;
|
|
|
|
|
|
|
|
export let headers: Headers = [];
|
2022-05-12 12:40:41 +08:00
|
|
|
export let elem_id: string = "";
|
2022-04-14 04:53:35 +08:00
|
|
|
export let value: Data | { data: Data; headers: Headers } = [["", "", ""]];
|
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-09 23:18:13 +08:00
|
|
|
export let parent: string | null = null;
|
2022-03-24 21:08:13 +08:00
|
|
|
|
2022-04-14 04:53:35 +08:00
|
|
|
$: {
|
|
|
|
if (!Array.isArray(value)) {
|
|
|
|
if (Array.isArray(value.headers)) headers = value.headers;
|
|
|
|
value =
|
|
|
|
value.data.length === 0 ? [Array(headers.length).fill("")] : value.data;
|
|
|
|
} else {
|
|
|
|
value = value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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-04-14 04:53:35 +08:00
|
|
|
async function handle_change({ detail }) {
|
|
|
|
value = detail;
|
|
|
|
await tick();
|
|
|
|
dispatch("change", detail);
|
|
|
|
}
|
2022-02-01 21:45:55 +08:00
|
|
|
</script>
|
|
|
|
|
2022-05-09 23:18:13 +08:00
|
|
|
<div
|
2022-05-12 12:40:41 +08:00
|
|
|
id={elem_id}
|
2022-05-09 23:18:13 +08:00
|
|
|
class="relative overflow-hidden"
|
|
|
|
class:flex-1={parent === "row" || !parent}
|
|
|
|
>
|
2022-05-06 03:05:05 +08:00
|
|
|
<StatusTracker {...loading_status} />
|
2022-04-26 22:48:39 +08:00
|
|
|
<Table
|
2022-05-09 12:55:02 +08:00
|
|
|
{row_count}
|
|
|
|
{col_count}
|
2022-04-26 22:48:39 +08:00
|
|
|
values={value}
|
|
|
|
{headers}
|
|
|
|
on:change={handle_change}
|
|
|
|
editable={mode === "dynamic"}
|
|
|
|
/>
|
|
|
|
</div>
|