feat(right_pane): add context menu with go to source for custom widgets

This commit is contained in:
Elian Doran 2025-12-20 11:39:46 +02:00
parent eeea96b98c
commit dced799976
No known key found for this signature in database
3 changed files with 32 additions and 3 deletions

View File

@ -2203,6 +2203,7 @@
"right_pane": {
"empty_message": "Nothing to show for this note",
"empty_button": "Hide the panel",
"toggle": "Toggle right panel"
"toggle": "Toggle right panel",
"custom_widget_go_to_source": "Go to source code"
}
}

View File

@ -4,6 +4,7 @@ import "./RightPanelContainer.css";
import Split from "@triliumnext/split.js";
import { useEffect, useRef } from "preact/hooks";
import appContext from "../../components/app_context";
import { t } from "../../services/i18n";
import options from "../../services/options";
import { DEFAULT_GUTTER_SIZE } from "../../services/resizer";
@ -77,6 +78,13 @@ function CustomWidget({ originalWidget }: { originalWidget: LegacyRightPanelWidg
id={originalWidget._noteId}
title={originalWidget.widgetTitle}
containerRef={containerRef}
contextMenuItems={[
{
title: t("right_pane.custom_widget_go_to_source"),
uiIcon: "bx bx-code-curly",
handler: () => appContext.tabManager.openInNewTab(originalWidget._noteId, null, true)
}
]}
>
<CustomWidgetContent originalWidget={originalWidget} />
</RightPanelWidget>

View File

@ -2,6 +2,8 @@ import clsx from "clsx";
import { ComponentChildren, RefObject } from "preact";
import { useContext, useState } from "preact/hooks";
import contextMenu, { MenuItem } from "../../menus/context_menu";
import ActionButton from "../react/ActionButton";
import { useSyncedRef, useTriliumOptionJson } from "../react/hooks";
import Icon from "../react/Icon";
import { ParentComponent } from "../react/react_utils";
@ -12,9 +14,10 @@ interface RightPanelWidgetProps {
children: ComponentChildren;
buttons?: ComponentChildren;
containerRef?: RefObject<HTMLDivElement>;
contextMenuItems?: MenuItem<unknown>[];
}
export default function RightPanelWidget({ id, title, buttons, children, containerRef: externalContainerRef }: RightPanelWidgetProps) {
export default function RightPanelWidget({ id, title, buttons, children, containerRef: externalContainerRef, contextMenuItems }: RightPanelWidgetProps) {
const [ rightPaneCollapsedItems, setRightPaneCollapsedItems ] = useTriliumOptionJson<string[]>("rightPaneCollapsedItems");
const [ expanded, setExpanded ] = useState(!rightPaneCollapsedItems.includes(id));
const containerRef = useSyncedRef<HTMLDivElement>(externalContainerRef, null);
@ -49,7 +52,24 @@ export default function RightPanelWidget({ id, title, buttons, children, contain
icon="bx bx-chevron-down"
/>
<div class="card-header-title">{title}</div>
<div class="card-header-buttons">{buttons}</div>
<div class="card-header-buttons">
{buttons}
{contextMenuItems && (
<ActionButton
icon="bx bx-dots-vertical-rounded"
text=""
onClick={e => {
e.stopPropagation();
contextMenu.show({
x: e.pageX,
y: e.pageY,
items: contextMenuItems,
selectMenuItemHandler: () => {}
});
}}
/>
)}
</div>
</div>
<div id={parentComponent?.componentId} class="body-wrapper">