diff --git a/apps/client/src/services/frontend_script_api_preact.ts b/apps/client/src/services/frontend_script_api_preact.ts index 61f62159e..081094046 100644 --- a/apps/client/src/services/frontend_script_api_preact.ts +++ b/apps/client/src/services/frontend_script_api_preact.ts @@ -14,6 +14,11 @@ export interface WidgetDefinitionWithType extends WidgetDefinition { type: "preact-widget" } +export interface LauncherWidgetDefinitionWithType { + type: "preact-launcher-widget" + render: () => VNode +} + export const preactAPI = Object.freeze({ // Core h, @@ -31,6 +36,13 @@ export const preactAPI = Object.freeze({ }; }, + defineLauncherWidget(definition: Omit) { + return { + type: "preact-launcher-widget", + ...definition + }; + }, + RightPanelWidget, ...hooks, diff --git a/apps/client/src/widgets/launch_bar/LauncherDefinitions.tsx b/apps/client/src/widgets/launch_bar/LauncherDefinitions.tsx index 908fe0bc0..5aa289257 100644 --- a/apps/client/src/widgets/launch_bar/LauncherDefinitions.tsx +++ b/apps/client/src/widgets/launch_bar/LauncherDefinitions.tsx @@ -4,7 +4,7 @@ import appContext, { CommandNames } from "../../components/app_context"; import FNote from "../../entities/fnote"; import date_notes from "../../services/date_notes"; import dialog from "../../services/dialog"; -import { WidgetDefinition } from "../../services/frontend_script_api_preact"; +import { LauncherWidgetDefinitionWithType } from "../../services/frontend_script_api_preact"; import { t } from "../../services/i18n"; import toast from "../../services/toast"; import { getErrorMessage, isMobile } from "../../services/utils"; @@ -122,7 +122,7 @@ export function QuickSearchLauncherWidget() { export function CustomWidget({ launcherNote }: LauncherNoteProps) { const [ widgetNote ] = useNoteRelationTarget(launcherNote, "widget"); - const [ widget, setWidget ] = useState(); + const [ widget, setWidget ] = useState(); const parentComponent = useContext(ParentComponent) as BasicWidget | null; parentComponent?.contentSized(); @@ -151,8 +151,8 @@ export function CustomWidget({ launcherNote }: LauncherNoteProps) { return (
{widget && ( - ("type" in widget && widget.type === "preact-widget") - ? + ("type" in widget && widget.type === "preact-launcher-widget") + ? : )}
@@ -167,7 +167,7 @@ export function LegacyWidgetRenderer({ widget }: { widget: BasicWidget }) { return widgetEl; } -function ReactWidgetRenderer({ widget }: { widget: WidgetDefinition }) { +function ReactWidgetRenderer({ widget }: { widget: LauncherWidgetDefinitionWithType }) { const El = widget.render; return ; }