mirror of
https://github.com/zadam/trilium.git
synced 2025-10-30 11:09:05 +01:00
37 lines
1.0 KiB
TypeScript
37 lines
1.0 KiB
TypeScript
import { useEffect, useMemo, useState } from "preact/hooks";
|
|
import link from "../../services/link";
|
|
import RawHtml from "./RawHtml";
|
|
|
|
interface NoteLinkOpts {
|
|
notePath: string | string[];
|
|
showNotePath?: boolean;
|
|
style?: Record<string, string | number>;
|
|
noPreview?: boolean;
|
|
noTnLink?: boolean;
|
|
}
|
|
|
|
export default function NoteLink({ notePath, showNotePath, style, noPreview, noTnLink }: NoteLinkOpts) {
|
|
const stringifiedNotePath = Array.isArray(notePath) ? notePath.join("/") : notePath;
|
|
const [ jqueryEl, setJqueryEl ] = useState<JQuery<HTMLElement>>();
|
|
|
|
useEffect(() => {
|
|
link.createLink(stringifiedNotePath, { showNotePath })
|
|
.then(setJqueryEl);
|
|
}, [ stringifiedNotePath, showNotePath ]);
|
|
|
|
if (style) {
|
|
jqueryEl?.css(style);
|
|
}
|
|
|
|
const $linkEl = jqueryEl?.find("a");
|
|
if (noPreview) {
|
|
$linkEl?.addClass("no-tooltip-preview");
|
|
}
|
|
|
|
if (!noTnLink) {
|
|
$linkEl?.addClass("tn-link");
|
|
}
|
|
|
|
return <RawHtml html={jqueryEl} />
|
|
|
|
} |