2020-11-11 00:00:54 +01:00
|
|
|
<script>
|
2023-05-30 15:51:10 +02:00
|
|
|
import { onMount } from 'svelte';
|
2020-12-01 23:01:21 +01:00
|
|
|
import PixeldrainLogo from '../util/PixeldrainLogo.svelte';
|
2022-04-26 15:23:57 +02:00
|
|
|
import LoadingIndicator from '../util/LoadingIndicator.svelte';
|
2023-05-17 15:34:56 +02:00
|
|
|
import EditWindow from './EditWindow.svelte';
|
|
|
|
import Toolbar from './Toolbar.svelte';
|
|
|
|
import Breadcrumbs from './Breadcrumbs.svelte';
|
|
|
|
import DetailsWindow from './DetailsWindow.svelte';
|
|
|
|
import Navigator from './Navigator.svelte';
|
|
|
|
import FilePreview from './viewers/FilePreview.svelte';
|
2023-05-25 17:06:17 +02:00
|
|
|
import SearchView from './SearchView.svelte';
|
2023-05-27 15:50:44 +02:00
|
|
|
import UploadWidget from './upload_widget/UploadWidget.svelte';
|
2023-11-15 15:50:54 +01:00
|
|
|
import HomeButton from '../file_viewer/HomeButton.svelte';
|
2023-05-31 00:27:00 +02:00
|
|
|
import { fs_path_url } from './FilesystemUtil';
|
2020-11-11 00:00:54 +01:00
|
|
|
|
2023-05-19 17:17:05 +02:00
|
|
|
let loading = true
|
2023-05-29 18:01:23 +02:00
|
|
|
let upload_widget
|
2023-05-17 15:34:56 +02:00
|
|
|
let download_frame
|
2020-11-11 00:00:54 +01:00
|
|
|
let details_visible = false
|
2023-05-11 19:07:29 +02:00
|
|
|
let edit_window
|
2023-05-17 15:34:56 +02:00
|
|
|
let edit_visible = false
|
2023-05-25 17:06:17 +02:00
|
|
|
let view = "file"
|
2020-11-11 00:00:54 +01:00
|
|
|
|
2023-05-17 22:46:27 +02:00
|
|
|
let fs_navigator
|
2020-11-17 23:39:27 +01:00
|
|
|
let state = {
|
2023-04-11 23:44:50 +02:00
|
|
|
path: window.initial_node.path,
|
|
|
|
base_index: window.initial_node.base_index,
|
2021-12-09 22:33:02 +01:00
|
|
|
children: window.initial_node.children,
|
2023-05-17 15:34:56 +02:00
|
|
|
permissions: window.initial_node.permissions,
|
|
|
|
|
|
|
|
// Shortcuts
|
|
|
|
base: window.initial_node.path[window.initial_node.base_index],
|
2020-11-11 00:00:54 +01:00
|
|
|
|
2020-12-01 23:01:21 +01:00
|
|
|
shuffle: false,
|
2020-11-17 23:39:27 +01:00
|
|
|
}
|
|
|
|
|
2023-05-29 12:33:22 +02:00
|
|
|
onMount(() => {
|
|
|
|
fs_navigator.open_node(window.initial_node, false)
|
|
|
|
})
|
2020-11-11 00:00:54 +01:00
|
|
|
|
|
|
|
const keydown = e => {
|
2020-12-01 23:01:21 +01:00
|
|
|
if (e.ctrlKey || e.altKey || e.metaKey) {
|
|
|
|
return // prevent custom shortcuts from interfering with system shortcuts
|
|
|
|
}
|
2021-03-04 15:42:46 +01:00
|
|
|
if (document.activeElement.type && document.activeElement.type === "text") {
|
|
|
|
return // Prevent shortcuts from interfering with input fields
|
|
|
|
}
|
2020-12-01 23:01:21 +01:00
|
|
|
|
2020-11-11 00:00:54 +01:00
|
|
|
switch (e.key) {
|
2020-11-26 11:13:27 +01:00
|
|
|
case "i":
|
2023-05-17 15:34:56 +02:00
|
|
|
details_visible = !details_visible
|
|
|
|
break;
|
|
|
|
case "e":
|
|
|
|
if (edit_visible) {
|
|
|
|
edit_visible = false
|
|
|
|
} else {
|
2023-05-25 14:47:36 +02:00
|
|
|
edit_window.edit(state.base, true)
|
2023-05-17 15:34:56 +02:00
|
|
|
}
|
2020-12-01 23:01:21 +01:00
|
|
|
break;
|
2020-11-26 11:13:27 +01:00
|
|
|
case "s":
|
|
|
|
download()
|
2020-12-01 23:01:21 +01:00
|
|
|
break;
|
|
|
|
case "r":
|
|
|
|
state.shuffle = !state.shuffle
|
|
|
|
break;
|
2023-05-25 17:06:17 +02:00
|
|
|
case "/":
|
|
|
|
case "f":
|
2023-05-25 20:19:37 +02:00
|
|
|
search()
|
2023-05-25 17:06:17 +02:00
|
|
|
break
|
2023-05-17 15:34:56 +02:00
|
|
|
case "a":
|
|
|
|
case "ArrowLeft":
|
2023-05-17 22:46:27 +02:00
|
|
|
fs_navigator.open_sibling(-1)
|
2020-12-01 23:01:21 +01:00
|
|
|
break;
|
2023-05-17 15:34:56 +02:00
|
|
|
case "d":
|
|
|
|
case "ArrowRight":
|
2023-05-17 22:46:27 +02:00
|
|
|
fs_navigator.open_sibling(1)
|
2020-12-01 23:01:21 +01:00
|
|
|
break;
|
2020-11-11 00:00:54 +01:00
|
|
|
}
|
2023-05-25 17:06:17 +02:00
|
|
|
|
|
|
|
e.preventDefault()
|
2020-11-11 00:00:54 +01:00
|
|
|
};
|
|
|
|
|
2020-11-17 23:39:27 +01:00
|
|
|
const download = () => {
|
2023-05-30 15:51:10 +02:00
|
|
|
download_frame.src = fs_path_url(state.base.path) + "?attach"
|
2020-12-01 23:01:21 +01:00
|
|
|
}
|
2023-05-25 20:19:37 +02:00
|
|
|
|
|
|
|
const search = async () => {
|
|
|
|
if (view === "search") {
|
|
|
|
view = "file"
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if (state.base.type !== "dir") {
|
|
|
|
await fs_navigator.navigate(state.path[state.path.length-2].path)
|
|
|
|
}
|
|
|
|
|
|
|
|
view = "search"
|
|
|
|
}
|
2023-05-25 21:36:59 +02:00
|
|
|
|
|
|
|
const loading_evt = e => {
|
|
|
|
loading = e.detail
|
|
|
|
}
|
2020-11-11 00:00:54 +01:00
|
|
|
</script>
|
|
|
|
|
2020-12-01 23:01:21 +01:00
|
|
|
<svelte:window on:keydown={keydown} />
|
2020-11-11 00:00:54 +01:00
|
|
|
|
2023-05-19 17:17:05 +02:00
|
|
|
<Navigator
|
|
|
|
bind:this={fs_navigator}
|
|
|
|
bind:state
|
2023-05-25 21:36:59 +02:00
|
|
|
on:loading={loading_evt}
|
2023-05-19 17:17:05 +02:00
|
|
|
/>
|
2023-05-17 15:34:56 +02:00
|
|
|
|
2023-04-11 23:44:50 +02:00
|
|
|
<div class="file_viewer">
|
2023-05-17 15:34:56 +02:00
|
|
|
<div class="headerbar">
|
2023-11-15 15:50:54 +01:00
|
|
|
<div>
|
|
|
|
<HomeButton/>
|
2020-11-11 00:00:54 +01:00
|
|
|
</div>
|
2023-11-15 15:50:54 +01:00
|
|
|
|
|
|
|
<Breadcrumbs state={state} fs_navigator={fs_navigator}/>
|
2020-11-11 00:00:54 +01:00
|
|
|
</div>
|
|
|
|
|
2023-05-25 17:06:17 +02:00
|
|
|
<div class="viewer_area">
|
2023-11-15 15:50:54 +01:00
|
|
|
<Toolbar
|
|
|
|
fs_navigator={fs_navigator}
|
|
|
|
state={state}
|
|
|
|
bind:details_visible={details_visible}
|
|
|
|
edit_window={edit_window}
|
|
|
|
bind:edit_visible={edit_visible}
|
|
|
|
bind:view={view}
|
|
|
|
on:download={download}
|
|
|
|
on:search={search}
|
|
|
|
/>
|
|
|
|
|
|
|
|
<div class="file_preview checkers">
|
2023-05-25 17:06:17 +02:00
|
|
|
{#if view === "file"}
|
|
|
|
<FilePreview
|
|
|
|
fs_navigator={fs_navigator}
|
|
|
|
state={state}
|
|
|
|
edit_window={edit_window}
|
2023-05-25 21:36:59 +02:00
|
|
|
on:loading={loading_evt}
|
2023-05-25 17:06:17 +02:00
|
|
|
on:open_sibling={e => fs_navigator.open_sibling(e.detail)}
|
|
|
|
on:download={download}
|
2023-05-29 18:01:23 +02:00
|
|
|
on:upload_picker={() => upload_widget.pick_files()}
|
2023-05-25 17:06:17 +02:00
|
|
|
/>
|
|
|
|
{:else if view === "search"}
|
|
|
|
<SearchView
|
|
|
|
state={state}
|
|
|
|
fs_navigator={fs_navigator}
|
2023-05-25 21:36:59 +02:00
|
|
|
on:loading={loading_evt}
|
2023-05-29 12:33:22 +02:00
|
|
|
on:done={() => {view = "file"}}
|
2023-05-25 17:06:17 +02:00
|
|
|
/>
|
|
|
|
{/if}
|
|
|
|
</div>
|
2020-11-11 00:00:54 +01:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<!-- This frame will load the download URL when a download button is pressed -->
|
2023-05-17 15:34:56 +02:00
|
|
|
<iframe
|
|
|
|
bind:this={download_frame}
|
|
|
|
title="Frame for downloading files"
|
|
|
|
style="display: none; width: 1px; height: 1px;">
|
|
|
|
</iframe>
|
2023-05-27 15:50:44 +02:00
|
|
|
</div>
|
2023-05-17 15:34:56 +02:00
|
|
|
|
2023-05-27 15:50:44 +02:00
|
|
|
<DetailsWindow
|
|
|
|
state={state}
|
|
|
|
bind:visible={details_visible}
|
|
|
|
/>
|
2023-05-17 15:34:56 +02:00
|
|
|
|
2023-05-27 15:50:44 +02:00
|
|
|
<EditWindow
|
|
|
|
bind:this={edit_window}
|
|
|
|
bind:visible={edit_visible}
|
|
|
|
fs_navigator={fs_navigator}
|
|
|
|
on:loading={loading_evt}
|
|
|
|
/>
|
|
|
|
|
2023-05-29 18:01:23 +02:00
|
|
|
<UploadWidget
|
|
|
|
bind:this={upload_widget}
|
|
|
|
fs_state={state}
|
|
|
|
drop_upload
|
|
|
|
on:uploads_finished={() => fs_navigator.reload()}
|
|
|
|
/>
|
2023-05-27 15:50:44 +02:00
|
|
|
|
|
|
|
<LoadingIndicator loading={loading}/>
|
2020-11-11 00:00:54 +01:00
|
|
|
|
|
|
|
<style>
|
|
|
|
/* Viewer container */
|
|
|
|
.file_viewer {
|
|
|
|
position: absolute;
|
|
|
|
top: 0;
|
|
|
|
right: 0;
|
|
|
|
bottom: 0;
|
|
|
|
left: 0;
|
2023-11-15 15:50:54 +01:00
|
|
|
display: flex;
|
|
|
|
flex-direction: column;
|
2020-11-11 00:00:54 +01:00
|
|
|
overflow: hidden;
|
2022-03-29 21:41:46 +02:00
|
|
|
background: var(--body_background);
|
2020-11-11 00:00:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Headerbar (row 1) */
|
2023-05-17 15:34:56 +02:00
|
|
|
.headerbar {
|
2023-11-15 15:50:54 +01:00
|
|
|
flex: 0 0 0;
|
2020-11-11 00:00:54 +01:00
|
|
|
display: flex;
|
|
|
|
flex-direction: row;
|
|
|
|
text-align: left;
|
|
|
|
box-shadow: none;
|
2020-11-11 23:45:52 +01:00
|
|
|
padding: 4px;
|
2020-11-11 00:00:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Headerbar components */
|
2023-05-17 15:34:56 +02:00
|
|
|
.headerbar > * {
|
2020-11-11 00:00:54 +01:00
|
|
|
flex-grow: 0;
|
|
|
|
flex-shrink: 0;
|
|
|
|
display: inline;
|
2020-11-11 23:45:52 +01:00
|
|
|
align-self: center;
|
2020-11-11 00:00:54 +01:00
|
|
|
}
|
2023-11-15 15:50:54 +01:00
|
|
|
/* File preview area (row 2) */
|
|
|
|
.viewer_area {
|
|
|
|
flex: 1 1 0;
|
2020-11-11 00:00:54 +01:00
|
|
|
display: flex;
|
2020-11-11 23:45:52 +01:00
|
|
|
flex-direction: row;
|
2023-11-15 15:50:54 +01:00
|
|
|
overflow: hidden;
|
2020-11-11 00:00:54 +01:00
|
|
|
}
|
2023-11-15 16:40:55 +01:00
|
|
|
@media (max-width: 700px) {
|
2023-11-15 15:50:54 +01:00
|
|
|
.viewer_area {
|
|
|
|
flex-direction: column-reverse;
|
2020-11-11 00:00:54 +01:00
|
|
|
}
|
|
|
|
}
|
2023-05-25 17:06:17 +02:00
|
|
|
|
|
|
|
.file_preview {
|
2023-11-15 15:50:54 +01:00
|
|
|
flex: 1 1 0;
|
2023-05-25 17:06:17 +02:00
|
|
|
border-radius: 8px;
|
2023-11-15 15:50:54 +01:00
|
|
|
overflow: auto;
|
2023-05-25 17:06:17 +02:00
|
|
|
border: 2px solid var(--separator);
|
|
|
|
}
|
2020-11-11 00:00:54 +01:00
|
|
|
</style>
|