mirror of
https://github.com/gpxstudio/gpx.studio.git
synced 2025-08-31 23:53:25 +00:00
drop file tabs to desktop
This commit is contained in:
@@ -61,7 +61,7 @@ export function parseGPX(gpxData: string): GPXFile {
|
|||||||
return new GPXFile(parsed);
|
return new GPXFile(parsed);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function buildGPX(file: GPXFile, exclude: string[]): string {
|
export function buildGPX(file: GPXFile, exclude: string[] = []): string {
|
||||||
const gpx = file.toGPXFileType(exclude);
|
const gpx = file.toGPXFileType(exclude);
|
||||||
|
|
||||||
const builder = new XMLBuilder({
|
const builder = new XMLBuilder({
|
||||||
|
@@ -5,10 +5,17 @@
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { GPXFile, Track, Waypoint, type AnyGPXTreeElement, type GPXTreeElement } from 'gpx';
|
import {
|
||||||
|
buildGPX,
|
||||||
|
GPXFile,
|
||||||
|
Track,
|
||||||
|
Waypoint,
|
||||||
|
type AnyGPXTreeElement,
|
||||||
|
type GPXTreeElement
|
||||||
|
} from 'gpx';
|
||||||
import { afterUpdate, getContext, onDestroy, onMount } from 'svelte';
|
import { afterUpdate, getContext, onDestroy, onMount } from 'svelte';
|
||||||
import Sortable from 'sortablejs/Sortable';
|
import Sortable from 'sortablejs/Sortable';
|
||||||
import { getFileIds, settings, type GPXFileWithStatistics } from '$lib/db';
|
import { getFile, getFileIds, settings, type GPXFileWithStatistics } from '$lib/db';
|
||||||
import { get, writable, type Readable, type Writable } from 'svelte/store';
|
import { get, writable, type Readable, type Writable } from 'svelte/store';
|
||||||
import FileListNodeStore from './FileListNodeStore.svelte';
|
import FileListNodeStore from './FileListNodeStore.svelte';
|
||||||
import FileListNode from './FileListNode.svelte';
|
import FileListNode from './FileListNode.svelte';
|
||||||
@@ -78,13 +85,8 @@
|
|||||||
|
|
||||||
if (
|
if (
|
||||||
e.originalEvent &&
|
e.originalEvent &&
|
||||||
!(
|
!(e.originalEvent.ctrlKey || e.originalEvent.metaKey || e.originalEvent.shiftKey) &&
|
||||||
e.originalEvent.ctrlKey ||
|
($selection.size > 1 || !$selection.has(item.extend(getRealId(changed[0]))))
|
||||||
e.originalEvent.metaKey ||
|
|
||||||
e.originalEvent.shiftKey
|
|
||||||
) &&
|
|
||||||
($selection.size > 1 ||
|
|
||||||
!$selection.has(item.extend(getRealId(changed[0]))))
|
|
||||||
) {
|
) {
|
||||||
// Fix bug that sometimes causes a single select to be treated as a multi-select
|
// Fix bug that sometimes causes a single select to be treated as a multi-select
|
||||||
$selection.clear();
|
$selection.clear();
|
||||||
@@ -197,9 +199,7 @@
|
|||||||
fromItems = [fromItem.extend('waypoints')];
|
fromItems = [fromItem.extend('waypoints')];
|
||||||
} else {
|
} else {
|
||||||
let oldIndices: number[] =
|
let oldIndices: number[] =
|
||||||
e.oldIndicies.length > 0
|
e.oldIndicies.length > 0 ? e.oldIndicies.map((i) => i.index) : [e.oldIndex];
|
||||||
? e.oldIndicies.map((i) => i.index)
|
|
||||||
: [e.oldIndex];
|
|
||||||
oldIndices = oldIndices.filter((i) => i >= 0);
|
oldIndices = oldIndices.filter((i) => i >= 0);
|
||||||
oldIndices.sort((a, b) => a - b);
|
oldIndices.sort((a, b) => a - b);
|
||||||
|
|
||||||
@@ -214,9 +214,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
let newIndices: number[] =
|
let newIndices: number[] =
|
||||||
e.newIndicies.length > 0
|
e.newIndicies.length > 0 ? e.newIndicies.map((i) => i.index) : [e.newIndex];
|
||||||
? e.newIndicies.map((i) => i.index)
|
|
||||||
: [e.newIndex];
|
|
||||||
newIndices = newIndices.filter((i) => i >= 0);
|
newIndices = newIndices.filter((i) => i >= 0);
|
||||||
newIndices.sort((a, b) => a - b);
|
newIndices.sort((a, b) => a - b);
|
||||||
|
|
||||||
@@ -233,6 +231,22 @@
|
|||||||
|
|
||||||
moveItems(fromItem, toItem, fromItems, toItems);
|
moveItems(fromItem, toItem, fromItems, toItems);
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
setData: function (dataTransfer: DataTransfer, dragEl: HTMLElement) {
|
||||||
|
if (sortableLevel === ListLevel.FILE) {
|
||||||
|
const fileId = dragEl.getAttribute('data-id');
|
||||||
|
const file = fileId ? getFile(fileId) : null;
|
||||||
|
|
||||||
|
if (file) {
|
||||||
|
const data = buildGPX(file);
|
||||||
|
dataTransfer.setData(
|
||||||
|
'DownloadURL',
|
||||||
|
`application/gpx+xml:${file.metadata.name}.gpx:data:text/octet-stream;charset=utf-8,${encodeURIComponent(data)}`
|
||||||
|
);
|
||||||
|
dataTransfer.dropEffect = 'copy';
|
||||||
|
dataTransfer.effectAllowed = 'copy';
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
Object.defineProperty(sortable, '_item', {
|
Object.defineProperty(sortable, '_item', {
|
||||||
|
Reference in New Issue
Block a user