diff --git a/apps/client/src/widgets/view_widgets/geo_view/dragging.ts b/apps/client/src/widgets/view_widgets/geo_view/dragging.ts deleted file mode 100644 index bc1b0aa97..000000000 --- a/apps/client/src/widgets/view_widgets/geo_view/dragging.ts +++ /dev/null @@ -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, 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); - } - }); -} diff --git a/apps/client/src/widgets/view_widgets/geo_view/editing.ts b/apps/client/src/widgets/view_widgets/geo_view/editing.ts index 7d70ba370..c9dd7368c 100644 --- a/apps/client/src/widgets/view_widgets/geo_view/editing.ts +++ b/apps/client/src/widgets/view_widgets/geo_view/editing.ts @@ -4,6 +4,10 @@ import { LOCATION_ATTRIBUTE } from "./index.js"; import dialog from "../../../services/dialog"; import server from "../../../services/server"; 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"; @@ -32,3 +36,45 @@ export async function createNewNote(noteId: string, e: LeafletMouseEvent) { moveMarker(note.noteId, e.latlng); } } + +export function setupDragging($container: JQuery, 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); + } + }); +} diff --git a/apps/client/src/widgets/view_widgets/geo_view/index.ts b/apps/client/src/widgets/view_widgets/geo_view/index.ts index 3181773d8..4af9b47cb 100644 --- a/apps/client/src/widgets/view_widgets/geo_view/index.ts +++ b/apps/client/src/widgets/view_widgets/geo_view/index.ts @@ -7,10 +7,8 @@ import processNoteWithMarker, { processNoteWithGpxTrack } from "./markers.js"; import { hasTouchBar } from "../../../services/utils.js"; import toast from "../../../services/toast.js"; import { CommandListenerData, EventData } from "../../../components/app_context.js"; -import { createNewNote, moveMarker } from "./editing.js"; -import link from "../../../services/link.js"; +import { createNewNote, moveMarker, setupDragging } from "./editing.js"; import { openMapContextMenu } from "./context_menu.js"; -import setupDragging from "./dragging.js"; const TPL = /*html*/`