Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.
feat: add advanced excel viewer
Marc Seitz9115d8c817f4
diff --git a/components/view/dataroom/dataroom-view.tsx b/components/view/dataroom/dataroom-view.tsxindex 5a952b53..6bb287f6 100644--- a/components/view/dataroom/dataroom-view.tsx+++ b/components/view/dataroom/dataroom-view.tsx@@ -21,6 +21,7 @@ import { LinkWithDataroom } from "@/lib/types";import DataroomViewer from "../DataroomViewer";import PagesViewerNew from "../PagesViewerNew";import EmailVerificationMessage from "../email-verification-form";+import AdvancedExcelViewer from "../viewer/advanced-excel-viewer";const ExcelViewer = dynamic(() => import("@/components/view/viewer/excel-viewer"),@@ -63,6 +64,7 @@ export default function DataroomView({brand,token,verifiedEmail,+ useAdvancedExcelViewer,}: {link: LinkWithDataroom;userEmail: string | null | undefined;@@ -71,6 +73,7 @@ export default function DataroomView({brand?: Partial<DataroomBrand> | null;token?: string;verifiedEmail?: string;+ useAdvancedExcelViewer?: boolean;}) {const {linkType,@@ -125,6 +128,7 @@ export default function DataroomView({linkType: linkType,dataroomViewId: viewData.dataroomViewId ?? null,viewType: viewType,+ useAdvancedExcelViewer,}),});@@ -286,6 +290,21 @@ export default function DataroomView({setDocumentData={setDocumentData}/></div>+ ) : useAdvancedExcelViewer ? (+ <div className="bg-gray-950">+ <AdvancedExcelViewer+ linkId={link.id}+ viewId={viewData.viewId}+ documentId={documentData.id}+ documentName={documentData.name}+ versionNumber={documentData.documentVersionNumber}+ file={viewData.file!}+ allowDownload={link.allowDownload!}+ brand={brand}+ dataroomId={dataroom.id}+ setDocumentData={setDocumentData}+ />+ </div>) : viewData.pages ? (<div className="bg-gray-950"><PagesViewerNewdiff --git a/components/view/document-view.tsx b/components/view/document-view.tsxindex 7562bd93..5eb1785c 100644--- a/components/view/document-view.tsx+++ b/components/view/document-view.tsx@@ -46,6 +46,7 @@ export default function DocumentView({verifiedEmail,showPoweredByBanner,showAccountCreationSlide,+ useAdvancedExcelViewer,}: {link: LinkWithDocument;userEmail: string | null | undefined;@@ -60,6 +61,7 @@ export default function DocumentView({verifiedEmail?: string;showPoweredByBanner?: boolean;showAccountCreationSlide?: boolean;+ useAdvancedExcelViewer?: boolean;}) {const {document,@@ -103,6 +105,7 @@ export default function DocumentView({hasPages: document.versions[0].hasPages,token: token ?? null,verifiedEmail: verifiedEmail ?? null,+ useAdvancedExcelViewer,}),});@@ -223,6 +226,7 @@ export default function DocumentView({brand={brand}showPoweredByBanner={showPoweredByBanner}showAccountCreationSlide={showAccountCreationSlide}+ useAdvancedExcelViewer={useAdvancedExcelViewer}viewerEmail={data.email ?? verifiedEmail ?? userEmail ?? undefined}/>) : (diff --git a/components/view/view-data.tsx b/components/view/view-data.tsxindex df53b52b..8fefafae 100644--- a/components/view/view-data.tsx+++ b/components/view/view-data.tsx@@ -10,6 +10,8 @@ import { DEFAULT_DOCUMENT_VIEW_TYPE } from "@/components/view/document-view";import { LinkWithDocument } from "@/lib/types";+import AdvancedExcelViewer from "./viewer/advanced-excel-viewer";+const ExcelViewer = dynamic(() => import("@/components/view/viewer/excel-viewer"),{ ssr: false },@@ -22,6 +24,7 @@ export default function ViewData({brand,showPoweredByBanner,showAccountCreationSlide,+ useAdvancedExcelViewer,viewerEmail,}: {viewData: DEFAULT_DOCUMENT_VIEW_TYPE;@@ -33,6 +36,7 @@ export default function ViewData({brand?: Partial<Brand> | null;showPoweredByBanner?: boolean;showAccountCreationSlide?: boolean;+ useAdvancedExcelViewer?: boolean;viewerEmail?: string;}) {const { document } = link;@@ -57,6 +61,17 @@ export default function ViewData({sheetData={viewData.sheetData}brand={brand}/>+ ) : useAdvancedExcelViewer ? (+ <AdvancedExcelViewer+ linkId={link.id}+ viewId={viewData.viewId}+ documentId={document.id}+ documentName={document.name}+ versionNumber={document.versions[0].versionNumber}+ file={viewData.file!}+ allowDownload={link.allowDownload!}+ brand={brand}+ />) : viewData.pages ? (<PagesViewerNewpages={viewData.pages}diff --git a/components/view/viewer/advanced-excel-viewer.tsx b/components/view/viewer/advanced-excel-viewer.tsxnew file mode 100644index 00000000..c04cff6f--- /dev/null+++ b/components/view/viewer/advanced-excel-viewer.tsx@@ -0,0 +1,118 @@+import { useEffect, useRef, useState } from "react";++import { Brand, DataroomBrand } from "@prisma/client";++import { TDocumentData } from "../dataroom/dataroom-view";+import Nav from "../nav";++const trackPageView = async (data: {+ linkId: string;+ documentId: string;+ viewId: string;+ duration: number;+ pageNumber: number;+ versionNumber: number;+ dataroomId?: string;+}) => {+ await fetch("/api/record_view", {+ method: "POST",+ body: JSON.stringify(data),+ headers: {+ "Content-Type": "application/json",+ },+ });+};++export default function AdvancedExcelViewer({+ file,+ viewId,+ linkId,+ documentId,+ documentName,+ allowDownload,+ versionNumber,+ brand,+ dataroomId,+ setDocumentData,+}: {+ linkId: string;+ viewId: string;+ documentId: string;+ documentName: string;+ versionNumber: number;+ file: string;+ allowDownload: boolean;+ brand?: Partial<Brand> | Partial<DataroomBrand> | null;+ dataroomId?: string;+ setDocumentData?: React.Dispatch<React.SetStateAction<TDocumentData | null>>;+}) {+ const [pageNumber, setPageNumber] = useState<number>(1); // start on first page+ const [maxScrollPercentage, setMaxScrollPercentage] = useState<number>(0);++ const startTimeRef = useRef(Date.now());+ const pageNumberRef = useRef<number>(pageNumber);+ const visibilityRef = useRef<boolean>(true);++ useEffect(() => {+ const handleVisibilityChange = () => {+ if (document.visibilityState === "visible") {+ visibilityRef.current = true;+ startTimeRef.current = Date.now(); // Reset start time when page becomes visible+ } else {+ visibilityRef.current = false;+ const duration = Date.now() - startTimeRef.current;+ if (duration > 0) {+ trackPageView({+ linkId,+ documentId,+ viewId,+ duration,+ pageNumber,+ versionNumber,+ dataroomId,+ });+ }+ }+ };++ document.addEventListener("visibilitychange", handleVisibilityChange);++ return () => {+ if (visibilityRef.current) {+ const duration = Date.now() - startTimeRef.current;+ trackPageView({+ linkId,+ documentId,+ viewId,+ duration,+ pageNumber,+ versionNumber,+ dataroomId,+ }); // Also capture duration if component unmounts while visible+ }+ document.removeEventListener("visibilitychange", handleVisibilityChange);+ };+ }, []);++ return (+ <>+ <Nav+ brand={brand}+ documentName={documentName}+ isDataroom={dataroomId ? true : false}+ setDocumentData={setDocumentData}+ type="sheet"+ />+ <div+ style={{ height: "calc(100dvh - 64px)" }}+ className="mx-2 flex h-screen flex-col sm:mx-6 lg:mx-8"+ // ref={containerRef}+ >+ <iframe+ className="h-full w-full"+ src={`https://view.officeapps.live.com/op/embed.aspx?src=${file}&wdPrint=0`}+ ></iframe>+ </div>+ </>+ );+}diff --git a/pages/api/views-dataroom.ts b/pages/api/views-dataroom.tsindex be7ca437..70ea38ea 100644--- a/pages/api/views-dataroom.ts+++ b/pages/api/views-dataroom.ts@@ -67,6 +67,11 @@ export default async function handle(hasConfirmedAgreement?: boolean;};+ // INFO: for using the advanced excel viewer+ const { useAdvancedExcelViewer } = data as {+ useAdvancedExcelViewer: boolean;+ };+// Fetch the link to verify the settingsconst link = await prisma.link.findUnique({where: {@@ -418,7 +423,7 @@ export default async function handle(recordMap = await notion.getPage(pageId);}- if (documentVersion.type === "sheet") {+ if (documentVersion.type === "sheet" && !useAdvancedExcelViewer) {const fileUrl = await getFile({data: documentVersion.file,type: documentVersion.storageType,@@ -434,13 +439,16 @@ export default async function handle(message: "View recorded",viewId: newView.id,file:- documentVersion && documentVersion.type === "pdf"+ (documentVersion && documentVersion.type === "pdf") ||+ (documentVersion && useAdvancedExcelViewer)? documentVersion.file: undefined,pages: documentPages ? documentPages : undefined,notionData: recordMap ? { recordMap } : undefined,sheetData:- documentVersion && documentVersion.type === "sheet"+ documentVersion &&+ documentVersion.type === "sheet" &&+ !useAdvancedExcelViewer? sheetData: undefined,};diff --git a/pages/api/views.ts b/pages/api/views.tsindex f9da60f4..b47f5b7c 100644--- a/pages/api/views.ts+++ b/pages/api/views.ts@@ -55,6 +55,11 @@ export default async function handle(hasConfirmedAgreement?: boolean;};+ // INFO: for using the advanced excel viewer+ const { useAdvancedExcelViewer } = data as {+ useAdvancedExcelViewer: boolean;+ };+// Fetch the link to verify the settingsconst link = await prisma.link.findUnique({where: {@@ -300,7 +305,7 @@ export default async function handle(});}- if (documentVersion.type === "sheet") {+ if (documentVersion.type === "sheet" && !useAdvancedExcelViewer) {const fileUrl = await getFile({data: documentVersion.file,type: documentVersion.storageType,@@ -308,8 +313,6 @@ export default async function handle(const data = await parseSheet({ fileUrl });sheetData = data;- // columnData = data.columnData;- // rowData = data.rowData;}console.timeEnd("get-file");}@@ -324,12 +327,15 @@ export default async function handle(message: "View recorded",viewId: newView.id,file:- documentVersion && documentVersion.type === "pdf"+ (documentVersion && documentVersion.type === "pdf") ||+ (documentVersion && useAdvancedExcelViewer)? documentVersion.file: undefined,pages: documentPages ? documentPages : undefined,sheetData:- documentVersion && documentVersion.type === "sheet"+ documentVersion &&+ documentVersion.type === "sheet" &&+ !useAdvancedExcelViewer? sheetData: undefined,};diff --git a/pages/view/[linkId]/index.tsx b/pages/view/[linkId]/index.tsxindex ed1d232b..9b808090 100644--- a/pages/view/[linkId]/index.tsx+++ b/pages/view/[linkId]/index.tsx@@ -65,7 +65,7 @@ export const getStaticProps = async (context: GetStaticPropsContext) => {recordMap = await notion.getPage(pageId);}- const { team, ...linkDocument } = link.document;+ const { team, teamId, ...linkDocument } = link.document;const teamPlan = team?.plan || "free";return {@@ -94,6 +94,9 @@ export const getStaticProps = async (context: GetStaticPropsContext) => {},showPoweredByBanner: teamPlan === "free",showAccountCreationSlide: teamPlan === "free" || teamPlan === "pro",+ useAdvancedExcelViewer:+ teamId === "clwt1qwt00000qz39aqra71w6" ||+ teamId === "clup33by90000oewh4rfvp2eg",},revalidate: brand ? 10 : false,};@@ -117,6 +120,8 @@ export const getStaticProps = async (context: GetStaticPropsContext) => {documents.push(newDocument);}+ const { teamId } = link.dataroom;+return {props: {linkData: {@@ -140,6 +145,9 @@ export const getStaticProps = async (context: GetStaticPropsContext) => {},showPoweredByBanner: false,showAccountCreationSlide: false,+ useAdvancedExcelViewer:+ teamId === "clwt1qwt00000qz39aqra71w6" ||+ teamId === "clup33by90000oewh4rfvp2eg",},revalidate: 10,};@@ -163,6 +171,7 @@ export default function ViewPage({meta,showPoweredByBanner,showAccountCreationSlide,+ useAdvancedExcelViewer,}: {linkData: DocumentLinkData | DataroomLinkData;notionData: {@@ -178,6 +187,7 @@ export default function ViewPage({};showPoweredByBanner: boolean;showAccountCreationSlide: boolean;+ useAdvancedExcelViewer: boolean;}) {const router = useRouter();const { data: session, status } = useSession();@@ -268,6 +278,7 @@ export default function ViewPage({verifiedEmail={verifiedEmail}showPoweredByBanner={showPoweredByBanner}showAccountCreationSlide={showAccountCreationSlide}+ useAdvancedExcelViewer={useAdvancedExcelViewer}/></>);@@ -295,6 +306,7 @@ export default function ViewPage({brand={brand}showPoweredByBanner={showPoweredByBanner}showAccountCreationSlide={showAccountCreationSlide}+ useAdvancedExcelViewer={useAdvancedExcelViewer}/></>);@@ -369,6 +381,7 @@ export default function ViewPage({brand={brand}token={token}verifiedEmail={verifiedEmail}+ useAdvancedExcelViewer={useAdvancedExcelViewer}/></>);@@ -393,6 +406,7 @@ export default function ViewPage({userId={userId}isProtected={false}brand={brand}+ useAdvancedExcelViewer={useAdvancedExcelViewer}/></>);diff --git a/pages/view/domains/[domain]/[slug]/index.tsx b/pages/view/domains/[domain]/[slug]/index.tsxindex 3f4be0e5..216b509f 100644--- a/pages/view/domains/[domain]/[slug]/index.tsx+++ b/pages/view/domains/[domain]/[slug]/index.tsx@@ -70,7 +70,7 @@ export const getStaticProps = async (context: GetStaticPropsContext) => {recordMap = await notion.getPage(pageId);}- const { team, ...linkDocument } = link.document;+ const { team, teamId, ...linkDocument } = link.document;const teamPlan = team?.plan || "free";return {@@ -99,6 +99,9 @@ export const getStaticProps = async (context: GetStaticPropsContext) => {},showPoweredByBanner: teamPlan === "free",showAccountCreationSlide: teamPlan === "free" || teamPlan === "pro",+ useAdvancedExcelViewer:+ teamId === "clwt1qwt00000qz39aqra71w6" ||+ teamId === "clup33by90000oewh4rfvp2eg",},revalidate: 10,};@@ -122,6 +125,8 @@ export const getStaticProps = async (context: GetStaticPropsContext) => {documents.push(newDocument);}+ const { teamId } = link.dataroom;+return {props: {linkData: {@@ -145,6 +150,9 @@ export const getStaticProps = async (context: GetStaticPropsContext) => {},showPoweredByBanner: false,showAccountCreationSlide: false,+ useAdvancedExcelViewer:+ teamId === "clwt1qwt00000qz39aqra71w6" ||+ teamId === "clup33by90000oewh4rfvp2eg",},revalidate: 10,};@@ -167,6 +175,7 @@ export default function ViewPage({notionData,meta,showAccountCreationSlide,+ useAdvancedExcelViewer,}: {linkData: DocumentLinkData | DataroomLinkData;notionData: {@@ -181,6 +190,7 @@ export default function ViewPage({metaUrl: string | null;};showAccountCreationSlide: boolean;+ useAdvancedExcelViewer: boolean;}) {const router = useRouter();const { data: session, status } = useSession();@@ -269,6 +279,7 @@ export default function ViewPage({token={token}verifiedEmail={verifiedEmail}showAccountCreationSlide={showAccountCreationSlide}+ useAdvancedExcelViewer={useAdvancedExcelViewer}/></>);@@ -295,6 +306,7 @@ export default function ViewPage({notionData={notionData}brand={brand}showAccountCreationSlide={showAccountCreationSlide}+ useAdvancedExcelViewer={useAdvancedExcelViewer}/></>);@@ -369,6 +381,7 @@ export default function ViewPage({brand={brand}token={token}verifiedEmail={verifiedEmail}+ useAdvancedExcelViewer={useAdvancedExcelViewer}/></>);@@ -393,6 +406,7 @@ export default function ViewPage({userId={userId}isProtected={false}brand={brand}+ useAdvancedExcelViewer={useAdvancedExcelViewer}/></>);