From dd4885e15c609c8cf3f9f46210e61ef15d7bb6a9 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Sun, 22 Dec 2024 18:03:03 +0200 Subject: [PATCH] chore(client/ts): port menus/link_context_menu --- src/public/app/components/app_context.ts | 9 ++++++++- src/public/app/menus/launcher_context_menu.ts | 7 +------ .../{link_context_menu.js => link_context_menu.ts} | 3 ++- src/public/app/services/link.ts | 10 ++++++---- 4 files changed, 17 insertions(+), 12 deletions(-) rename src/public/app/menus/{link_context_menu.js => link_context_menu.ts} (89%) diff --git a/src/public/app/components/app_context.ts b/src/public/app/components/app_context.ts index 1997315d4..d629c2e28 100644 --- a/src/public/app/components/app_context.ts +++ b/src/public/app/components/app_context.ts @@ -8,7 +8,7 @@ import zoomComponent from "./zoom.js"; import TabManager from "./tab_manager.js"; import Component from "./component.js"; import keyboardActionsService from "../services/keyboard_actions.js"; -import linkService from "../services/link.js"; +import linkService, { ViewScope } from "../services/link.js"; import MobileScreenSwitcherExecutor from "./mobile_screen_switcher.js"; import MainTreeExecutors from "./main_tree_executors.js"; import toast from "../services/toast.js"; @@ -62,7 +62,14 @@ type CommandMappings = { openNewNoteSplit: CommandData & { ntxId: string; notePath: string; + hoistedNoteId?: string; + viewScope?: ViewScope; }; + openInWindow: CommandData & { + notePath: string; + hoistedNoteId: string; + viewScope: ViewScope; + } executeInActiveNoteDetailWidget: CommandData & { callback: (value: NoteDetailWidget | PromiseLike) => void }; diff --git a/src/public/app/menus/launcher_context_menu.ts b/src/public/app/menus/launcher_context_menu.ts index eda0c5c14..b67a9b9c9 100644 --- a/src/public/app/menus/launcher_context_menu.ts +++ b/src/public/app/menus/launcher_context_menu.ts @@ -7,11 +7,6 @@ import { t } from '../services/i18n.js'; import type { SelectMenuItemEventListener } from '../components/events.js'; import NoteTreeWidget from '../widgets/note_tree.js'; -interface ShowContext { - pageX: number; - pageY: number; -} - export default class LauncherContextMenu implements SelectMenuItemEventListener { private treeWidget: NoteTreeWidget; @@ -22,7 +17,7 @@ export default class LauncherContextMenu implements SelectMenuItemEventListener this.node = node; } - async show(e: ShowContext) { + async show(e: PointerEvent) { contextMenu.show({ x: e.pageX, y: e.pageY, diff --git a/src/public/app/menus/link_context_menu.js b/src/public/app/menus/link_context_menu.ts similarity index 89% rename from src/public/app/menus/link_context_menu.js rename to src/public/app/menus/link_context_menu.ts index fda888f14..1c0993f76 100644 --- a/src/public/app/menus/link_context_menu.js +++ b/src/public/app/menus/link_context_menu.ts @@ -1,8 +1,9 @@ import { t } from "../services/i18n.js"; import contextMenu from "./context_menu.js"; import appContext from "../components/app_context.js"; +import { ViewScope } from "../services/link.js"; -function openContextMenu(notePath, e, viewScope = {}, hoistedNoteId = null) { +function openContextMenu(notePath: string, e: PointerEvent, viewScope: ViewScope = {}, hoistedNoteId: string | null = null) { contextMenu.show({ x: e.pageX, y: e.pageY, diff --git a/src/public/app/services/link.ts b/src/public/app/services/link.ts index a4d6a6d6e..e14f1a573 100644 --- a/src/public/app/services/link.ts +++ b/src/public/app/services/link.ts @@ -27,7 +27,7 @@ async function getLinkIcon(noteId: string, viewMode: ViewMode | undefined) { type ViewMode = "default" | "source" | "attachments" | string; -interface ViewScope { +export interface ViewScope { viewMode?: ViewMode; attachmentId?: string; } @@ -286,7 +286,7 @@ function goToLinkExt(evt: MouseEvent, hrefLink: string | undefined, $link: JQuer const electron = utils.dynamicRequire('electron'); electron.shell.openPath(hrefLink); } else { - // Enable protocols supported by CKEditor 5 to be clickable. + // Enable protocols supported by CKEditor 5 to be clickable. // Refer to `allowedProtocols` in https://github.com/TriliumNext/trilium-ckeditor5/blob/main/packages/ckeditor5-build-balloon-block/src/ckeditor.ts. // And be consistent with `allowedSchemes` in `src\services\html_sanitizer.ts` const allowedSchemes = [ @@ -305,7 +305,7 @@ function goToLinkExt(evt: MouseEvent, hrefLink: string | undefined, $link: JQuer return true; } -function linkContextMenu(e: Event) { +function linkContextMenu(e: PointerEvent) { const $link = $(e.target as any).closest("a"); const url = $link.attr("href") || $link.attr("data-href"); @@ -334,7 +334,7 @@ async function loadReferenceLinkTitle($el: JQuery, href: string | n console.warn("Missing note ID."); return; } - + const note = await froca.getNote(noteId, true); if (note) { @@ -403,6 +403,8 @@ $(document).on('click', "a", goToLink); // TODO: Check why the event is not supported. //@ts-ignore $(document).on('auxclick', "a", goToLink); // to handle the middle button +// TODO: Check why the event is not supported. +//@ts-ignore $(document).on('contextmenu', 'a', linkContextMenu); $(document).on('dblclick', "a", e => { e.preventDefault();