Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
chore(client/ts): port menus/link_context_menu
Elian Dorandd4885e15c60
diff --git a/src/public/app/components/app_context.ts b/src/public/app/components/app_context.tsindex 1997315d40..d629c2e283 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<NoteDetailWidget>) => void};diff --git a/src/public/app/menus/launcher_context_menu.ts b/src/public/app/menus/launcher_context_menu.tsindex eda0c5c14a..b67a9b9c94 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 SelectMenuItemEventListenerthis.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.tssimilarity index 89%rename from src/public/app/menus/link_context_menu.jsrename to src/public/app/menus/link_context_menu.tsindex fda888f142..1c0993f76c 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.tsindex a4d6a6d6ec..e14f1a573f 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: JQuerconst 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: JQuerreturn 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<HTMLElement>, href: string | nconsole.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();