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-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 = [];
|
|
|
|
export let value: Data | { data: Data; headers: Headers } = [["", "", ""]];
|
2022-03-29 21:10:35 +08:00
|
|
|
export let default_value: Array<Array<string | number>> = [["", "", ""]];
|
2022-04-09 02:46:00 +08:00
|
|
|
|
|
|
|
export let style: string = "";
|
2022-03-08 21:35:42 +08:00
|
|
|
export let is_static: boolean;
|
2022-03-24 21:08:13 +08:00
|
|
|
|
2022-03-29 21:10:35 +08:00
|
|
|
if (default_value) value = default_value;
|
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();
|
|
|
|
|
|
|
|
async function handle_change({ detail }) {
|
|
|
|
value = detail;
|
|
|
|
await tick();
|
|
|
|
|
|
|
|
dispatch("change", detail);
|
|
|
|
}
|
2022-02-01 21:45:55 +08:00
|
|
|
</script>
|
|
|
|
|
2022-04-14 04:53:35 +08:00
|
|
|
<Table
|
|
|
|
values={value}
|
|
|
|
{headers}
|
|
|
|
{style}
|
|
|
|
on:change={handle_change}
|
|
|
|
editable={!is_static}
|
|
|
|
/>
|