Files
gpx.studio/website/src/lib/components/file-list/FileList.svelte

92 lines
3.5 KiB
Svelte
Raw Normal View History

2024-05-16 18:18:42 +02:00
<script lang="ts">
import { ScrollArea } from '$lib/components/ui/scroll-area/index';
import * as ContextMenu from '$lib/components/ui/context-menu';
import FileListNode from './FileListNode.svelte';
2025-10-26 12:12:23 +01:00
import { onMount, setContext } from 'svelte';
import { ListFileItem, ListLevel, ListRootItem } from './file-list';
2025-06-21 21:07:36 +02:00
import { ClipboardPaste, FileStack, Plus } from '@lucide/svelte';
import Shortcut from '$lib/components/Shortcut.svelte';
2025-06-21 21:07:36 +02:00
import { i18n } from '$lib/i18n.svelte';
2025-10-17 23:54:45 +02:00
import { fileStateCollection } from '$lib/logic/file-state';
import { createFile, pasteSelection } from '$lib/logic/file-actions';
2025-10-18 09:36:55 +02:00
import { selection, copied } from '$lib/logic/selection';
2025-10-26 12:12:23 +01:00
import { allowedPastes } from './sortable-file-list';
2024-05-21 13:22:14 +02:00
2025-06-21 21:07:36 +02:00
let {
orientation,
recursive = false,
class: className = '',
style = '',
}: {
orientation: 'vertical' | 'horizontal';
recursive?: boolean;
class?: string;
style?: string;
} = $props();
2024-05-21 13:22:14 +02:00
setContext('orientation', orientation);
setContext('recursive', recursive);
2024-05-24 20:23:49 +02:00
2025-10-26 12:12:23 +01:00
onMount(() => {
2025-11-09 19:00:33 +01:00
if (orientation === 'horizontal') {
2025-10-26 12:12:23 +01:00
selection.update(($selection) => {
$selection.forEach((item) => {
if (!(item instanceof ListFileItem)) {
$selection.toggle(item);
$selection.set(new ListFileItem(item.getFileId()), true);
}
});
return $selection;
});
}
});
2024-05-16 18:18:42 +02:00
</script>
<ScrollArea
class="shrink-0 {orientation === 'vertical' ? 'p-0 pr-3' : 'h-10 px-1'}"
{orientation}
2025-11-12 09:05:20 +01:00
scrollbarXClasses={orientation === 'vertical' ? '' : 'hidden'}
scrollbarYClasses={orientation === 'vertical' ? '' : ''}
>
<div
class="flex {orientation === 'vertical'
? 'flex-col py-1 pl-1 min-h-screen'
2025-06-21 21:07:36 +02:00
: 'flex-row'} {className ?? ''}"
{style}
>
2025-10-17 23:54:45 +02:00
<FileListNode node={$fileStateCollection} item={new ListRootItem()} />
{#if orientation === 'vertical'}
<ContextMenu.Root>
<ContextMenu.Trigger class="grow" />
<ContextMenu.Content>
2025-06-21 21:07:36 +02:00
<ContextMenu.Item onclick={createFile}>
2025-10-26 12:12:23 +01:00
<Plus size="16" />
2025-06-21 21:07:36 +02:00
{i18n._('menu.new_file')}
<Shortcut key="+" ctrl={true} />
</ContextMenu.Item>
<ContextMenu.Separator />
2025-10-17 23:54:45 +02:00
<ContextMenu.Item
onclick={() => selection.selectAll()}
disabled={$fileStateCollection.size === 0}
>
2025-10-26 12:12:23 +01:00
<FileStack size="16" />
2025-06-21 21:07:36 +02:00
{i18n._('menu.select_all')}
<Shortcut key="A" ctrl={true} />
</ContextMenu.Item>
<ContextMenu.Separator />
<ContextMenu.Item
2025-10-18 09:36:55 +02:00
disabled={$copied === undefined ||
$copied.length === 0 ||
!allowedPastes[$copied[0].level].includes(ListLevel.ROOT)}
2025-06-21 21:07:36 +02:00
onclick={pasteSelection}
>
2025-10-26 12:12:23 +01:00
<ClipboardPaste size="16" />
2025-06-21 21:07:36 +02:00
{i18n._('menu.paste')}
<Shortcut key="V" ctrl={true} />
</ContextMenu.Item>
</ContextMenu.Content>
</ContextMenu.Root>
{/if}
</div>
2024-05-16 18:18:42 +02:00
</ScrollArea>