2025-03-28 14:16:20 +01:00
|
|
|
<script lang="ts">
|
2025-10-14 00:03:48 +02:00
|
|
|
import { onMount } from "svelte"
|
2025-03-27 15:38:59 +01:00
|
|
|
import ListView from "./ListView.svelte"
|
|
|
|
|
import GalleryView from "./GalleryView.svelte"
|
|
|
|
|
import CompactView from "./CompactView.svelte"
|
|
|
|
|
import Modal from "util/Modal.svelte";
|
2026-04-01 19:38:15 +02:00
|
|
|
import { FSNavigator, path_link } from "filesystem/FSNavigator";
|
2026-07-30 17:18:46 +02:00
|
|
|
import { fs_encode_path, type FSNode } from "lib/FilesystemAPI.svelte";
|
2025-10-13 23:20:42 +02:00
|
|
|
import { FileAction, type FileActionHandler } from "./FileManagerLib";
|
2026-11-09 18:48:27 +01:00
|
|
|
import CreateDirectory from "./CreateDirectory.svelte";
|
2024-02-15 18:52:46 +01:00
|
|
|
|
2025-10-13 16:05:50 +02:00
|
|
|
let nav = $state(new FSNavigator(false))
|
|
|
|
|
let modal: Modal = $state()
|
|
|
|
|
let directory_view = $state("")
|
|
|
|
|
let large_icons = $state(false)
|
|
|
|
|
let show_hidden = $state(false)
|
2026-11-09 18:48:27 +01:00
|
|
|
let creating_dir = $state(false)
|
2025-10-13 16:05:50 +02:00
|
|
|
|
2025-10-14 00:03:48 +02:00
|
|
|
let {
|
|
|
|
|
callback,
|
2026-10-05 13:46:24 +02:00
|
|
|
select_multiple = false,
|
|
|
|
|
directories = false,
|
2025-10-14 00:03:48 +02:00
|
|
|
}: {
|
|
|
|
|
callback: (files: FSNode[]) => void
|
|
|
|
|
select_multiple?: boolean
|
2026-10-05 13:46:24 +02:00
|
|
|
// Picks the directory which is open, instead of files in it
|
|
|
|
|
directories?: boolean
|
2025-10-13 16:05:50 +02:00
|
|
|
} = $props();
|
2024-02-15 18:52:46 +01:00
|
|
|
|
2025-03-28 14:16:20 +01:00
|
|
|
export const open = (path: string) => {
|
2026-11-09 18:48:27 +01:00
|
|
|
creating_dir = false
|
2024-02-15 18:52:46 +01:00
|
|
|
modal.show()
|
2026-10-02 15:10:34 +02:00
|
|
|
nav.set_selecting(false)
|
2024-08-09 13:02:07 +02:00
|
|
|
nav.navigate(path, false)
|
2024-02-15 18:52:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Navigation functions
|
|
|
|
|
|
2025-10-13 23:20:42 +02:00
|
|
|
const file_event: FileActionHandler = (action: FileAction, index: number, orig: Event) => {
|
|
|
|
|
switch (action) {
|
2025-05-14 11:56:52 +02:00
|
|
|
case FileAction.Click:
|
2025-10-13 23:20:42 +02:00
|
|
|
orig.preventDefault()
|
2025-05-14 11:56:52 +02:00
|
|
|
if (nav.children[index].type === "dir") {
|
|
|
|
|
nav.navigate(nav.children[index].path, true)
|
2026-10-05 13:46:24 +02:00
|
|
|
} else if (!directories) {
|
2026-10-02 15:10:34 +02:00
|
|
|
select_node(index, orig)
|
2025-05-14 11:56:52 +02:00
|
|
|
}
|
|
|
|
|
break
|
|
|
|
|
case FileAction.Context:
|
|
|
|
|
// If this is a touch event we will select the item
|
2026-10-05 13:46:24 +02:00
|
|
|
if (!directories && navigator.maxTouchPoints && navigator.maxTouchPoints > 0) {
|
2025-10-13 23:20:42 +02:00
|
|
|
orig.preventDefault()
|
2026-10-02 15:10:34 +02:00
|
|
|
select_node(index, orig)
|
2025-05-14 11:56:52 +02:00
|
|
|
}
|
|
|
|
|
break
|
2024-02-15 18:52:46 +01:00
|
|
|
}
|
|
|
|
|
}
|
2025-01-28 12:16:37 +01:00
|
|
|
|
2024-02-15 18:52:46 +01:00
|
|
|
const toggle_view = () => {
|
|
|
|
|
if (directory_view === "list") {
|
|
|
|
|
directory_view = "gallery"
|
2025-01-28 12:16:37 +01:00
|
|
|
} else if (directory_view === "gallery") {
|
|
|
|
|
directory_view = "compact"
|
2024-02-15 18:52:46 +01:00
|
|
|
} else {
|
|
|
|
|
directory_view = "list"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
localStorage.setItem("directory_view", directory_view)
|
|
|
|
|
}
|
|
|
|
|
|
2026-10-02 15:10:34 +02:00
|
|
|
const select_node = (index: number, e: Event) => {
|
|
|
|
|
if (!select_multiple) {
|
|
|
|
|
nav.selection.clear()
|
2024-02-15 18:52:46 +01:00
|
|
|
}
|
2026-10-02 15:10:34 +02:00
|
|
|
nav.select(nav.children[index], select_multiple && (e as MouseEvent).shiftKey, show_hidden)
|
2024-02-15 18:52:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let done = () => {
|
2026-10-05 13:46:24 +02:00
|
|
|
if (directories) {
|
|
|
|
|
callback([nav.base])
|
|
|
|
|
} else if (nav.selection.size > 0) {
|
2026-10-02 15:10:34 +02:00
|
|
|
callback([...nav.selection.values()])
|
2024-02-15 18:52:46 +01:00
|
|
|
}
|
|
|
|
|
modal.hide()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onMount(() => {
|
|
|
|
|
if(typeof Storage !== "undefined") {
|
|
|
|
|
directory_view = localStorage.getItem("directory_view")
|
|
|
|
|
large_icons = localStorage.getItem("large_icons") === "true"
|
|
|
|
|
}
|
|
|
|
|
if (directory_view === "" || directory_view === null) {
|
|
|
|
|
directory_view = "list"
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<Modal bind:this={modal} width="900px">
|
2025-10-13 23:20:42 +02:00
|
|
|
{#snippet header()}
|
2025-10-13 16:05:50 +02:00
|
|
|
<div class="header" >
|
2026-11-09 20:42:08 +01:00
|
|
|
<button class="button round" onclick={modal.hide} title="Close">
|
2026-11-09 20:26:23 +01:00
|
|
|
<i class="icon i_close"></i>
|
2025-10-13 16:05:50 +02:00
|
|
|
</button>
|
|
|
|
|
<button onclick={() => nav.navigate_up()} disabled={$nav.path.length <= 1} title="Up">
|
2026-11-09 20:26:23 +01:00
|
|
|
<i class="icon i_north"></i>
|
2025-10-13 16:05:50 +02:00
|
|
|
</button>
|
|
|
|
|
<button onclick={() => nav.reload()} title="Refresh directory listing">
|
2026-11-09 20:26:23 +01:00
|
|
|
<i class="icon i_refresh"></i>
|
2025-10-13 16:05:50 +02:00
|
|
|
</button>
|
|
|
|
|
|
|
|
|
|
<div class="title">
|
2026-10-05 13:46:24 +02:00
|
|
|
{#if directories}
|
|
|
|
|
Open the directory to pick
|
|
|
|
|
{:else}
|
|
|
|
|
Selected {$nav.selection.size} files
|
|
|
|
|
{/if}
|
2025-10-13 16:05:50 +02:00
|
|
|
</div>
|
|
|
|
|
|
2026-11-09 18:48:27 +01:00
|
|
|
{#if $nav.permissions.write}
|
|
|
|
|
<button onclick={() => creating_dir = !creating_dir} class:button_highlight={creating_dir} title="Make folder">
|
2026-11-09 20:26:23 +01:00
|
|
|
<i class="icon i_create_new_folder"></i>
|
2026-11-09 18:48:27 +01:00
|
|
|
</button>
|
|
|
|
|
{/if}
|
2025-10-13 16:05:50 +02:00
|
|
|
<button onclick={() => {show_hidden = !show_hidden}} title="Toggle hidden files">
|
|
|
|
|
{#if show_hidden}
|
2026-11-09 20:26:23 +01:00
|
|
|
<i class="icon i_visibility_off"></i>
|
2025-10-13 16:05:50 +02:00
|
|
|
{:else}
|
2026-11-09 20:26:23 +01:00
|
|
|
<i class="icon i_visibility"></i>
|
2025-10-13 16:05:50 +02:00
|
|
|
{/if}
|
|
|
|
|
</button>
|
|
|
|
|
|
|
|
|
|
<button onclick={() => toggle_view()} title="Switch between gallery, list and compact view">
|
2026-11-09 20:26:23 +01:00
|
|
|
<i class="icon i_list" class:button_highlight={directory_view === "list"}></i>
|
|
|
|
|
<i class="icon i_collections" class:button_highlight={directory_view === "gallery"}></i>
|
|
|
|
|
<i class="icon i_view_compact" class:button_highlight={directory_view === "compact"}></i>
|
2025-10-13 16:05:50 +02:00
|
|
|
</button>
|
|
|
|
|
|
|
|
|
|
<button class="button button_highlight round" onclick={done}>
|
2026-11-09 20:26:23 +01:00
|
|
|
<i class="icon i_done"></i> Pick
|
2025-10-13 16:05:50 +02:00
|
|
|
</button>
|
2024-02-15 18:52:46 +01:00
|
|
|
</div>
|
2025-10-13 16:05:50 +02:00
|
|
|
{/snippet}
|
2024-02-16 14:50:34 +01:00
|
|
|
|
2026-04-01 19:38:15 +02:00
|
|
|
{#each $nav.path as node, i (node.path)}
|
|
|
|
|
<a
|
|
|
|
|
href={"/d"+fs_encode_path(node.path)}
|
|
|
|
|
class="breadcrumb button flat"
|
|
|
|
|
use:path_link={{nav: nav, node: node}}
|
|
|
|
|
>
|
|
|
|
|
{#if node.abuse_type !== undefined}
|
2026-11-09 20:26:23 +01:00
|
|
|
<i class="icon small i_block"></i>
|
2026-04-01 19:38:15 +02:00
|
|
|
{:else if node.is_shared()}
|
2026-11-09 20:26:23 +01:00
|
|
|
<i class="icon small i_share"></i>
|
2026-04-01 19:38:15 +02:00
|
|
|
{/if}
|
|
|
|
|
<div class="node_name" class:base={$nav.base_index === i}>
|
|
|
|
|
{node.name}
|
|
|
|
|
</div>
|
|
|
|
|
</a>
|
|
|
|
|
{#if $nav.base_index !== i}
|
2026-11-09 20:26:23 +01:00
|
|
|
<i class="icon i_chevron_right"></i>
|
2026-04-01 19:38:15 +02:00
|
|
|
{/if}
|
|
|
|
|
{/each}
|
|
|
|
|
|
2024-02-16 14:50:34 +01:00
|
|
|
|
2026-11-09 18:48:27 +01:00
|
|
|
{#if creating_dir}
|
|
|
|
|
<CreateDirectory nav={nav}/>
|
|
|
|
|
{/if}
|
|
|
|
|
|
2024-02-15 18:52:46 +01:00
|
|
|
{#if directory_view === "list"}
|
|
|
|
|
<ListView
|
2024-08-09 13:02:07 +02:00
|
|
|
nav={nav}
|
2025-10-13 23:20:42 +02:00
|
|
|
file_event={file_event}
|
2024-02-15 18:52:46 +01:00
|
|
|
show_hidden={show_hidden}
|
|
|
|
|
large_icons={large_icons}
|
2024-08-09 13:02:07 +02:00
|
|
|
hide_edit
|
|
|
|
|
hide_branding
|
2024-02-15 18:52:46 +01:00
|
|
|
/>
|
|
|
|
|
{:else if directory_view === "gallery"}
|
|
|
|
|
<GalleryView
|
2024-08-09 13:02:07 +02:00
|
|
|
nav={nav}
|
2025-10-13 23:20:42 +02:00
|
|
|
file_event={file_event}
|
2024-02-15 18:52:46 +01:00
|
|
|
show_hidden={show_hidden}
|
|
|
|
|
large_icons={large_icons}
|
|
|
|
|
/>
|
2025-01-28 12:16:37 +01:00
|
|
|
{:else if directory_view === "compact"}
|
|
|
|
|
<CompactView
|
|
|
|
|
nav={nav}
|
2025-10-13 23:20:42 +02:00
|
|
|
file_event={file_event}
|
2025-01-28 12:16:37 +01:00
|
|
|
show_hidden={show_hidden}
|
|
|
|
|
large_icons={large_icons}
|
2025-04-02 15:12:38 +02:00
|
|
|
hide_edit
|
2025-01-28 12:16:37 +01:00
|
|
|
/>
|
2024-02-15 18:52:46 +01:00
|
|
|
{/if}
|
|
|
|
|
</Modal>
|
|
|
|
|
|
|
|
|
|
<style>
|
|
|
|
|
.header {
|
|
|
|
|
flex-grow: 1;
|
|
|
|
|
flex-shrink: 1;
|
|
|
|
|
display: flex;
|
|
|
|
|
flex-direction: row;
|
|
|
|
|
align-items: center;
|
|
|
|
|
justify-content: center;
|
|
|
|
|
font-size: 1em;
|
|
|
|
|
white-space: nowrap;
|
|
|
|
|
text-overflow: ellipsis;
|
|
|
|
|
overflow: hidden;
|
|
|
|
|
}
|
|
|
|
|
.title {
|
|
|
|
|
flex-grow: 1;
|
|
|
|
|
flex-shrink: 1;
|
|
|
|
|
text-align: center;
|
|
|
|
|
font-size: 1.2em;
|
|
|
|
|
}
|
|
|
|
|
</style>
|