feat(views/geomap): dragging notes that are children

This commit is contained in:
Elian Doran 2025-07-07 17:55:16 +03:00
parent 6509acd6ee
commit 2a665dffbc
No known key found for this signature in database
3 changed files with 46 additions and 0 deletions

View file

@ -186,6 +186,12 @@ interface RefreshContext {
noteIdsToReload: Set<string>;
}
export interface DragData {
noteId: string;
branchId: string;
title: string;
}
export default class NoteTreeWidget extends NoteContextAwareWidget {
private $tree!: JQuery<HTMLElement>;
private $treeActions!: JQuery<HTMLElement>;

View file

@ -0,0 +1,38 @@
import type { Map } from "leaflet";
import type { DragData } from "../../note_tree.js";
import { moveMarker } from "./editing";
export default function setupDragging($container: JQuery<HTMLElement>, map: Map) {
$container.on("dragover", (e) => {
// Allow drag.
e.preventDefault();
});
$container.on("drop", (e) => {
if (!e.originalEvent) {
return;
}
const data = e.originalEvent.dataTransfer?.getData('text');
if (!data) {
return;
}
try {
const parsedData = JSON.parse(data) as DragData[];
if (!parsedData.length) {
return;
}
const { noteId } = parsedData[0];
var offset = $container.offset();
var x = e.originalEvent.clientX - (offset?.left ?? 0);
var y = e.originalEvent.clientY - (offset?.top ?? 0);
const latlng = map.containerPointToLatLng([ x, y ]);
moveMarker(noteId, latlng);
} catch (e) {
console.warn(e);
}
});
}

View file

@ -10,6 +10,7 @@ import { CommandListenerData, EventData } from "../../../components/app_context.
import { createNewNote, moveMarker } from "./editing.js";
import link from "../../../services/link.js";
import { openMapContextMenu } from "./context_menu.js";
import setupDragging from "./dragging.js";
const TPL = /*html*/`
<div class="geo-view">
@ -158,6 +159,7 @@ export default class GeoView extends ViewMode<MapData> {
map.on("zoomend", updateFn);
map.on("click", (e) => this.#onMapClicked(e))
map.on("contextmenu", (e) => openMapContextMenu(this.parentNote.noteId, e));
setupDragging(this.$container, map);
this.#reloadMarkers();