2025-10-09 15:48:23 +02:00
|
|
|
<script lang="ts">
|
2026-10-02 15:10:34 +02:00
|
|
|
import { bookmarks_failed, bookmarks_save, bookmarks_store } from "lib/Bookmarks";
|
2026-07-30 17:18:46 +02:00
|
|
|
import { fs_encode_path, fs_thumbnail_url } from "lib/FilesystemAPI.svelte";
|
2026-10-02 15:10:34 +02:00
|
|
|
import { global_navigator, move_target } from "filesystem/FSNavigator";
|
2025-10-09 15:48:23 +02:00
|
|
|
import { highlight_current_page } from "lib/HighlightCurrentPage";
|
2026-02-12 19:42:23 +01:00
|
|
|
import MenuEntry from "./MenuEntry.svelte";
|
2026-02-19 18:15:06 +01:00
|
|
|
import { flip } from "svelte/animate";
|
2025-10-13 23:20:42 +02:00
|
|
|
|
|
|
|
|
let editing = $state(false)
|
|
|
|
|
|
2026-02-19 18:15:06 +01:00
|
|
|
const toggle_edit = async () => {
|
|
|
|
|
if (editing) {
|
|
|
|
|
try {
|
|
|
|
|
await bookmarks_save($bookmarks_store)
|
|
|
|
|
} catch (err) {
|
|
|
|
|
alert("Failed to save bookmarks:\n"+err)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-13 23:20:42 +02:00
|
|
|
editing = !editing
|
|
|
|
|
}
|
2026-02-19 18:15:06 +01:00
|
|
|
|
|
|
|
|
const delete_bookmark = (id: string) => {
|
|
|
|
|
console.debug("Deleting bookmark", id)
|
|
|
|
|
$bookmarks_store = $bookmarks_store.filter((bm) => bm.id !== id)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let hovering: number = $state(-1);
|
|
|
|
|
const enable_drag = (e: MouseEvent) => {
|
|
|
|
|
(e.target as HTMLElement).closest("div").setAttribute("draggable", "true");
|
|
|
|
|
}
|
|
|
|
|
const disable_drag = (e: MouseEvent) => {
|
|
|
|
|
(e.target as HTMLElement).closest("div").setAttribute("draggable", "false");
|
|
|
|
|
}
|
|
|
|
|
const drag = (e: DragEvent, index: number) => {
|
|
|
|
|
if (!editing) {
|
|
|
|
|
e.preventDefault()
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
e.dataTransfer.effectAllowed = 'move';
|
|
|
|
|
e.dataTransfer.dropEffect = 'move';
|
|
|
|
|
e.dataTransfer.setData('text/plain', index.toString());
|
|
|
|
|
}
|
|
|
|
|
const drop = (e: DragEvent, drop_idx: number) => {
|
|
|
|
|
hovering = -1
|
|
|
|
|
|
|
|
|
|
if (e.dataTransfer.files.length !== 0) {
|
|
|
|
|
// This is not a rearrangement, this is a file upload
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
e.dataTransfer.dropEffect = 'move';
|
|
|
|
|
let drag_idx = parseInt(e.dataTransfer.getData("text/plain"));
|
|
|
|
|
if ($bookmarks_store[drag_idx] === undefined) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
e.preventDefault()
|
|
|
|
|
|
|
|
|
|
// If the drag is up, we will place the item before the drop target. If the
|
|
|
|
|
// drag is down, we place it after the drop target
|
|
|
|
|
if (drag_idx < drop_idx) {
|
|
|
|
|
$bookmarks_store.splice(drop_idx + 1, 0, $bookmarks_store[drag_idx]);
|
|
|
|
|
$bookmarks_store.splice(drag_idx, 1);
|
|
|
|
|
} else if (drag_idx > drop_idx) {
|
|
|
|
|
$bookmarks_store.splice(drop_idx, 0, $bookmarks_store[drag_idx]);
|
|
|
|
|
$bookmarks_store.splice(drag_idx + 1, 1);
|
|
|
|
|
} else {
|
|
|
|
|
return; // Nothing changed
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$bookmarks_store = $bookmarks_store
|
|
|
|
|
}
|
2025-10-09 15:48:23 +02:00
|
|
|
</script>
|
|
|
|
|
|
2025-11-03 19:15:57 +01:00
|
|
|
{#if $bookmarks_store.length !== 0}
|
2026-04-08 19:54:09 +02:00
|
|
|
<MenuEntry id="bookmarks">
|
2026-02-12 19:42:23 +01:00
|
|
|
{#snippet title()}
|
|
|
|
|
<div class="title">Bookmarks</div>
|
2026-04-01 15:30:11 +02:00
|
|
|
<button onclick={toggle_edit} class:button_highlight={editing} class="button flat">
|
2026-02-19 18:15:06 +01:00
|
|
|
{#if editing}
|
2026-11-09 20:26:23 +01:00
|
|
|
<i class="icon i_save"></i>
|
2026-02-19 18:15:06 +01:00
|
|
|
{:else}
|
2026-11-09 20:26:23 +01:00
|
|
|
<i class="icon i_edit"></i>
|
2026-02-19 18:15:06 +01:00
|
|
|
{/if}
|
2026-02-12 19:42:23 +01:00
|
|
|
</button>
|
|
|
|
|
{/snippet}
|
2025-10-13 23:20:42 +02:00
|
|
|
|
2026-02-12 19:42:23 +01:00
|
|
|
{#snippet body()}
|
2026-02-19 18:15:06 +01:00
|
|
|
{#each $bookmarks_store as bookmark, index (bookmark.id)}
|
|
|
|
|
<div class="row"
|
|
|
|
|
role="button"
|
|
|
|
|
tabindex="0"
|
|
|
|
|
ondragstart={e => drag(e, index)}
|
|
|
|
|
ondrop={e => drop(e, index)}
|
|
|
|
|
ondragover={e => {e.preventDefault(); e.stopPropagation()}}
|
2026-10-02 15:10:34 +02:00
|
|
|
ondragenter={() => {if (editing) hovering = index}}
|
|
|
|
|
use:move_target={{nav: global_navigator, node: () => bookmark}}
|
2026-02-19 18:15:06 +01:00
|
|
|
ondragend={() => {hovering = -1}}
|
|
|
|
|
class:highlight={hovering === index}
|
|
|
|
|
animate:flip={{duration: 300}}
|
|
|
|
|
>
|
2026-02-12 19:42:23 +01:00
|
|
|
{#if editing}
|
2026-02-19 18:15:06 +01:00
|
|
|
<button
|
|
|
|
|
class="button flat"
|
|
|
|
|
style="cursor: grab;"
|
|
|
|
|
onmousedown={enable_drag}
|
|
|
|
|
onmouseup={disable_drag}
|
|
|
|
|
>
|
2026-11-09 20:26:23 +01:00
|
|
|
<i class="icon i_drag_indicator"></i>
|
2026-02-19 18:15:06 +01:00
|
|
|
</button>
|
|
|
|
|
<input type="text" bind:value={bookmark.label}/>
|
|
|
|
|
<button onclick={() => delete_bookmark(bookmark.id)}>
|
2026-11-09 20:26:23 +01:00
|
|
|
<i class="icon i_delete"></i>
|
2026-02-12 19:42:23 +01:00
|
|
|
</button>
|
2026-02-19 18:15:06 +01:00
|
|
|
{:else}
|
|
|
|
|
<a class="button" href="/d{fs_encode_path(bookmark.path)}" use:highlight_current_page>
|
2026-04-08 19:54:09 +02:00
|
|
|
<img src={fs_thumbnail_url(bookmark.path, 32, 32)} class="thumbnail" alt="Bookmark icon" />
|
|
|
|
|
<span>{bookmark.label}</span>
|
2026-02-19 18:15:06 +01:00
|
|
|
</a>
|
2026-02-12 19:42:23 +01:00
|
|
|
{/if}
|
|
|
|
|
</div>
|
|
|
|
|
{/each}
|
|
|
|
|
{/snippet}
|
|
|
|
|
</MenuEntry>
|
2026-10-02 15:10:34 +02:00
|
|
|
{:else if $bookmarks_failed}
|
|
|
|
|
<div>Could not load bookmarks</div>
|
2026-01-29 23:41:30 +01:00
|
|
|
{/if}
|
2025-10-09 15:48:23 +02:00
|
|
|
|
|
|
|
|
<style>
|
2025-10-13 23:20:42 +02:00
|
|
|
.title {
|
|
|
|
|
flex: 1 1 auto;
|
|
|
|
|
}
|
2025-10-09 15:48:23 +02:00
|
|
|
.row {
|
|
|
|
|
display: flex;
|
|
|
|
|
flex-direction: row;
|
2026-02-19 18:15:06 +01:00
|
|
|
align-items: center;
|
2025-10-09 15:48:23 +02:00
|
|
|
}
|
|
|
|
|
.row>a {
|
|
|
|
|
flex: 1 1 auto;
|
|
|
|
|
}
|
|
|
|
|
.row>button {
|
|
|
|
|
flex: 0 0 auto;
|
|
|
|
|
}
|
|
|
|
|
.button {
|
|
|
|
|
background: none;
|
|
|
|
|
box-shadow: none;
|
|
|
|
|
}
|
2026-02-19 18:15:06 +01:00
|
|
|
.highlight {
|
2026-10-01 02:06:00 +02:00
|
|
|
box-shadow: 0 0 0px 1px var(--accent_color);
|
2026-02-19 18:15:06 +01:00
|
|
|
text-decoration: none;
|
|
|
|
|
}
|
2026-04-08 19:54:09 +02:00
|
|
|
.thumbnail {
|
|
|
|
|
height: 1.5em;
|
|
|
|
|
width: 1.5em;
|
|
|
|
|
border-radius: 2px;
|
|
|
|
|
}
|
2025-10-09 15:48:23 +02:00
|
|
|
</style>
|