File size: 1,847 Bytes
8fdc036 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
<script lang="ts">
import FileTree from "./FileTree.svelte";
import type { FileNode } from "./types";
export let interactive: boolean;
export let file_count: "single" | "multiple" = "multiple";
export let value: string[][] = [];
export let ls_fn: (path: string[]) => Promise<FileNode[]>;
let selected_folders: string[][] = [];
const paths_equal = (path: string[], path_2: string[]): boolean => {
return path.join("/") === path_2.join("/");
};
const path_in_set = (path: string[], set: string[][]): boolean => {
return set.some((x) => paths_equal(x, path));
};
const path_inside = (path: string[], path_2: string[]): boolean => {
return path.join("/").startsWith(path_2.join("/"));
};
</script>
<div class="file-wrap">
<FileTree
path={[]}
selected_files={value}
{selected_folders}
{interactive}
{ls_fn}
{file_count}
valid_for_selection={false}
on:check={(e) => {
const { path, checked, type } = e.detail;
if (checked) {
if (file_count === "single") {
value = [path];
} else if (type === "folder") {
if (!path_in_set(path, selected_folders)) {
selected_folders = [...selected_folders, path];
}
} else {
if (!path_in_set(path, value)) {
value = [...value, path];
}
}
} else {
selected_folders = selected_folders.filter(
(folder) => !path_inside(path, folder)
); // deselect all parent folders
if (type === "folder") {
selected_folders = selected_folders.filter(
(folder) => !path_inside(folder, path)
); // deselect all children folders
value = value.filter((file) => !path_inside(file, path)); // deselect all children files
} else {
value = value.filter((x) => !paths_equal(x, path));
}
}
}}
/>
</div>
<style>
.file-wrap {
height: calc(100% - 25px);
overflow-y: scroll;
}
</style>
|