diff --git a/apps/client/src/widgets/react/hooks.tsx b/apps/client/src/widgets/react/hooks.tsx index 9868e9f55..dfaa029d0 100644 --- a/apps/client/src/widgets/react/hooks.tsx +++ b/apps/client/src/widgets/react/hooks.tsx @@ -7,10 +7,12 @@ import options, { type OptionValue } from "../../services/options"; import utils, { reloadFrontendApp } from "../../services/utils"; import Component from "../../components/component"; import NoteContext from "../../components/note_context"; -import { ReactWrappedWidget } from "../basic_widget"; +import BasicWidget, { ReactWrappedWidget } from "../basic_widget"; import FNote from "../../entities/fnote"; import attributes from "../../services/attributes"; import FBlob from "../../entities/fblob"; +import RawHtml from "./RawHtml"; +import NoteContextAwareWidget from "../note_context_aware_widget"; type TriliumEventHandler = (data: EventData) => void; const registeredHandlers: Map[]>> = new Map(); @@ -410,4 +412,22 @@ export function useNoteBlob(note: FNote | null | undefined): [ FBlob | null | un }); return [ blob ] as const; +} + +export function useLegacyWidget(widgetFactory: () => BasicWidget, { noteContext }: { + noteContext?: NoteContext; +} = {}) { + const widget = useMemo(widgetFactory, []); + const parentComponent = useContext(ParentComponent); + + if (parentComponent) { + parentComponent.child(widget); + } + + if (noteContext && widget instanceof NoteContextAwareWidget) { + console.log("Inject!"); + widget.setNoteContextEvent({ noteContext }); + } + + return } \ No newline at end of file