chore(script/jsx): move Preact API in dedicated object

This commit is contained in:
Elian Doran 2025-12-20 20:10:19 +02:00
parent 644ff07a50
commit 4d7e5bc8f6
No known key found for this signature in database
3 changed files with 13 additions and 7 deletions

View File

@ -1,5 +1,5 @@
import { dayjs, formatLogMessage } from "@triliumnext/commons"; import { dayjs, formatLogMessage } from "@triliumnext/commons";
import { Fragment, h, VNode } from "preact"; import { VNode } from "preact";
import appContext from "../components/app_context.js"; import appContext from "../components/app_context.js";
import type Component from "../components/component.js"; import type Component from "../components/component.js";
@ -11,6 +11,7 @@ import RightPanelWidget from "../widgets/right_panel_widget.js";
import dateNotesService from "./date_notes.js"; import dateNotesService from "./date_notes.js";
import dialogService from "./dialog.js"; import dialogService from "./dialog.js";
import froca from "./froca.js"; import froca from "./froca.js";
import { preactAPI } from "./frontend_script_api_preact.js";
import { t } from "./i18n.js"; import { t } from "./i18n.js";
import linkService from "./link.js"; import linkService from "./link.js";
import noteTooltipService from "./note_tooltip.js"; import noteTooltipService from "./note_tooltip.js";
@ -475,8 +476,7 @@ export interface Api {
*/ */
defineWidget(definition: WidgetDefinition): void; defineWidget(definition: WidgetDefinition): void;
h: typeof h; preact: typeof preactAPI;
Fragment: typeof Fragment;
} }
export interface WidgetDefinition { export interface WidgetDefinition {
@ -751,8 +751,7 @@ function FrontendScriptApi(this: Api, startNote: FNote, currentNote: FNote, orig
...definition ...definition
}; };
}; };
this.h = h; this.preact = preactAPI;
this.Fragment = Fragment;
} }
export default FrontendScriptApi as any as { export default FrontendScriptApi as any as {

View File

@ -0,0 +1,7 @@
import { Fragment, h } from "preact";
export const preactAPI = Object.freeze({
// Core
h,
Fragment
});

View File

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