Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
refactor(react/type_widgets): bring back executeInActiveNoteDetailWidget
Elian Doran3f7b8447d079
diff --git a/apps/client/src/components/app_context.ts b/apps/client/src/components/app_context.tsindex 68343b864c..35efd283ab 100644--- a/apps/client/src/components/app_context.ts+++ b/apps/client/src/components/app_context.ts@@ -35,6 +35,7 @@ import type RootContainer from "../widgets/containers/root_container.js";import { SqlExecuteResults } from "@triliumnext/commons";import { AddLinkOpts } from "../widgets/dialogs/add_link.jsx";import { IncludeNoteOpts } from "../widgets/dialogs/include_note.jsx";+import { ReactWrappedWidget } from "../widgets/basic_widget.js";interface Layout {getRootWidget: (appContext: AppContext) => RootContainer;@@ -201,7 +202,7 @@ export type CommandMappings = {resetLauncher: ContextMenuCommandData;executeInActiveNoteDetailWidget: CommandData & {- callback: (value: NoteDetailWidget | PromiseLike<NoteDetailWidget>) => void;+ callback: (value: ReactWrappedWidget) => void;};executeWithTextEditor: CommandData &ExecuteCommandData<CKTextEditor> & {diff --git a/apps/client/src/widgets/NoteDetail.tsx b/apps/client/src/widgets/NoteDetail.tsxindex 6f26ea2cbe..65f1abaad0 100644--- a/apps/client/src/widgets/NoteDetail.tsx+++ b/apps/client/src/widgets/NoteDetail.tsx@@ -13,10 +13,13 @@ import { dynamicRequire, isMobile } from "../services/utils";/*** The note detail is in charge of rendering the content of a note, by determining its type (e.g. text, code) and using the appropriate view widget.*- * Apart from that:- * - It applies a full-height style depending on the content type (e.g. canvas notes).+ * Apart from that, it:+ * - Applies a full-height style depending on the content type (e.g. canvas notes).* - Focuses the content when switching tabs.* - Caches the note type elements based on what the user has accessed, in order to quickly load it again.+ * - Fixes the tree for launch bar configurations on mobile.+ * - Provides scripting events such as obtaining the active note detail widget, or note type widget.+ * - Printing and exporting to PDF.*/export default function NoteDetail() {const containerRef = useRef<HTMLDivElement>(null);@@ -104,6 +107,11 @@ export default function NoteDetail() {document.body.classList.toggle("force-fixed-tree", hasFixedTree);}, [ note ]);+ useTriliumEvent("executeInActiveNoteDetailWidget", ({ callback }) => {+ if (!noteContext?.isActive()) return;+ callback(parentComponent);+ });+useTriliumEvent("executeWithTypeWidget", ({ resolve, ntxId: eventNtxId }) => {if (eventNtxId !== ntxId || !activeNoteType || !containerRef.current) return;diff --git a/apps/client/src/widgets/note_detail.ts.bak b/apps/client/src/widgets/note_detail.ts.bakindex ceafff9e6e..abbbbeb1e5 100644--- a/apps/client/src/widgets/note_detail.ts.bak+++ b/apps/client/src/widgets/note_detail.ts.bak@@ -13,17 +13,6 @@ export default class NoteDetailWidget extends NoteContextAwareWidget {appContext.addBeforeUnloadListener(this);}- /**- * sets full height of container that contains note content for a subset of note-types- */- getTypeWidget() {- if (!this.type || !this.typeWidgets[this.type]) {- throw new Error(t(`note_detail.could_not_find_typewidget`, { type: this.type }));- }-- return this.typeWidgets[this.type];- }-async beforeNoteSwitchEvent({ noteContext }: EventData<"beforeNoteSwitch">) {if (this.isNoteContext(noteContext.ntxId)) {await this.spacedUpdate.updateNowIfNecessary();@@ -49,20 +38,4 @@ export default class NoteDetailWidget extends NoteContextAwareWidget {return this.spacedUpdate.isAllSavedAndTriggerUpdate();}- async executeInActiveNoteDetailWidgetEvent({ callback }: EventData<"executeInActiveNoteDetailWidget">) {- if (!this.isActiveNoteContext()) {- return;- }-- await this.initialized;-- callback(this);- }-- renderActiveNoteEvent() {- if (this.noteContext?.isActive()) {- this.refresh();- }- }-}