2024-05-16 18:18:42 +02:00
|
|
|
<script lang="ts">
|
2024-06-05 14:51:32 +02:00
|
|
|
import {
|
|
|
|
GPXFile,
|
|
|
|
Track,
|
|
|
|
TrackSegment,
|
|
|
|
Waypoint,
|
|
|
|
type AnyGPXTreeElement,
|
|
|
|
type GPXTreeElement
|
|
|
|
} from 'gpx';
|
2024-05-17 15:02:45 +02:00
|
|
|
import { CollapsibleTreeNode } from '$lib/components/collapsible-tree/index';
|
2024-05-24 13:16:41 +02:00
|
|
|
import { settings, type GPXFileWithStatistics } from '$lib/db';
|
|
|
|
import { get, type Readable } from 'svelte/store';
|
2024-05-17 15:02:45 +02:00
|
|
|
import FileListNodeContent from './FileListNodeContent.svelte';
|
2024-05-21 13:22:14 +02:00
|
|
|
import FileListNodeLabel from './FileListNodeLabel.svelte';
|
2024-06-05 21:54:29 +02:00
|
|
|
import { afterUpdate, getContext } from 'svelte';
|
2024-06-05 14:51:32 +02:00
|
|
|
import {
|
2024-07-02 20:04:17 +02:00
|
|
|
ListFileItem,
|
2024-06-05 14:51:32 +02:00
|
|
|
ListTrackSegmentItem,
|
|
|
|
ListWaypointItem,
|
2024-07-02 20:04:17 +02:00
|
|
|
ListWaypointsItem,
|
2024-06-05 14:51:32 +02:00
|
|
|
type ListItem,
|
|
|
|
type ListTrackItem
|
|
|
|
} from './FileList';
|
2024-05-24 13:16:41 +02:00
|
|
|
import { _ } from 'svelte-i18n';
|
|
|
|
import { selection } from './Selection';
|
2024-05-16 18:18:42 +02:00
|
|
|
|
2024-05-17 15:02:45 +02:00
|
|
|
export let node:
|
|
|
|
| Map<string, Readable<GPXFileWithStatistics | undefined>>
|
|
|
|
| GPXTreeElement<AnyGPXTreeElement>
|
2024-07-04 02:17:50 +02:00
|
|
|
| Waypoint[]
|
|
|
|
| Waypoint;
|
2024-05-22 16:05:31 +02:00
|
|
|
export let item: ListItem;
|
2024-05-17 15:02:45 +02:00
|
|
|
|
2024-05-21 17:47:08 +02:00
|
|
|
let recursive = getContext<boolean>('recursive');
|
2024-05-17 15:02:45 +02:00
|
|
|
|
2024-05-24 13:16:41 +02:00
|
|
|
let collapsible: CollapsibleTreeNode;
|
|
|
|
|
2024-05-23 11:21:57 +02:00
|
|
|
$: label =
|
2024-07-02 20:04:17 +02:00
|
|
|
node instanceof GPXFile && item instanceof ListFileItem
|
2024-05-21 17:47:08 +02:00
|
|
|
? node.metadata.name
|
|
|
|
: node instanceof Track
|
2024-05-24 13:16:41 +02:00
|
|
|
? node.name ?? `${$_('gpx.track')} ${(item as ListTrackItem).trackIndex + 1}`
|
2024-06-05 14:51:32 +02:00
|
|
|
: node instanceof TrackSegment
|
|
|
|
? `${$_('gpx.segment')} ${(item as ListTrackSegmentItem).segmentIndex + 1}`
|
|
|
|
: node instanceof Waypoint
|
|
|
|
? node.name ?? `${$_('gpx.waypoint')} ${(item as ListWaypointItem).waypointIndex + 1}`
|
2024-07-02 20:04:17 +02:00
|
|
|
: node instanceof GPXFile && item instanceof ListWaypointsItem
|
2024-06-05 14:51:32 +02:00
|
|
|
? $_('gpx.waypoints')
|
|
|
|
: '';
|
2024-05-24 13:16:41 +02:00
|
|
|
|
|
|
|
const { verticalFileView } = settings;
|
2024-06-05 21:54:29 +02:00
|
|
|
|
|
|
|
function openIfSelectedChild() {
|
2024-05-24 13:16:41 +02:00
|
|
|
if (collapsible && get(verticalFileView) && $selection.hasAnyChildren(item, false)) {
|
|
|
|
collapsible.openNode();
|
|
|
|
}
|
2024-06-05 21:54:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($selection) {
|
|
|
|
openIfSelectedChild();
|
|
|
|
}
|
2024-05-24 13:16:41 +02:00
|
|
|
|
2024-06-05 21:54:29 +02:00
|
|
|
afterUpdate(openIfSelectedChild);
|
2024-05-16 18:18:42 +02:00
|
|
|
</script>
|
|
|
|
|
2024-05-17 15:02:45 +02:00
|
|
|
{#if node instanceof Map}
|
2024-05-22 16:05:31 +02:00
|
|
|
<FileListNodeContent {node} {item} />
|
2024-06-05 14:51:32 +02:00
|
|
|
{:else if node instanceof TrackSegment}
|
2024-06-18 15:32:54 +02:00
|
|
|
<FileListNodeLabel {node} {item} {label} />
|
2024-06-05 14:51:32 +02:00
|
|
|
{:else if node instanceof Waypoint}
|
2024-06-18 15:32:54 +02:00
|
|
|
<FileListNodeLabel {node} {item} {label} />
|
2024-05-21 17:47:08 +02:00
|
|
|
{:else if recursive}
|
2024-05-24 13:16:41 +02:00
|
|
|
<CollapsibleTreeNode id={item.getId()} bind:this={collapsible}>
|
2024-06-18 15:32:54 +02:00
|
|
|
<FileListNodeLabel {node} {item} {label} slot="trigger" />
|
2024-05-17 15:02:45 +02:00
|
|
|
<div slot="content">
|
2024-06-05 17:19:03 +02:00
|
|
|
{#key node}
|
|
|
|
<FileListNodeContent {node} {item} />
|
|
|
|
{/key}
|
2024-05-16 18:18:42 +02:00
|
|
|
</div>
|
|
|
|
</CollapsibleTreeNode>
|
2024-05-21 17:47:08 +02:00
|
|
|
{:else}
|
2024-06-18 15:32:54 +02:00
|
|
|
<FileListNodeLabel {node} {item} {label} />
|
2024-05-16 18:18:42 +02:00
|
|
|
{/if}
|