Skip to content

Build your personal knowledge base with Trilium Notes

feat(pdfjs): optionally hide left sidebar

Elian Doraneee8d9ab7c21
diff --git a/apps/client/src/widgets/type_widgets/file/Pdf.tsx b/apps/client/src/widgets/type_widgets/file/Pdf.tsx
index 638d5fb304..7b784865f5 100644
--- a/apps/client/src/widgets/type_widgets/file/Pdf.tsx
+++ b/apps/client/src/widgets/type_widgets/file/Pdf.tsx
@@ -6,7 +6,7 @@ import FBlob from "../../../entities/fblob";
import FNote from "../../../entities/fnote";
import server from "../../../services/server";
import { useViewModeConfig } from "../../collections/NoteList";
-import { useTriliumOption } from "../../react/hooks";
+import { useTriliumOption, useTriliumOptionBool } from "../../react/hooks";
const VARIABLE_WHITELIST = new Set([
"root-background",
@@ -25,6 +25,7 @@ export default function PdfPreview({ note, blob, componentId, noteContext }: {
const { onLoad } = useStyleInjection(iframeRef);
const historyConfig = useViewModeConfig(note, "pdfHistory");
const [ locale ] = useTriliumOption("locale");
+ const [ newLayout ] = useTriliumOptionBool("newLayout");
useEffect(() => {
function handleMessage(event: MessageEvent) {
@@ -154,7 +155,7 @@ export default function PdfPreview({ note, blob, componentId, noteContext }: {
<iframe
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 --git a/packages/pdfjs-viewer/src/custom.css b/packages/pdfjs-viewer/src/custom.css
index ac5b49035f..9e68e8eec3 100644
--- a/packages/pdfjs-viewer/src/custom.css
+++ b/packages/pdfjs-viewer/src/custom.css
@@ -12,3 +12,7 @@
box-shadow: 0 0 3px rgba(0, 0, 0, 0.2);
}
}
+
+#toolbarViewerLeft > .toolbarButtonSpacer:first-child {
+ display: none !important;
+}
diff --git a/packages/pdfjs-viewer/src/custom.ts b/packages/pdfjs-viewer/src/custom.ts
index 8dec7bcaf7..4f7adbcd7f 100644
--- a/packages/pdfjs-viewer/src/custom.ts
+++ b/packages/pdfjs-viewer/src/custom.ts
@@ -7,8 +7,12 @@ import { setupPdfLayers } from "./layers";
const LOG_EVENT_BUS = false;
async function main() {
- console.log("Hi");
- 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) {
@@ -31,14 +35,27 @@ async function main() {
await app.initializedPromise;
};
-function getCustomAppOptions() {
- const urlParams = new URLSearchParams(window.location.search);
+function hideSidebar() {
+ window.TRILIUM_HIDE_SIDEBAR = true;
+ const toggleButtonEl = document.getElementById("viewsManagerToggleButton");
+ if (toggleButtonEl) {
+ const spacer = toggleButtonEl.nextElementSibling.nextElementSibling;
+ if (spacer.classList.contains("toolbarButtonSpacer")) {
+ spacer.remove();
+ }
+ toggleButtonEl.remove();
+ }
+}
+function getCustomAppOptions(urlParams: URLSearchParams) {
return {
localeProperties: {
// Read from URL query
lang: urlParams.get("lang") || "en"
- }
+ },
+ // Control sidebar visibility via query parameter
+ // sidebarViewOnLoad: -1 disables sidebar, 0 = NONE (default)
+ viewsManager: null
};
}
diff --git a/packages/pdfjs-viewer/viewer/viewer.mjs b/packages/pdfjs-viewer/viewer/viewer.mjs
index d4186b8b90..078e855887 100644
--- a/packages/pdfjs-viewer/viewer/viewer.mjs
+++ b/packages/pdfjs-viewer/viewer/viewer.mjs
@@ -18609,7 +18609,7 @@ function getViewerConfiguration() {
imageAltTextSettingsSeparator: document.getElementById("imageAltTextSettingsSeparator"),
documentPropertiesButton: document.getElementById("documentProperties")
},
- viewsManager: {
+ viewsManager: window.TRILIUM_HIDE_SIDEBAR ? null : {
outerContainer: document.getElementById("outerContainer"),
toggleButton: document.getElementById("viewsManagerToggleButton"),
sidebarContainer: document.getElementById("viewsManager"),