mirror of
https://github.com/zadam/trilium.git
synced 2025-12-24 00:04:23 +01:00
This commit is contained in:
parent
af37c175a3
commit
0688ea7de3
@ -23,9 +23,10 @@ export interface Bundle {
|
|||||||
type LegacyWidget = (BasicWidget | RightPanelWidget) & {
|
type LegacyWidget = (BasicWidget | RightPanelWidget) & {
|
||||||
parentWidget?: string;
|
parentWidget?: string;
|
||||||
};
|
};
|
||||||
export type Widget = (LegacyWidget | WidgetDefinitionWithType) & {
|
type WithNoteId<T> = T & {
|
||||||
_noteId: string;
|
_noteId: string;
|
||||||
};
|
};
|
||||||
|
export type Widget = WithNoteId<(LegacyWidget | WidgetDefinitionWithType)>;
|
||||||
|
|
||||||
async function getAndExecuteBundle(noteId: string, originEntity = null, script = null, params = null) {
|
async function getAndExecuteBundle(noteId: string, originEntity = null, script = null, params = null) {
|
||||||
const bundle = await server.post<Bundle>(`script/bundle/${noteId}`, {
|
const bundle = await server.post<Bundle>(`script/bundle/${noteId}`, {
|
||||||
@ -71,8 +72,8 @@ async function executeStartupBundles() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class WidgetsByParent {
|
export class WidgetsByParent {
|
||||||
private legacyWidgets: Record<string, LegacyWidget[]>;
|
private legacyWidgets: Record<string, WithNoteId<LegacyWidget>[]>;
|
||||||
private preactWidgets: Record<string, WidgetDefinitionWithType[]>;
|
private preactWidgets: Record<string, WithNoteId<WidgetDefinitionWithType>[]>;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.legacyWidgets = {};
|
this.legacyWidgets = {};
|
||||||
@ -84,7 +85,7 @@ export class WidgetsByParent {
|
|||||||
let isPreact = false;
|
let isPreact = false;
|
||||||
if ("type" in widget && widget.type === "preact-widget") {
|
if ("type" in widget && widget.type === "preact-widget") {
|
||||||
// React-based script.
|
// 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] = this.preactWidgets[reactWidget.parent] || [];
|
||||||
this.preactWidgets[reactWidget.parent].push(reactWidget);
|
this.preactWidgets[reactWidget.parent].push(reactWidget);
|
||||||
isPreact = true;
|
isPreact = true;
|
||||||
|
|||||||
@ -175,7 +175,6 @@ describe("JSX building", () => {
|
|||||||
"use strict";const _triliumapi = api;
|
"use strict";const _triliumapi = api;
|
||||||
_triliumapi.log.call(void 0, "Hi");
|
_triliumapi.log.call(void 0, "Hi");
|
||||||
`;
|
`;
|
||||||
console.log(buildJsx(script).code);
|
|
||||||
expect(buildJsx(script).code).toStrictEqual(expected);
|
expect(buildJsx(script).code).toStrictEqual(expected);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@ -237,13 +237,13 @@ export function buildJsx(contentRaw: string | Buffer) {
|
|||||||
|
|
||||||
// Rewrite ESM-like imports to Preact, to `const { foo } = api.preact`
|
// Rewrite ESM-like imports to Preact, to `const { foo } = api.preact`
|
||||||
code = code.replaceAll(
|
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;'
|
'const $1 = api.preact;'
|
||||||
);
|
);
|
||||||
|
|
||||||
// Rewrite ESM-like imports to internal API, to `const { foo } = api.preact`
|
// Rewrite ESM-like imports to internal API, to `const { foo } = api.preact`
|
||||||
code = code.replaceAll(
|
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;'
|
'const $1 = api;'
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user