mirror of
https://github.com/zadam/trilium.git
synced 2025-10-06 05:25:37 +08:00
feat(views/geomap): dragging notes that are children
This commit is contained in:
parent
6509acd6ee
commit
2a665dffbc
3 changed files with 46 additions and 0 deletions
|
@ -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>;
|
||||
|
|
38
apps/client/src/widgets/view_widgets/geo_view/dragging.ts
Normal file
38
apps/client/src/widgets/view_widgets/geo_view/dragging.ts
Normal 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);
|
||||
}
|
||||
});
|
||||
}
|
|
@ -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();
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue