diff --git a/services/web/frontend/js/features/pdf-preview/hooks/use-compile-triggers.js b/services/web/frontend/js/features/pdf-preview/hooks/use-compile-triggers.ts similarity index 86% rename from services/web/frontend/js/features/pdf-preview/hooks/use-compile-triggers.js rename to services/web/frontend/js/features/pdf-preview/hooks/use-compile-triggers.ts index f75e9ee2b4..4e46134ba8 100644 --- a/services/web/frontend/js/features/pdf-preview/hooks/use-compile-triggers.js +++ b/services/web/frontend/js/features/pdf-preview/hooks/use-compile-triggers.ts @@ -2,7 +2,9 @@ import { useCallback, useEffect } from 'react' import useEventListener from '../../../shared/hooks/use-event-listener' import useDetachAction from '../../../shared/hooks/use-detach-action' -export const startCompileKeypress = event => { +export const startCompileKeypress = ( + event: KeyboardEvent | React.KeyboardEvent +) => { if (event.shiftKey || event.altKey) { return false } @@ -30,9 +32,12 @@ export const startCompileKeypress = event => { } } -export default function useCompileTriggers(startCompile, setChangedAt) { +export default function useCompileTriggers( + startCompile: (...args: any[]) => void, + setChangedAt: (...args: any[]) => void +) { const handleKeyDown = useCallback( - event => { + (event: KeyboardEvent) => { if (startCompileKeypress(event)) { event.preventDefault() startCompile() diff --git a/services/web/frontend/js/features/pdf-preview/util/editor-files.js b/services/web/frontend/js/features/pdf-preview/util/editor-files.js deleted file mode 100644 index a2f40858e9..0000000000 --- a/services/web/frontend/js/features/pdf-preview/util/editor-files.js +++ /dev/null @@ -1,4 +0,0 @@ -const documentClassRe = /^[^%]*\\documentclass/ - -export const isMainFile = doc => - doc.split('\n').some(line => documentClassRe.test(line)) diff --git a/services/web/frontend/js/features/pdf-preview/util/editor-files.ts b/services/web/frontend/js/features/pdf-preview/util/editor-files.ts new file mode 100644 index 0000000000..63ed164647 --- /dev/null +++ b/services/web/frontend/js/features/pdf-preview/util/editor-files.ts @@ -0,0 +1,4 @@ +const documentClassRe = /^[^%]*\\documentclass/ + +export const isMainFile = (doc: string | undefined): boolean => + !!doc && doc.split('\n').some(line => documentClassRe.test(line)) diff --git a/services/web/frontend/js/features/pdf-preview/util/highlights.js b/services/web/frontend/js/features/pdf-preview/util/highlights.ts similarity index 91% rename from services/web/frontend/js/features/pdf-preview/util/highlights.js rename to services/web/frontend/js/features/pdf-preview/util/highlights.ts index 2fb204ac11..61ab54a463 100644 --- a/services/web/frontend/js/features/pdf-preview/util/highlights.js +++ b/services/web/frontend/js/features/pdf-preview/util/highlights.ts @@ -1,6 +1,11 @@ import { PDFJS } from '@/features/pdf-preview/util/pdf-js' +import { PDFViewer } from 'pdfjs-dist/web/pdf_viewer.mjs' +import { HighlightData } from './types' -export function buildHighlightElement(highlight, viewer) { +export function buildHighlightElement( + highlight: HighlightData, + viewer: PDFViewer +) { const { viewport, div } = viewer.getPageView(highlight.page - 1) // page coordinates from synctex diff --git a/services/web/frontend/js/features/pdf-preview/util/pdf-caching-flags.js b/services/web/frontend/js/features/pdf-preview/util/pdf-caching-flags.ts similarity index 79% rename from services/web/frontend/js/features/pdf-preview/util/pdf-caching-flags.js rename to services/web/frontend/js/features/pdf-preview/util/pdf-caching-flags.ts index fb2a5b12b2..b0d069aeb7 100644 --- a/services/web/frontend/js/features/pdf-preview/util/pdf-caching-flags.js +++ b/services/web/frontend/js/features/pdf-preview/util/pdf-caching-flags.ts @@ -7,13 +7,16 @@ if (!hasTextEncoder) { } const isOpera = - Array.isArray(navigator.userAgentData?.brands) && - navigator.userAgentData.brands.some(b => b.brand === 'Opera') + // userAgentData is experimental and not currently in the Navigator type + Array.isArray((navigator as any).userAgentData?.brands) && + (navigator as any).userAgentData.brands.some( + (b: { brand: string }) => b.brand === 'Opera' + ) if (isOpera) { debugConsole.warn('Browser cache is limited in Opera. Disabling pdf-caching.') } -function isFlagEnabled(flag) { +function isFlagEnabled(flag: string): boolean { if (!hasTextEncoder) return false if (isOpera) return false return getMeta('ol-splitTestVariants')?.[flag] === 'enabled' diff --git a/services/web/frontend/js/features/pdf-preview/util/types.ts b/services/web/frontend/js/features/pdf-preview/util/types.ts index 922db116a9..866b130be4 100644 --- a/services/web/frontend/js/features/pdf-preview/util/types.ts +++ b/services/web/frontend/js/features/pdf-preview/util/types.ts @@ -40,3 +40,11 @@ export type PdfFileDataList = { other: PdfFileData[] archive?: PdfFileArchiveData } + +export type HighlightData = { + page: number + h: number + v: number + width: number + height: number +} diff --git a/services/web/frontend/js/shared/context/local-compile-context.tsx b/services/web/frontend/js/shared/context/local-compile-context.tsx index 0e938aa881..59ce0e90d0 100644 --- a/services/web/frontend/js/shared/context/local-compile-context.tsx +++ b/services/web/frontend/js/shared/context/local-compile-context.tsx @@ -44,7 +44,11 @@ import { PdfScrollPosition, usePdfScrollPosition, } from '@/shared/hooks/use-pdf-scroll-position' -import { LogEntry, PdfFileDataList } from '@/features/pdf-preview/util/types' +import { + HighlightData, + LogEntry, + PdfFileDataList, +} from '@/features/pdf-preview/util/types' import { isSplitTestEnabled } from '@/utils/splitTestUtils' import { captureException } from '@/infrastructure/error-reporter' import OError from '@overleaf/o-error' @@ -65,7 +69,7 @@ export type CompileContext = { fileList?: PdfFileDataList hasChanges: boolean hasShortCompileTimeout: boolean - highlights?: Record[] + highlights?: HighlightData[] isProjectOwner: boolean logEntries?: { all: LogEntry[]