mirror of
https://github.com/zadam/trilium.git
synced 2026-02-22 05:34:27 +01:00
feat(client/render_note): display rendering errors
This commit is contained in:
parent
8b3e3c2c3a
commit
a6e596a5e3
@ -6,7 +6,7 @@ import bundleService, { type Bundle } from "./bundle.js";
|
|||||||
import froca from "./froca.js";
|
import froca from "./froca.js";
|
||||||
import server from "./server.js";
|
import server from "./server.js";
|
||||||
|
|
||||||
async function render(note: FNote, $el: JQuery<HTMLElement>) {
|
async function render(note: FNote, $el: JQuery<HTMLElement>, onError?: (e: unknown) => void) {
|
||||||
const relations = note.getRelations("renderNote");
|
const relations = note.getRelations("renderNote");
|
||||||
const renderNoteIds = relations.map((rel) => rel.value).filter((noteId) => noteId);
|
const renderNoteIds = relations.map((rel) => rel.value).filter((noteId) => noteId);
|
||||||
|
|
||||||
@ -21,12 +21,14 @@ async function render(note: FNote, $el: JQuery<HTMLElement>) {
|
|||||||
$scriptContainer.append(bundle.html);
|
$scriptContainer.append(bundle.html);
|
||||||
|
|
||||||
// async so that scripts cannot block trilium execution
|
// async so that scripts cannot block trilium execution
|
||||||
bundleService.executeBundle(bundle, note, $scriptContainer).then(result => {
|
bundleService.executeBundle(bundle, note, $scriptContainer)
|
||||||
// Render JSX
|
.catch(onError)
|
||||||
if (bundle.html === "") {
|
.then(result => {
|
||||||
renderIfJsx(bundle, result, $el);
|
// Render JSX
|
||||||
}
|
if (bundle.html === "") {
|
||||||
});
|
renderIfJsx(bundle, result, $el).catch(onError);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return renderNoteIds.length > 0;
|
return renderNoteIds.length > 0;
|
||||||
|
|||||||
@ -1,8 +1,7 @@
|
|||||||
.note-detail-render {
|
.note-detail-render {
|
||||||
position: relative;
|
position: relative;
|
||||||
}
|
|
||||||
|
|
||||||
.note-detail-render .note-detail-render-help {
|
&>.admonition {
|
||||||
margin: 50px;
|
margin: 1em;
|
||||||
padding: 20px;
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
import "./Render.css";
|
import "./Render.css";
|
||||||
|
|
||||||
import { useEffect, useRef } from "preact/hooks";
|
import { useEffect, useRef, useState } from "preact/hooks";
|
||||||
|
|
||||||
import FNote from "../../entities/fnote";
|
import FNote from "../../entities/fnote";
|
||||||
import attributes from "../../services/attributes";
|
import attributes from "../../services/attributes";
|
||||||
@ -8,6 +8,8 @@ import { t } from "../../services/i18n";
|
|||||||
import note_create from "../../services/note_create";
|
import note_create from "../../services/note_create";
|
||||||
import render from "../../services/render";
|
import render from "../../services/render";
|
||||||
import toast from "../../services/toast";
|
import toast from "../../services/toast";
|
||||||
|
import { getErrorMessage } from "../../services/utils";
|
||||||
|
import Admonition from "../react/Admonition";
|
||||||
import Button, { SplitButton } from "../react/Button";
|
import Button, { SplitButton } from "../react/Button";
|
||||||
import FormGroup from "../react/FormGroup";
|
import FormGroup from "../react/FormGroup";
|
||||||
import { FormListItem } from "../react/FormList";
|
import { FormListItem } from "../react/FormList";
|
||||||
@ -47,10 +49,12 @@ export default function Render(props: TypeWidgetProps) {
|
|||||||
|
|
||||||
function RenderContent({ note, noteContext, ntxId }: TypeWidgetProps) {
|
function RenderContent({ note, noteContext, ntxId }: TypeWidgetProps) {
|
||||||
const contentRef = useRef<HTMLDivElement>(null);
|
const contentRef = useRef<HTMLDivElement>(null);
|
||||||
|
const [ error, setError ] = useState<unknown | null>(null);
|
||||||
|
|
||||||
function refresh() {
|
function refresh() {
|
||||||
if (!contentRef) return;
|
if (!contentRef) return;
|
||||||
render.render(note, refToJQuerySelector(contentRef));
|
setError(null);
|
||||||
|
render.render(note, refToJQuerySelector(contentRef), setError);
|
||||||
}
|
}
|
||||||
|
|
||||||
useEffect(refresh, [ note ]);
|
useEffect(refresh, [ note ]);
|
||||||
@ -80,7 +84,16 @@ function RenderContent({ note, noteContext, ntxId }: TypeWidgetProps) {
|
|||||||
resolve(refToJQuerySelector(contentRef));
|
resolve(refToJQuerySelector(contentRef));
|
||||||
});
|
});
|
||||||
|
|
||||||
return <div ref={contentRef} className="note-detail-render-content" />;
|
return (
|
||||||
|
<>
|
||||||
|
{error && (
|
||||||
|
<Admonition type="caution">
|
||||||
|
{getErrorMessage(error)}
|
||||||
|
</Admonition>
|
||||||
|
)}
|
||||||
|
<div ref={contentRef} className="note-detail-render-content" />
|
||||||
|
</>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function DisabledRender({ note }: TypeWidgetProps) {
|
function DisabledRender({ note }: TypeWidgetProps) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user