mirror of
https://github.com/TriliumNext/Trilium.git
synced 2025-12-11 05:45:26 -06:00
feat(render): integrate with search
This commit is contained in:
parent
b990770e48
commit
763c489cd3
@ -45,13 +45,13 @@ function RevisionsButton({ note }: { note: FNote }) {
|
|||||||
function NoteContextMenu({ note, noteContext }: { note: FNote, noteContext?: NoteContext }) {
|
function NoteContextMenu({ note, noteContext }: { note: FNote, noteContext?: NoteContext }) {
|
||||||
const parentComponent = useContext(ParentComponent);
|
const parentComponent = useContext(ParentComponent);
|
||||||
const canBeConvertedToAttachment = note?.isEligibleForConversionToAttachment();
|
const canBeConvertedToAttachment = note?.isEligibleForConversionToAttachment();
|
||||||
const isSearchable = ["text", "code", "book", "mindMap", "doc"].includes(note.type);
|
const isSearchable = ["text", "code", "book", "mindMap", "doc", "render"].includes(note.type);
|
||||||
const isInOptions = note.noteId.startsWith("_options");
|
const isInOptions = note.noteId.startsWith("_options");
|
||||||
const isPrintable = ["text", "code"].includes(note.type);
|
const isPrintable = ["text", "code"].includes(note.type);
|
||||||
const isElectron = getIsElectron();
|
const isElectron = getIsElectron();
|
||||||
const isMac = getIsMac();
|
const isMac = getIsMac();
|
||||||
const hasSource = ["text", "code", "relationMap", "mermaid", "canvas", "mindMap"].includes(note.type);
|
const hasSource = ["text", "code", "relationMap", "mermaid", "canvas", "mindMap"].includes(note.type);
|
||||||
const isSearchOrBook = ["search", "book"].includes(note.type);
|
const isSearchOrBook = ["search", "book"].includes(note.type);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Dropdown
|
<Dropdown
|
||||||
@ -74,7 +74,7 @@ function NoteContextMenu({ note, noteContext }: { note: FNote, noteContext?: Not
|
|||||||
<CommandItem icon="bx bx-export" text={t("note_actions.export_note")}
|
<CommandItem icon="bx bx-export" text={t("note_actions.export_note")}
|
||||||
disabled={isInOptions || note.noteId === "_backendLog"}
|
disabled={isInOptions || note.noteId === "_backendLog"}
|
||||||
command={() => noteContext?.notePath && parentComponent?.triggerCommand("showExportDialog", {
|
command={() => noteContext?.notePath && parentComponent?.triggerCommand("showExportDialog", {
|
||||||
notePath: noteContext.notePath,
|
notePath: noteContext.notePath,
|
||||||
defaultType: "single"
|
defaultType: "single"
|
||||||
})} />
|
})} />
|
||||||
<FormDropdownDivider />
|
<FormDropdownDivider />
|
||||||
@ -133,4 +133,4 @@ function ConvertToAttachment({ note }: { note: FNote }) {
|
|||||||
}}
|
}}
|
||||||
>{t("note_actions.convert_into_attachment")}</FormListItem>
|
>{t("note_actions.convert_into_attachment")}</FormListItem>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -18,15 +18,25 @@ export default function Render({ note, noteContext, ntxId }: TypeWidgetProps) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
useEffect(refresh, [ note ]);
|
useEffect(refresh, [ note ]);
|
||||||
|
|
||||||
|
// Keyboard shortcut.
|
||||||
useTriliumEvent("renderActiveNote", () => {
|
useTriliumEvent("renderActiveNote", () => {
|
||||||
if (noteContext?.isActive()) return;
|
if (noteContext?.isActive()) return;
|
||||||
refresh();
|
refresh();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Refresh on floating buttons.
|
||||||
useTriliumEvent("refreshData", ({ ntxId: eventNtxId }) => {
|
useTriliumEvent("refreshData", ({ ntxId: eventNtxId }) => {
|
||||||
if (eventNtxId !== ntxId) return;
|
if (eventNtxId !== ntxId) return;
|
||||||
refresh();
|
refresh();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Integration with search.
|
||||||
|
useTriliumEvent("executeWithContentElement", ({ resolve, ntxId: eventNtxId }) => {
|
||||||
|
if (eventNtxId !== ntxId) return;
|
||||||
|
resolve(refToJQuerySelector(contentRef));
|
||||||
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="note-detail-render note-detail-printable">
|
<div className="note-detail-render note-detail-printable">
|
||||||
{!renderNotesFound && (
|
{!renderNotesFound && (
|
||||||
|
|||||||
@ -1,44 +0,0 @@
|
|||||||
import renderService from "../../services/render.js";
|
|
||||||
import TypeWidget from "./type_widget.js";
|
|
||||||
import type FNote from "../../entities/fnote.js";
|
|
||||||
import type { EventData } from "../../components/app_context.js";
|
|
||||||
|
|
||||||
|
|
||||||
export default class RenderTypeWidget extends TypeWidget {
|
|
||||||
|
|
||||||
private $noteDetailRenderHelp!: JQuery<HTMLElement>;
|
|
||||||
private $noteDetailRenderContent!: JQuery<HTMLElement>;
|
|
||||||
|
|
||||||
static getType() {
|
|
||||||
return "render";
|
|
||||||
}
|
|
||||||
|
|
||||||
doRender() {
|
|
||||||
this.$widget = $(TPL);
|
|
||||||
this.$noteDetailRenderHelp = this.$widget.find(".note-detail-render-help");
|
|
||||||
this.$noteDetailRenderContent = this.$widget.find(".note-detail-render-content");
|
|
||||||
|
|
||||||
super.doRender();
|
|
||||||
}
|
|
||||||
|
|
||||||
async doRefresh(note: FNote) {
|
|
||||||
this.$widget.show();
|
|
||||||
this.$noteDetailRenderHelp.hide();
|
|
||||||
|
|
||||||
const renderNotesFound = await renderService.render(note, this.$noteDetailRenderContent);
|
|
||||||
}
|
|
||||||
|
|
||||||
cleanup() {
|
|
||||||
this.$noteDetailRenderContent.empty();
|
|
||||||
}
|
|
||||||
|
|
||||||
async executeWithContentElementEvent({ resolve, ntxId }: EventData<"executeWithContentElement">) {
|
|
||||||
if (!this.isNoteContext(ntxId)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
await this.initialized;
|
|
||||||
|
|
||||||
resolve(this.$noteDetailRenderContent);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
x
Reference in New Issue
Block a user