Skip to content

Build your personal knowledge base with Trilium Notes

chore(pdfjs): fix typecheck issues

Elian Doran0ff4756ef49d
diff --git a/apps/client/src/types-pdfjs.d.ts b/apps/client/src/types-pdfjs.d.ts
index 54a440f162..13cb91f6e6 100644
--- a/apps/client/src/types-pdfjs.d.ts
+++ b/apps/client/src/types-pdfjs.d.ts
@@ -1,3 +1,15 @@
interface Window {
+ /**
+ * By default, pdf.js will try to store information about the opened PDFs such as zoom and scroll position in local storage.
+ * The Trilium alternative is to use attachments stored at note level.
+ * This variable represents the direct content used by the pdf.js viewer in its local storage key, but in plain JS object format.
+ * The variable must be set early at startup, before pdf.js fully initializes.
+ */
TRILIUM_VIEW_HISTORY_STORE?: object;
+
+ /**
+ * If set to true, hides the pdf.js viewer default sidebar containing the outline, page navigation, etc.
+ * This needs to be set early in the main method.
+ */
+ TRILIUM_HIDE_SIDEBAR?: boolean;
}
diff --git a/apps/client/src/widgets/note_types.tsx b/apps/client/src/widgets/note_types.tsx
index a6b3feb278..76142b7af1 100644
--- a/apps/client/src/widgets/note_types.tsx
+++ b/apps/client/src/widgets/note_types.tsx
@@ -4,7 +4,8 @@
*/
import { NoteType } from "@triliumnext/commons";
-import { VNode, type JSX } from "preact";
+import { type JSX,VNode } from "preact";
+
import { TypeWidgetProps } from "./type_widgets/type_widget";
/**
@@ -13,7 +14,7 @@ import { TypeWidgetProps } from "./type_widgets/type_widget";
*/
export type ExtendedNoteType = Exclude<NoteType, "launcher" | "text" | "code"> | "empty" | "readOnlyCode" | "readOnlyText" | "editableText" | "editableCode" | "attachmentDetail" | "attachmentList" | "protectedSession" | "aiChat";
-export type TypeWidget = ((props: TypeWidgetProps) => VNode | JSX.Element);
+export type TypeWidget = ((props: TypeWidgetProps) => VNode | JSX.Element | undefined);
type NoteTypeView = () => (Promise<{ default: TypeWidget } | TypeWidget> | TypeWidget);
interface NoteTypeMapping {
diff --git a/packages/pdfjs-viewer/src/pages.ts b/packages/pdfjs-viewer/src/pages.ts
index e63c234b94..67896e2567 100644
--- a/packages/pdfjs-viewer/src/pages.ts
+++ b/packages/pdfjs-viewer/src/pages.ts
@@ -64,7 +64,7 @@ async function generateThumbnail(pageNumber: number) {
// Render page to canvas
await page.render({
- canvasContext: context,
+ canvas: canvas,
viewport: viewport
}).promise;
diff --git a/packages/pdfjs-viewer/src/toc.ts b/packages/pdfjs-viewer/src/toc.ts
index eca3d7da83..ddc2db7075 100644
--- a/packages/pdfjs-viewer/src/toc.ts
+++ b/packages/pdfjs-viewer/src/toc.ts
@@ -126,7 +126,6 @@ export function setupActiveHeadingTracking() {
function updateActiveHeading() {
if (!headingPositions || headingPositions.length === 0) return;
- const currentPage = app.page - 1; // PDF.js uses 1-based, we need 0-based
const viewer = app.pdfViewer;
const container = viewer.container;
const scrollTop = container.scrollTop;
diff --git a/packages/pdfjs-viewer/src/typings.d.ts b/packages/pdfjs-viewer/src/typings.d.ts
index 9370df20a1..50ac44fc07 100644
--- a/packages/pdfjs-viewer/src/typings.d.ts
+++ b/packages/pdfjs-viewer/src/typings.d.ts
@@ -14,10 +14,32 @@ declare global {
_readFromStorage: () => Promise<string>;
}
+ interface PdfJsDestination {
+
+ }
+
interface Window {
PDFViewerApplication?: {
initializedPromise: Promise<void>;
pdfDocument: PDFDocumentProxy;
+ pdfViewer: {
+ currentPageNumber: number;
+ optionalContentConfigPromise: {
+ setVisibility(groupId: string, visible: boolean);
+ getGroup(groupId: string): {
+ name: string;
+ usage: {};
+ };
+ getOrder(): {}[]
+ };
+ getPageView(pageIndex: number): {
+ div: HTMLDivElement;
+ };
+ container: HTMLElement;
+ };
+ pdfLinkService: {
+ goToDestination(dest: PdfJsDestination);
+ };
eventBus: {
on(event: string, listener: (...args: any[]) => void): void;
dispatch(event: string, data?: any): void;