mirror of
https://github.com/gpxstudio/gpx.studio.git
synced 2025-08-31 23:53:25 +00:00
minor dnd improvements
This commit is contained in:
@@ -259,21 +259,6 @@ export function moveItems(fromParent: ListItem, toParent: ListItem, fromItems: L
|
|||||||
sortItems(fromItems, true);
|
sortItems(fromItems, true);
|
||||||
sortItems(toItems, false);
|
sortItems(toItems, false);
|
||||||
|
|
||||||
let toFileObserver = get(fileObservers).get(toParent.getFileId());
|
|
||||||
let first = true;
|
|
||||||
toFileObserver?.subscribe(() => { // Update selection when the target file has been updated
|
|
||||||
if (first) first = false;
|
|
||||||
else {
|
|
||||||
selection.update(($selection) => {
|
|
||||||
$selection.clear();
|
|
||||||
toItems.forEach((item) => {
|
|
||||||
$selection.set(item, true);
|
|
||||||
});
|
|
||||||
return $selection;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
dbUtils.applyEachToFilesAndGlobal([fromParent.getFileId(), toParent.getFileId()], [
|
dbUtils.applyEachToFilesAndGlobal([fromParent.getFileId(), toParent.getFileId()], [
|
||||||
(file, context: (Track | TrackSegment | Waypoint[] | Waypoint)[]) => {
|
(file, context: (Track | TrackSegment | Waypoint[] | Waypoint)[]) => {
|
||||||
let newFile = file;
|
let newFile = file;
|
||||||
@@ -352,4 +337,12 @@ export function moveItems(fromParent: ListItem, toParent: ListItem, fromItems: L
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
selection.update(($selection) => {
|
||||||
|
$selection.clear();
|
||||||
|
toItems.forEach((item) => {
|
||||||
|
$selection.set(item, true);
|
||||||
|
});
|
||||||
|
return $selection;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
@@ -174,7 +174,10 @@
|
|||||||
|
|
||||||
if (toItem instanceof ListRootItem) {
|
if (toItem instanceof ListRootItem) {
|
||||||
let newFileIds = getFileIds(newIndices.length);
|
let newFileIds = getFileIds(newIndices.length);
|
||||||
toItems = newIndices.map((_i, index) => item.extend(newFileIds[index]));
|
toItems = newIndices.map((i, index) => {
|
||||||
|
$fileOrder.splice(i, 0, newFileIds[index]);
|
||||||
|
return item.extend(newFileIds[index]);
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
toItems = newIndices.map((i) => toItem.extend(i));
|
toItems = newIndices.map((i) => toItem.extend(i));
|
||||||
}
|
}
|
||||||
@@ -201,11 +204,15 @@
|
|||||||
|
|
||||||
afterUpdate(() => {
|
afterUpdate(() => {
|
||||||
elements = {};
|
elements = {};
|
||||||
container.childNodes.forEach((node) => {
|
container.childNodes.forEach((element) => {
|
||||||
if (node instanceof HTMLElement) {
|
if (element instanceof HTMLElement) {
|
||||||
let attr = node.getAttribute('data-id');
|
let attr = element.getAttribute('data-id');
|
||||||
if (attr) {
|
if (attr) {
|
||||||
elements[attr] = node;
|
if (node instanceof Map && !node.has(attr)) {
|
||||||
|
element.remove();
|
||||||
|
} else {
|
||||||
|
elements[attr] = element;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -241,7 +248,7 @@
|
|||||||
bind:this={container}
|
bind:this={container}
|
||||||
class="sortable {orientation} flex {orientation === 'vertical'
|
class="sortable {orientation} flex {orientation === 'vertical'
|
||||||
? 'flex-col'
|
? 'flex-col'
|
||||||
: 'flex-row gap-1'} {canDrop ? 'p-b-5' : ''}"
|
: 'flex-row gap-1'} {canDrop ? 'min-h-5' : ''}"
|
||||||
>
|
>
|
||||||
{#if node instanceof Map}
|
{#if node instanceof Map}
|
||||||
{#each node as [fileId, file] (fileId)}
|
{#each node as [fileId, file] (fileId)}
|
||||||
|
Reference in New Issue
Block a user