gradio/js/fileexplorer/shared/DirectoryExplorer.svelte
aliabid94 e4a307ed6c
Add component <-> server direct communication support, as well as a "file explorer" component (#5672)
* changes

* changes

* add changeset

* add changeset

* Server fns ext (#5760)

* start changes

* changes

* changes

* fix arrows

* add changeset

* rename demo

* fix some ci

* add changeset

* add changeset

* fix

* remove configs

* fix

* fix

* add changeset

* fixes

* linting

* Update gradio/components/file_explorer.py

* notebook

* typing

* tweaks

* fixed class method problem

* fix test

* file explorer

* gr.load

* format

* tweaks

* fix

* fix

* fix

* fix

* final tweaks + changelog

* changelog

* changelog

* changelog

* lint

---------

Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
Co-authored-by: pngwn <hello@pngwn.io>
Co-authored-by: Abubakar Abid <abubakar@huggingface.co>
2023-10-05 14:20:01 +01:00

70 lines
1.5 KiB
Svelte

<script lang="ts">
import { createEventDispatcher } from "svelte";
import { dequal } from "dequal";
import FileTree from "./FileTree.svelte";
import { make_fs_store } from "./utils";
import { File } from "@gradio/icons";
import { Empty } from "@gradio/atoms";
export let mode: "static" | "interactive";
export let server: any;
export let file_count: "single" | "multiple" = "multiple";
export let value: string[][] = [];
const dispatch = createEventDispatcher<{
change: typeof value;
}>();
const tree = make_fs_store();
server.ls().then((v: any) => {
tree.create_fs_graph(v);
});
$: value.length && $tree && set_checked_from_paths();
function set_checked_from_paths(): void {
value = file_count === "single" ? [value[0] || []] : value;
value = tree.set_checked_from_paths(value);
if (!dequal(value, old_value)) {
old_value = value;
dispatch("change", value);
}
}
let old_value: typeof value = [];
function handle_select({
node_indices,
checked
}: {
node_indices: number[];
checked: boolean;
}): void {
value = tree.set_checked(node_indices, checked, value, file_count);
if (!dequal(value, old_value)) {
old_value = value;
dispatch("change", value);
}
}
</script>
{#if $tree && $tree.length}
<div class="file-wrap">
<FileTree
tree={$tree}
{mode}
on:check={({ detail }) => handle_select(detail)}
{file_count}
/>
</div>
{:else}
<Empty unpadded_box={true} size="large"><File /></Empty>
{/if}
<style>
.file-wrap {
height: 100%;
overflow: auto;
}
</style>