mirror of
https://github.com/zadam/trilium.git
synced 2025-11-02 11:26:15 +01:00
refactor(views/geomap): integrate drag into editing
This commit is contained in:
@@ -1,48 +0,0 @@
|
|||||||
import type { Map } from "leaflet";
|
|
||||||
import type { DragData } from "../../note_tree.js";
|
|
||||||
import { moveMarker } from "./editing";
|
|
||||||
import froca from "../../../services/froca.js";
|
|
||||||
import branches from "../../../services/branches.js";
|
|
||||||
|
|
||||||
export default function setupDragging($container: JQuery<HTMLElement>, map: Map, mapNoteId: string) {
|
|
||||||
$container.on("dragover", (e) => {
|
|
||||||
// Allow drag.
|
|
||||||
e.preventDefault();
|
|
||||||
});
|
|
||||||
$container.on("drop", async (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 ]);
|
|
||||||
|
|
||||||
const note = await froca.getNote(noteId, true);
|
|
||||||
const parents = note?.getParentNoteIds();
|
|
||||||
if (parents?.includes(mapNoteId)) {
|
|
||||||
await moveMarker(noteId, latlng);
|
|
||||||
} else {
|
|
||||||
await branches.cloneNoteToParentNote(noteId, mapNoteId);
|
|
||||||
await moveMarker(noteId, latlng);
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
console.warn(e);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
@@ -4,6 +4,10 @@ import { LOCATION_ATTRIBUTE } from "./index.js";
|
|||||||
import dialog from "../../../services/dialog";
|
import dialog from "../../../services/dialog";
|
||||||
import server from "../../../services/server";
|
import server from "../../../services/server";
|
||||||
import { t } from "../../../services/i18n";
|
import { t } from "../../../services/i18n";
|
||||||
|
import type { Map } from "leaflet";
|
||||||
|
import type { DragData } from "../../note_tree.js";
|
||||||
|
import froca from "../../../services/froca.js";
|
||||||
|
import branches from "../../../services/branches.js";
|
||||||
|
|
||||||
const CHILD_NOTE_ICON = "bx bx-pin";
|
const CHILD_NOTE_ICON = "bx bx-pin";
|
||||||
|
|
||||||
@@ -32,3 +36,45 @@ export async function createNewNote(noteId: string, e: LeafletMouseEvent) {
|
|||||||
moveMarker(note.noteId, e.latlng);
|
moveMarker(note.noteId, e.latlng);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function setupDragging($container: JQuery<HTMLElement>, map: Map, mapNoteId: string) {
|
||||||
|
$container.on("dragover", (e) => {
|
||||||
|
// Allow drag.
|
||||||
|
e.preventDefault();
|
||||||
|
});
|
||||||
|
$container.on("drop", async (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];
|
||||||
|
|
||||||
|
const offset = $container.offset();
|
||||||
|
const x = e.originalEvent.clientX - (offset?.left ?? 0);
|
||||||
|
const y = e.originalEvent.clientY - (offset?.top ?? 0);
|
||||||
|
const latlng = map.containerPointToLatLng([ x, y ]);
|
||||||
|
|
||||||
|
const note = await froca.getNote(noteId, true);
|
||||||
|
const parents = note?.getParentNoteIds();
|
||||||
|
if (parents?.includes(mapNoteId)) {
|
||||||
|
await moveMarker(noteId, latlng);
|
||||||
|
} else {
|
||||||
|
await branches.cloneNoteToParentNote(noteId, mapNoteId);
|
||||||
|
await moveMarker(noteId, latlng);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.warn(e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|||||||
@@ -7,10 +7,8 @@ import processNoteWithMarker, { processNoteWithGpxTrack } from "./markers.js";
|
|||||||
import { hasTouchBar } from "../../../services/utils.js";
|
import { hasTouchBar } from "../../../services/utils.js";
|
||||||
import toast from "../../../services/toast.js";
|
import toast from "../../../services/toast.js";
|
||||||
import { CommandListenerData, EventData } from "../../../components/app_context.js";
|
import { CommandListenerData, EventData } from "../../../components/app_context.js";
|
||||||
import { createNewNote, moveMarker } from "./editing.js";
|
import { createNewNote, moveMarker, setupDragging } from "./editing.js";
|
||||||
import link from "../../../services/link.js";
|
|
||||||
import { openMapContextMenu } from "./context_menu.js";
|
import { openMapContextMenu } from "./context_menu.js";
|
||||||
import setupDragging from "./dragging.js";
|
|
||||||
|
|
||||||
const TPL = /*html*/`
|
const TPL = /*html*/`
|
||||||
<div class="geo-view">
|
<div class="geo-view">
|
||||||
|
|||||||
Reference in New Issue
Block a user