mirror of
https://github.com/zadam/trilium.git
synced 2025-12-22 07:14:24 +01:00
feat(right_pane): add context menu with go to source for custom widgets
This commit is contained in:
parent
eeea96b98c
commit
dced799976
@ -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"
|
||||
}
|
||||
}
|
||||
|
||||
@ -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>
|
||||
|
||||
@ -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">
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user