refactor(react/type_widgets): bring back executeInActiveNoteDetailWidget

This commit is contained in:
Elian Doran 2025-10-05 17:31:51 +03:00
parent d3594e4a05
commit 3f7b8447d0
No known key found for this signature in database
3 changed files with 12 additions and 30 deletions

View file

@ -35,6 +35,7 @@ import type RootContainer from "../widgets/containers/root_container.js";
import { SqlExecuteResults } from "@triliumnext/commons"; import { SqlExecuteResults } from "@triliumnext/commons";
import { AddLinkOpts } from "../widgets/dialogs/add_link.jsx"; import { AddLinkOpts } from "../widgets/dialogs/add_link.jsx";
import { IncludeNoteOpts } from "../widgets/dialogs/include_note.jsx"; import { IncludeNoteOpts } from "../widgets/dialogs/include_note.jsx";
import { ReactWrappedWidget } from "../widgets/basic_widget.js";
interface Layout { interface Layout {
getRootWidget: (appContext: AppContext) => RootContainer; getRootWidget: (appContext: AppContext) => RootContainer;
@ -201,7 +202,7 @@ export type CommandMappings = {
resetLauncher: ContextMenuCommandData; resetLauncher: ContextMenuCommandData;
executeInActiveNoteDetailWidget: CommandData & { executeInActiveNoteDetailWidget: CommandData & {
callback: (value: NoteDetailWidget | PromiseLike<NoteDetailWidget>) => void; callback: (value: ReactWrappedWidget) => void;
}; };
executeWithTextEditor: CommandData & executeWithTextEditor: CommandData &
ExecuteCommandData<CKTextEditor> & { ExecuteCommandData<CKTextEditor> & {

View file

@ -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. * 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: * Apart from that, it:
* - It applies a full-height style depending on the content type (e.g. canvas notes). * - Applies a full-height style depending on the content type (e.g. canvas notes).
* - Focuses the content when switching tabs. * - 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. * - 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() { export default function NoteDetail() {
const containerRef = useRef<HTMLDivElement>(null); const containerRef = useRef<HTMLDivElement>(null);
@ -104,6 +107,11 @@ export default function NoteDetail() {
document.body.classList.toggle("force-fixed-tree", hasFixedTree); document.body.classList.toggle("force-fixed-tree", hasFixedTree);
}, [ note ]); }, [ note ]);
useTriliumEvent("executeInActiveNoteDetailWidget", ({ callback }) => {
if (!noteContext?.isActive()) return;
callback(parentComponent);
});
useTriliumEvent("executeWithTypeWidget", ({ resolve, ntxId: eventNtxId }) => { useTriliumEvent("executeWithTypeWidget", ({ resolve, ntxId: eventNtxId }) => {
if (eventNtxId !== ntxId || !activeNoteType || !containerRef.current) return; if (eventNtxId !== ntxId || !activeNoteType || !containerRef.current) return;

View file

@ -13,17 +13,6 @@ export default class NoteDetailWidget extends NoteContextAwareWidget {
appContext.addBeforeUnloadListener(this); 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">) { async beforeNoteSwitchEvent({ noteContext }: EventData<"beforeNoteSwitch">) {
if (this.isNoteContext(noteContext.ntxId)) { if (this.isNoteContext(noteContext.ntxId)) {
await this.spacedUpdate.updateNowIfNecessary(); await this.spacedUpdate.updateNowIfNecessary();
@ -49,20 +38,4 @@ export default class NoteDetailWidget extends NoteContextAwareWidget {
return this.spacedUpdate.isAllSavedAndTriggerUpdate(); 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();
}
}
} }