Skip to content

Build your personal knowledge base with Trilium Notes

Merge remote-tracking branch 'origin/main' into feature/pdfjs_sidebar_experiments

Elian Doran7182d32d9c54
diff --cc apps/client/src/widgets/type_widgets/File.tsx
index 1871b96c52,a26bb09874..0d5b038608
--- a/apps/client/src/widgets/type_widgets/File.tsx
+++ b/apps/client/src/widgets/type_widgets/File.tsx
@@@ -16,7 -16,7 +16,7 @@@ export default function FileTypeWidget(
if (blob?.content) {
return <TextPreview content={blob.content} />;
} else if (note.mime === "application/pdf") {
- return <PdfPreview blob={blob} note={note} componentId={parentComponent?.componentId} noteContext={noteContext} />;
- return <PdfPreview blob={blob} note={note} ntxId={noteContext?.ntxId} componentId={parentComponent?.componentId} />;
++ return noteContext && <PdfPreview blob={blob} note={note} componentId={parentComponent?.componentId} noteContext={noteContext} />;
} else if (note.mime.startsWith("video/")) {
return <VideoPreview note={note} />;
} else if (note.mime.startsWith("audio/")) {
diff --cc apps/client/src/widgets/type_widgets/file/Pdf.tsx
index 7b784865f5,1c4e245737..e46d64717a
--- a/apps/client/src/widgets/type_widgets/file/Pdf.tsx
+++ b/apps/client/src/widgets/type_widgets/file/Pdf.tsx
@@@ -1,7 -1,7 +1,8 @@@
import { RefObject } from "preact";
import { useCallback, useEffect, useRef } from "preact/hooks";
+ import appContext from "../../../components/app_context";
+import type NoteContext from "../../../components/note_context";
import FBlob from "../../../entities/fblob";
import FNote from "../../../entities/fnote";
import server from "../../../services/server";
@@@ -15,11 -15,11 +16,11 @@@ const VARIABLE_WHITELIST = new Set(
"main-text-color"
]);
-export default function PdfPreview({ note, blob, componentId, ntxId }: {
- note: FNote,
- blob: FBlob | null | undefined,
+export default function PdfPreview({ note, blob, componentId, noteContext }: {
- note: FNote,
- noteContext: NoteContext
- blob: FBlob | null | undefined,
++ note: FNote;
++ noteContext: NoteContext;
++ blob: FBlob | null | undefined;
componentId: string | undefined;
- ntxId: string | null | undefined;
}) {
const iframeRef = useRef<HTMLIFrameElement>(null);
const { onLoad } = useStyleInjection(iframeRef);
@@@ -150,12 -51,31 +151,31 @@@
}
}, [ blob ]);
+ // Trigger focus when iframe content is clicked (iframe focus doesn't bubble)
+ useEffect(() => {
+ const iframe = iframeRef.current;
+ if (!iframe) return;
+
+ const handleIframeClick = () => {
- if (ntxId) {
- appContext.tabManager.activateNoteContext(ntxId);
++ if (noteContext.ntxId) {
++ appContext.tabManager.activateNoteContext(noteContext.ntxId);
+ }
+ };
+
+ // Listen for clicks on the iframe's content window
+ const iframeDoc = iframe.contentWindow?.document;
+ if (iframeDoc) {
+ iframeDoc.addEventListener('click', handleIframeClick);
+ return () => iframeDoc.removeEventListener('click', handleIframeClick);
+ }
- }, [ iframeRef.current?.contentWindow, ntxId ]);
++ }, [ iframeRef.current?.contentWindow, noteContext ]);
return (historyConfig &&
<iframe
+ tabIndex={300}
ref={iframeRef}
class="pdf-preview"
- src={`pdfjs/web/viewer.html?file=../../api/notes/${note.noteId}/open&lang=${locale}`}
+ src={`pdfjs/web/viewer.html?file=../../api/notes/${note.noteId}/open&lang=${locale}&sidebar=${newLayout ? "0" : "1"}`}
onLoad={() => {
const win = iframeRef.current?.contentWindow;
if (win) {
diff --cc packages/pdfjs-viewer/src/custom.ts
index 4f7adbcd7f,da1fb68501..919a03d621
--- a/packages/pdfjs-viewer/src/custom.ts
+++ b/packages/pdfjs-viewer/src/custom.ts
@@@ -1,18 -1,7 +1,16 @@@
import interceptPersistence from "./persistence";
+import { extractAndSendToc, setupScrollToHeading, setupActiveHeadingTracking } from "./toc";
+import { setupPdfPages } from "./pages";
+import { setupPdfAttachments } from "./attachments";
+import { setupPdfLayers } from "./layers";
- const LOG_EVENT_BUS = false;
-
async function main() {
- interceptPersistence(getCustomAppOptions());
+ const urlParams = new URLSearchParams(window.location.search);
+ if (urlParams.get("sidebar") === "0") {
+ hideSidebar();
+ }
+
+ interceptPersistence(getCustomAppOptions(urlParams));
// Wait for the PDF viewer application to be available.
while (!window.PDFViewerApplication) {
@@@ -20,17 -9,8 +18,14 @@@
}
const app = window.PDFViewerApplication;
- if (LOG_EVENT_BUS) {
- patchEventBus();
- }
app.eventBus.on("documentloaded", () => {
manageSave();
+ extractAndSendToc();
+ setupScrollToHeading();
+ setupActiveHeadingTracking();
+ setupPdfPages();
+ setupPdfAttachments();
+ setupPdfLayers();
});
await app.initializedPromise;
};