chore(breadcrumb): get a menu to render on note link

This commit is contained in:
Elian Doran 2025-12-16 09:27:40 +02:00
parent 16a6344687
commit 587ea42700
No known key found for this signature in database
2 changed files with 27 additions and 2 deletions

View File

@ -6,6 +6,7 @@ import { Fragment } from "preact/jsx-runtime";
import appContext from "../../components/app_context";
import NoteContext from "../../components/note_context";
import FNote from "../../entities/fnote";
import contextMenu from "../../menus/context_menu";
import link_context_menu from "../../menus/link_context_menu";
import { getReadableTextColor } from "../../services/css_class_manager";
import froca from "../../services/froca";
@ -150,7 +151,22 @@ function BreadcrumbItem({ index, notePath, noteContext, notePathLength }: { inde
</>;
}
return <NoteLink notePath={notePath} />;
return <NoteLink
notePath={notePath}
noContextMenu
onContextMenu={(e) => {
e.preventDefault();
contextMenu.show({
items: [
{
title: "Foo"
}
],
x: e.pageX,
y: e.pageY
});
}}
/>;
}
function BreadcrumbSeparator({ notePath, noteContext, activeNotePath }: { notePath: string, activeNotePath: string, noteContext: NoteContext | undefined }) {

View File

@ -1,4 +1,5 @@
import { useEffect, useRef, useState } from "preact/hooks";
import link, { ViewScope } from "../../services/link";
import { useImperativeSearchHighlighlighting, useTriliumEvent } from "./hooks";
@ -16,9 +17,10 @@ interface NoteLinkOpts {
title?: string;
viewScope?: ViewScope;
noContextMenu?: boolean;
onContextMenu?: (e: MouseEvent) => void;
}
export default function NoteLink({ className, containerClassName, notePath, showNotePath, showNoteIcon, style, noPreview, noTnLink, highlightedTokens, title, viewScope, noContextMenu }: NoteLinkOpts) {
export default function NoteLink({ className, containerClassName, notePath, showNotePath, showNoteIcon, style, noPreview, noTnLink, highlightedTokens, title, viewScope, noContextMenu, onContextMenu }: NoteLinkOpts) {
const stringifiedNotePath = Array.isArray(notePath) ? notePath.join("/") : notePath;
const noteId = stringifiedNotePath.split("/").at(-1);
const ref = useRef<HTMLSpanElement>(null);
@ -35,6 +37,13 @@ export default function NoteLink({ className, containerClassName, notePath, show
}).then(setJqueryEl);
}, [ stringifiedNotePath, showNotePath, title, viewScope, noteTitle ]);
useEffect(() => {
const el = jqueryEl?.[0];
if (!el || !onContextMenu) return;
el.addEventListener("contextmenu", onContextMenu);
return () => el.removeEventListener("contextmenu", onContextMenu);
}, [ jqueryEl, onContextMenu ]);
useEffect(() => {
if (!ref.current || !jqueryEl) return;
ref.current.replaceChildren(jqueryEl[0]);