2024-05-21 13:22:14 +02:00
|
|
|
<script lang="ts">
|
2024-05-21 17:47:08 +02:00
|
|
|
import { Button } from '$lib/components/ui/button';
|
|
|
|
import * as ContextMenu from '$lib/components/ui/context-menu';
|
|
|
|
import Shortcut from '$lib/components/Shortcut.svelte';
|
|
|
|
import { dbUtils } from '$lib/db';
|
|
|
|
import { Copy, Trash2 } from 'lucide-svelte';
|
2024-05-22 16:05:31 +02:00
|
|
|
import { type ListItem } from './FileList';
|
2024-05-23 14:44:07 +02:00
|
|
|
import { selectItem, selection } from './Selection';
|
2024-05-21 17:47:08 +02:00
|
|
|
import { _ } from 'svelte-i18n';
|
2024-05-21 13:22:14 +02:00
|
|
|
import { getContext } from 'svelte';
|
2024-05-23 14:44:07 +02:00
|
|
|
import { get } from 'svelte/store';
|
2024-05-21 13:22:14 +02:00
|
|
|
|
2024-05-22 16:05:31 +02:00
|
|
|
export let item: ListItem;
|
2024-05-21 13:22:14 +02:00
|
|
|
export let label: string | undefined;
|
|
|
|
|
2024-05-21 17:47:08 +02:00
|
|
|
let orientation = getContext<'vertical' | 'horizontal'>('orientation');
|
2024-05-21 13:22:14 +02:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
|
|
|
<!-- svelte-ignore a11y-no-static-element-interactions -->
|
2024-05-23 14:44:07 +02:00
|
|
|
<ContextMenu.Root
|
|
|
|
onOpenChange={(open) => {
|
|
|
|
if (open && !get(selection).has(item)) {
|
|
|
|
selectItem(item);
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
>
|
2024-05-21 17:47:08 +02:00
|
|
|
<ContextMenu.Trigger class="grow truncate">
|
|
|
|
<Button
|
|
|
|
variant="ghost"
|
|
|
|
class="w-full p-0 px-1 border-none focus-visible:ring-0 focus-visible:ring-offset-0 {orientation ===
|
|
|
|
'vertical'
|
|
|
|
? 'h-fit'
|
|
|
|
: 'h-9 px-1.5 shadow-md'}"
|
|
|
|
>
|
|
|
|
<span
|
|
|
|
class="w-full text-left truncate py-1"
|
|
|
|
on:click={(e) => {
|
|
|
|
e.stopPropagation(); // Avoid toggling the collapsible element
|
|
|
|
}}
|
|
|
|
on:contextmenu={(e) => {
|
|
|
|
if (e.ctrlKey) {
|
|
|
|
// Add to selection instead of opening context menu
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
2024-05-22 16:05:31 +02:00
|
|
|
$selection.toggle(item);
|
2024-05-21 17:47:08 +02:00
|
|
|
}
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
{label}
|
|
|
|
</span>
|
|
|
|
</Button>
|
|
|
|
</ContextMenu.Trigger>
|
|
|
|
<ContextMenu.Content>
|
2024-05-23 14:44:07 +02:00
|
|
|
{#if item.level !== 'waypoints'}
|
|
|
|
<ContextMenu.Item on:click={dbUtils.duplicateSelection}>
|
|
|
|
<Copy size="16" class="mr-1" />
|
|
|
|
{$_('menu.duplicate')}
|
|
|
|
<Shortcut key="D" ctrl={true} /></ContextMenu.Item
|
|
|
|
>
|
|
|
|
<ContextMenu.Separator />
|
|
|
|
{/if}
|
2024-05-22 16:05:31 +02:00
|
|
|
<ContextMenu.Item on:click={dbUtils.deleteSelection}
|
2024-05-21 17:47:08 +02:00
|
|
|
><Trash2 size="16" class="mr-1" />
|
|
|
|
{$_('menu.delete')}
|
|
|
|
<Shortcut key="⌫" ctrl={true} /></ContextMenu.Item
|
|
|
|
>
|
|
|
|
</ContextMenu.Content>
|
|
|
|
</ContextMenu.Root>
|