chore(script/jsx): move defineWidget into Preact API

This commit is contained in:
Elian Doran
2025-12-20 21:25:36 +02:00
parent 34d5793888
commit f64de3acca
3 changed files with 27 additions and 31 deletions

View File

@@ -1,13 +1,34 @@
import { Fragment, h } from "preact";
import { Fragment, h, VNode } from "preact";
import * as hooks from "preact/hooks";
import RightPanelWidget from "../widgets/sidebar/RightPanelWidget";
export interface WidgetDefinition {
parent: "right-pane",
render: () => VNode
}
export interface WidgetDefinitionWithType extends WidgetDefinition {
type: "react-widget"
}
export const preactAPI = Object.freeze({
// Core
h,
Fragment,
/**
* Method that must be run for widget scripts that run on Preact, using JSX. The method just returns the same definition, reserved for future typechecking and perhaps validation purposes.
*
* @param definition the widget definition.
*/
defineWidget(definition: WidgetDefinition) {
return {
type: "react-widget",
...definition
};
},
RightPanelWidget,
...hooks