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";
|
2022-06-02 01:02:18 +08:00
|
|
|
import type { Styles } from "@gradio/utils";
|
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 = "";
|
2022-06-17 07:49:54 +08:00
|
|
|
export let visible: boolean = true;
|
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-06-02 01:02:18 +08:00
|
|
|
export let style: Styles = {};
|
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>
|
|
|
|
|
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-06-17 08:22:09 +08:00
|
|
|
class:!hidden={!visible}
|
2022-05-09 23:18:13 +08:00
|
|
|
>
|
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)}
|
2022-04-26 22:48:39 +08:00
|
|
|
editable={mode === "dynamic"}
|
2022-06-02 01:02:18 +08:00
|
|
|
{style}
|
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>
|