chore(client): address requested changes
Some checks failed
Checks / main (push) Has been cancelled

This commit is contained in:
Elian Doran 2025-12-21 22:59:21 +02:00
parent af37c175a3
commit 0688ea7de3
No known key found for this signature in database
3 changed files with 7 additions and 7 deletions

View File

@ -23,9 +23,10 @@ export interface Bundle {
type LegacyWidget = (BasicWidget | RightPanelWidget) & {
parentWidget?: string;
};
export type Widget = (LegacyWidget | WidgetDefinitionWithType) & {
type WithNoteId<T> = T & {
_noteId: string;
};
export type Widget = WithNoteId<(LegacyWidget | WidgetDefinitionWithType)>;
async function getAndExecuteBundle(noteId: string, originEntity = null, script = null, params = null) {
const bundle = await server.post<Bundle>(`script/bundle/${noteId}`, {
@ -71,8 +72,8 @@ async function executeStartupBundles() {
}
export class WidgetsByParent {
private legacyWidgets: Record<string, LegacyWidget[]>;
private preactWidgets: Record<string, WidgetDefinitionWithType[]>;
private legacyWidgets: Record<string, WithNoteId<LegacyWidget>[]>;
private preactWidgets: Record<string, WithNoteId<WidgetDefinitionWithType>[]>;
constructor() {
this.legacyWidgets = {};
@ -84,7 +85,7 @@ export class WidgetsByParent {
let isPreact = false;
if ("type" in widget && widget.type === "preact-widget") {
// React-based script.
const reactWidget = widget as WidgetDefinitionWithType;
const reactWidget = widget as WithNoteId<WidgetDefinitionWithType>;
this.preactWidgets[reactWidget.parent] = this.preactWidgets[reactWidget.parent] || [];
this.preactWidgets[reactWidget.parent].push(reactWidget);
isPreact = true;

View File

@ -175,7 +175,6 @@ describe("JSX building", () => {
"use strict";const _triliumapi = api;
_triliumapi.log.call(void 0, "Hi");
`;
console.log(buildJsx(script).code);
expect(buildJsx(script).code).toStrictEqual(expected);
});
});

View File

@ -237,13 +237,13 @@ export function buildJsx(contentRaw: string | Buffer) {
// Rewrite ESM-like imports to Preact, to `const { foo } = api.preact`
code = code.replaceAll(
/var\s+(\w+)\s*=\s*require\(['"]trilium:preact['"]\);?/g,
/(?:var|let|const)\s+(\w+)\s*=\s*require\(['"]trilium:preact['"]\);?/g,
'const $1 = api.preact;'
);
// Rewrite ESM-like imports to internal API, to `const { foo } = api.preact`
code = code.replaceAll(
/var\s+(\w+)\s*=\s*require\(['"]trilium:api['"]\);?/g,
/(?:var|let|const)\s+(\w+)\s*=\s*require\(['"]trilium:api['"]\);?/g,
'const $1 = api;'
);