mirror of
https://github.com/zadam/trilium.git
synced 2025-12-22 07:14:24 +01:00
feat(script/jsx): get right panel widgets to actually render
This commit is contained in:
parent
41220a9d1d
commit
644ff07a50
@ -6,7 +6,7 @@ import { t } from "./i18n.js";
|
|||||||
import ScriptContext from "./script_context.js";
|
import ScriptContext from "./script_context.js";
|
||||||
import server from "./server.js";
|
import server from "./server.js";
|
||||||
import toast from "./toast.js";
|
import toast from "./toast.js";
|
||||||
import toastService, { showError } from "./toast.js";
|
import toastService from "./toast.js";
|
||||||
import utils, { getErrorMessage } from "./utils.js";
|
import utils, { getErrorMessage } from "./utils.js";
|
||||||
|
|
||||||
// TODO: Deduplicate with server.
|
// TODO: Deduplicate with server.
|
||||||
@ -20,7 +20,9 @@ export interface Bundle {
|
|||||||
type LegacyWidget = (BasicWidget | RightPanelWidget) & {
|
type LegacyWidget = (BasicWidget | RightPanelWidget) & {
|
||||||
parentWidget?: string;
|
parentWidget?: string;
|
||||||
};
|
};
|
||||||
type Widget = LegacyWidget | WidgetDefinition;
|
export type Widget = (LegacyWidget | WidgetDefinition) & {
|
||||||
|
_noteId: string;
|
||||||
|
};
|
||||||
|
|
||||||
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}`, {
|
||||||
|
|||||||
@ -2,10 +2,11 @@
|
|||||||
import "./RightPanelContainer.css";
|
import "./RightPanelContainer.css";
|
||||||
|
|
||||||
import Split from "@triliumnext/split.js";
|
import Split from "@triliumnext/split.js";
|
||||||
import { VNode } from "preact";
|
import { isValidElement, VNode } from "preact";
|
||||||
import { useEffect, useRef } from "preact/hooks";
|
import { useEffect, useRef } from "preact/hooks";
|
||||||
|
|
||||||
import appContext from "../../components/app_context";
|
import appContext from "../../components/app_context";
|
||||||
|
import { Widget } from "../../services/bundle";
|
||||||
import { t } from "../../services/i18n";
|
import { t } from "../../services/i18n";
|
||||||
import options from "../../services/options";
|
import options from "../../services/options";
|
||||||
import { DEFAULT_GUTTER_SIZE } from "../../services/resizer";
|
import { DEFAULT_GUTTER_SIZE } from "../../services/resizer";
|
||||||
@ -51,7 +52,7 @@ export default function RightPanelContainer({ customWidgets }: { customWidgets:
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function useItems(rightPaneVisible: boolean, customWidgets: BasicWidget[]) {
|
function useItems(rightPaneVisible: boolean, customWidgets: Widget[]) {
|
||||||
const { note } = useActiveNoteContext();
|
const { note } = useActiveNoteContext();
|
||||||
const noteType = useNoteProperty(note, "type");
|
const noteType = useNoteProperty(note, "type");
|
||||||
const [ highlightsList ] = useTriliumOptionJson<string[]>("highlightsList");
|
const [ highlightsList ] = useTriliumOptionJson<string[]>("highlightsList");
|
||||||
@ -69,7 +70,7 @@ function useItems(rightPaneVisible: boolean, customWidgets: BasicWidget[]) {
|
|||||||
position: 20,
|
position: 20,
|
||||||
},
|
},
|
||||||
...customWidgets.map((w, i) => ({
|
...customWidgets.map((w, i) => ({
|
||||||
el: <CustomWidget key={w._noteId} originalWidget={w as LegacyRightPanelWidget} />,
|
el: isValidElement(w) ? w : <CustomLegacyWidget key={w._noteId} originalWidget={w as LegacyRightPanelWidget} />,
|
||||||
enabled: true,
|
enabled: true,
|
||||||
position: w.position ?? 30 + i * 10
|
position: w.position ?? 30 + i * 10
|
||||||
}))
|
}))
|
||||||
@ -99,7 +100,7 @@ function useSplit(visible: boolean) {
|
|||||||
}, [ visible ]);
|
}, [ visible ]);
|
||||||
}
|
}
|
||||||
|
|
||||||
function CustomWidget({ originalWidget }: { originalWidget: LegacyRightPanelWidget }) {
|
function CustomLegacyWidget({ originalWidget }: { originalWidget: LegacyRightPanelWidget }) {
|
||||||
const containerRef = useRef<HTMLDivElement>(null);
|
const containerRef = useRef<HTMLDivElement>(null);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user