mirror of
https://github.com/zadam/trilium.git
synced 2025-12-21 23:04: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 server from "./server.js";
|
||||
import toast from "./toast.js";
|
||||
import toastService, { showError } from "./toast.js";
|
||||
import toastService from "./toast.js";
|
||||
import utils, { getErrorMessage } from "./utils.js";
|
||||
|
||||
// TODO: Deduplicate with server.
|
||||
@ -20,7 +20,9 @@ export interface Bundle {
|
||||
type LegacyWidget = (BasicWidget | RightPanelWidget) & {
|
||||
parentWidget?: string;
|
||||
};
|
||||
type Widget = LegacyWidget | WidgetDefinition;
|
||||
export type Widget = (LegacyWidget | WidgetDefinition) & {
|
||||
_noteId: string;
|
||||
};
|
||||
|
||||
async function getAndExecuteBundle(noteId: string, originEntity = null, script = null, params = null) {
|
||||
const bundle = await server.post<Bundle>(`script/bundle/${noteId}`, {
|
||||
|
||||
@ -2,10 +2,11 @@
|
||||
import "./RightPanelContainer.css";
|
||||
|
||||
import Split from "@triliumnext/split.js";
|
||||
import { VNode } from "preact";
|
||||
import { isValidElement, VNode } from "preact";
|
||||
import { useEffect, useRef } from "preact/hooks";
|
||||
|
||||
import appContext from "../../components/app_context";
|
||||
import { Widget } from "../../services/bundle";
|
||||
import { t } from "../../services/i18n";
|
||||
import options from "../../services/options";
|
||||
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 noteType = useNoteProperty(note, "type");
|
||||
const [ highlightsList ] = useTriliumOptionJson<string[]>("highlightsList");
|
||||
@ -69,7 +70,7 @@ function useItems(rightPaneVisible: boolean, customWidgets: BasicWidget[]) {
|
||||
position: 20,
|
||||
},
|
||||
...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,
|
||||
position: w.position ?? 30 + i * 10
|
||||
}))
|
||||
@ -99,7 +100,7 @@ function useSplit(visible: boolean) {
|
||||
}, [ visible ]);
|
||||
}
|
||||
|
||||
function CustomWidget({ originalWidget }: { originalWidget: LegacyRightPanelWidget }) {
|
||||
function CustomLegacyWidget({ originalWidget }: { originalWidget: LegacyRightPanelWidget }) {
|
||||
const containerRef = useRef<HTMLDivElement>(null);
|
||||
|
||||
return (
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user