mirror of
https://github.com/zadam/trilium.git
synced 2025-12-23 16:49:58 +01:00
chore(client/jsx): use different method for launcher widget defs
This commit is contained in:
@@ -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<LauncherWidgetDefinitionWithType, "type">) {
|
||||
return {
|
||||
type: "preact-launcher-widget",
|
||||
...definition
|
||||
};
|
||||
},
|
||||
|
||||
RightPanelWidget,
|
||||
|
||||
...hooks,
|
||||
|
||||
@@ -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<BasicWidget | NoteContextAwareWidget | WidgetDefinition>();
|
||||
const [ widget, setWidget ] = useState<BasicWidget | NoteContextAwareWidget | LauncherWidgetDefinitionWithType>();
|
||||
|
||||
const parentComponent = useContext(ParentComponent) as BasicWidget | null;
|
||||
parentComponent?.contentSized();
|
||||
@@ -151,8 +151,8 @@ export function CustomWidget({ launcherNote }: LauncherNoteProps) {
|
||||
return (
|
||||
<div>
|
||||
{widget && (
|
||||
("type" in widget && widget.type === "preact-widget")
|
||||
? <ReactWidgetRenderer widget={widget as WidgetDefinition} />
|
||||
("type" in widget && widget.type === "preact-launcher-widget")
|
||||
? <ReactWidgetRenderer widget={widget as LauncherWidgetDefinitionWithType} />
|
||||
: <LegacyWidgetRenderer widget={widget as BasicWidget} />
|
||||
)}
|
||||
</div>
|
||||
@@ -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 <El />;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user