fix(script/jsx): cannot find preact hydration function

This commit is contained in:
Elian Doran
2025-12-20 19:45:44 +02:00
parent 88945788d6
commit 41220a9d1d
2 changed files with 13 additions and 5 deletions

View File

@@ -1,6 +1,5 @@
import { dayjs } from "@triliumnext/commons";
import { formatLogMessage } from "@triliumnext/commons";
import { VNode } from "preact";
import { dayjs, formatLogMessage } from "@triliumnext/commons";
import { Fragment, h, VNode } from "preact";
import appContext from "../components/app_context.js";
import type Component from "../components/component.js";
@@ -467,12 +466,17 @@ export interface Api {
*/
log(message: string | object): void;
// Preact support
/**
* 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): void;
h: typeof h;
Fragment: typeof Fragment;
}
export interface WidgetDefinition {
@@ -739,12 +743,16 @@ function FrontendScriptApi(this: Api, startNote: FNote, currentNote: FNote, orig
this.logMessages[noteId].push(message);
this.logSpacedUpdates[noteId].scheduleUpdate();
};
// React support.
this.defineWidget = (definition) => {
return {
type: "react-widget",
...definition
};
};
this.h = h;
this.Fragment = Fragment;
}
export default FrontendScriptApi as any as {

View File

@@ -224,8 +224,8 @@ function buildJsx(jsxNote: BNote) {
const content = Buffer.isBuffer(contentRaw) ? contentRaw.toString("utf-8") : contentRaw;
return transform(content, {
transforms: ["jsx"],
jsxPragma: "h", // for Preact
jsxFragmentPragma: "Fragment",
jsxPragma: "api.h",
jsxFragmentPragma: "api.Fragment",
});
}