@osdk/react-components 0.56.0 → 0.57.0-main-e5dd4c9c26091761a0ff1ff5252089c6cf4072b3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +13 -0
- package/build/browser/pdf-viewer/BasePdfViewer.js +12 -8
- package/build/browser/pdf-viewer/BasePdfViewer.js.map +1 -1
- package/build/browser/pdf-viewer/PdfViewerApi.js.map +1 -1
- package/build/browser/pdf-viewer/PdfViewerContext.js +4 -0
- package/build/browser/pdf-viewer/PdfViewerContext.js.map +1 -1
- package/build/browser/pdf-viewer/components/PdfViewerContent.js +6 -2
- package/build/browser/pdf-viewer/components/PdfViewerContent.js.map +1 -1
- package/build/browser/pdf-viewer/hooks/usePdfViewerCore.js +10 -4
- package/build/browser/pdf-viewer/hooks/usePdfViewerCore.js.map +1 -1
- package/build/browser/pdf-viewer/hooks/usePdfViewerState.js +9 -1
- package/build/browser/pdf-viewer/hooks/usePdfViewerState.js.map +1 -1
- package/build/browser/util/UserAgent.js +1 -1
- package/build/browser/util/UserAgent.js.map +1 -1
- package/build/cjs/{PdfViewerApi-CQJlwPUl.d.cts → PdfViewerApi-CIpvxxUo.d.cts} +9 -1
- package/build/cjs/{chunk-2UJNMXVL.cjs → chunk-32L4XMOU.cjs} +4 -4
- package/build/cjs/{chunk-2UJNMXVL.cjs.map → chunk-32L4XMOU.cjs.map} +1 -1
- package/build/cjs/{chunk-HVJTECCC.cjs → chunk-4KHF42ZL.cjs} +34 -15
- package/build/cjs/chunk-4KHF42ZL.cjs.map +1 -0
- package/build/cjs/{chunk-DJNKQI5C.cjs → chunk-5BW22VWH.cjs} +34 -26
- package/build/cjs/chunk-5BW22VWH.cjs.map +1 -0
- package/build/cjs/{chunk-ABT6IGXN.cjs → chunk-BDZLTKGG.cjs} +4 -4
- package/build/cjs/{chunk-ABT6IGXN.cjs.map → chunk-BDZLTKGG.cjs.map} +1 -1
- package/build/cjs/{chunk-6RCVPIW5.cjs → chunk-E27ABWSC.cjs} +3 -3
- package/build/cjs/chunk-E27ABWSC.cjs.map +1 -0
- package/build/cjs/{chunk-JHKAQXRZ.cjs → chunk-G62RSQCU.cjs} +4 -4
- package/build/cjs/{chunk-JHKAQXRZ.cjs.map → chunk-G62RSQCU.cjs.map} +1 -1
- package/build/cjs/{chunk-RDJK72SG.cjs → chunk-GVSFXLNN.cjs} +4 -4
- package/build/cjs/{chunk-RDJK72SG.cjs.map → chunk-GVSFXLNN.cjs.map} +1 -1
- package/build/cjs/chunk-HB6AK5XA.cjs +11 -0
- package/build/cjs/{chunk-CR5S7BJM.cjs.map → chunk-HB6AK5XA.cjs.map} +1 -1
- package/build/cjs/chunk-IJEO6F4B.cjs +11 -0
- package/build/cjs/{chunk-S4DLEUUJ.cjs.map → chunk-IJEO6F4B.cjs.map} +1 -1
- package/build/cjs/{chunk-ULVTAKJF.cjs → chunk-J5BWCMBP.cjs} +4 -4
- package/build/cjs/{chunk-ULVTAKJF.cjs.map → chunk-J5BWCMBP.cjs.map} +1 -1
- package/build/cjs/chunk-JOWWFTI2.cjs +11 -0
- package/build/cjs/{chunk-A5ZKDZH4.cjs.map → chunk-JOWWFTI2.cjs.map} +1 -1
- package/build/cjs/{chunk-L2FCT7HW.cjs → chunk-OXMB7BD3.cjs} +4 -4
- package/build/cjs/{chunk-L2FCT7HW.cjs.map → chunk-OXMB7BD3.cjs.map} +1 -1
- package/build/cjs/chunk-PONH7AXA.cjs +11 -0
- package/build/cjs/{chunk-4F5VJN66.cjs.map → chunk-PONH7AXA.cjs.map} +1 -1
- package/build/cjs/{chunk-JDKKKXMF.cjs → chunk-XPL7E6G7.cjs} +4 -4
- package/build/cjs/{chunk-JDKKKXMF.cjs.map → chunk-XPL7E6G7.cjs.map} +1 -1
- package/build/cjs/{chunk-BBXX42YT.cjs → chunk-ZPGUMGAH.cjs} +7 -7
- package/build/cjs/{chunk-BBXX42YT.cjs.map → chunk-ZPGUMGAH.cjs.map} +1 -1
- package/build/cjs/public/experimental/action-form.cjs +4 -4
- package/build/cjs/public/experimental/cbac-picker.cjs +11 -11
- package/build/cjs/public/experimental/document-viewer.cjs +5 -5
- package/build/cjs/public/experimental/document-viewer.d.cts +1 -1
- package/build/cjs/public/experimental/email-viewer.cjs +3 -3
- package/build/cjs/public/experimental/filter-list.cjs +15 -15
- package/build/cjs/public/experimental/image-viewer.cjs +3 -3
- package/build/cjs/public/experimental/markdown-renderer.cjs +5 -5
- package/build/cjs/public/experimental/object-table.cjs +22 -22
- package/build/cjs/public/experimental/pdf-viewer.cjs +25 -25
- package/build/cjs/public/experimental/pdf-viewer.d.cts +17 -5
- package/build/cjs/public/experimental/spreadsheet-viewer.cjs +3 -3
- package/build/cjs/public/experimental/tiff-renderer.cjs +5 -5
- package/build/cjs/public/experimental/video-viewer.cjs +3 -3
- package/build/cjs/public/experimental/xml-viewer.cjs +3 -3
- package/build/cjs/public/experimental.cjs +94 -94
- package/build/cjs/public/experimental.d.cts +1 -1
- package/build/esm/pdf-viewer/BasePdfViewer.js +12 -8
- package/build/esm/pdf-viewer/BasePdfViewer.js.map +1 -1
- package/build/esm/pdf-viewer/PdfViewerApi.js.map +1 -1
- package/build/esm/pdf-viewer/PdfViewerContext.js +4 -0
- package/build/esm/pdf-viewer/PdfViewerContext.js.map +1 -1
- package/build/esm/pdf-viewer/components/PdfViewerContent.js +6 -2
- package/build/esm/pdf-viewer/components/PdfViewerContent.js.map +1 -1
- package/build/esm/pdf-viewer/hooks/usePdfViewerCore.js +10 -4
- package/build/esm/pdf-viewer/hooks/usePdfViewerCore.js.map +1 -1
- package/build/esm/pdf-viewer/hooks/usePdfViewerState.js +9 -1
- package/build/esm/pdf-viewer/hooks/usePdfViewerState.js.map +1 -1
- package/build/esm/util/UserAgent.js +1 -1
- package/build/esm/util/UserAgent.js.map +1 -1
- package/build/types/pdf-viewer/PdfViewerApi.d.ts +9 -1
- package/build/types/pdf-viewer/PdfViewerApi.d.ts.map +1 -1
- package/build/types/pdf-viewer/components/PdfViewerContent.d.ts +5 -1
- package/build/types/pdf-viewer/components/PdfViewerContent.d.ts.map +1 -1
- package/build/types/pdf-viewer/hooks/usePdfViewerCore.d.ts +7 -1
- package/build/types/pdf-viewer/hooks/usePdfViewerCore.d.ts.map +1 -1
- package/build/types/pdf-viewer/hooks/usePdfViewerState.d.ts +3 -1
- package/build/types/pdf-viewer/hooks/usePdfViewerState.d.ts.map +1 -1
- package/docs/DocumentViewer.md +1 -1
- package/docs/DocumentViewerOverview.md +1 -1
- package/docs/PdfViewer.md +9 -9
- package/package.json +8 -8
- package/build/cjs/chunk-4F5VJN66.cjs +0 -11
- package/build/cjs/chunk-6RCVPIW5.cjs.map +0 -1
- package/build/cjs/chunk-A5ZKDZH4.cjs +0 -11
- package/build/cjs/chunk-CR5S7BJM.cjs +0 -11
- package/build/cjs/chunk-DJNKQI5C.cjs.map +0 -1
- package/build/cjs/chunk-HVJTECCC.cjs.map +0 -1
- package/build/cjs/chunk-S4DLEUUJ.cjs +0 -11
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# @osdk/react-components
|
|
2
2
|
|
|
3
|
+
## 0.57.0-main-e5dd4c9c26091761a0ff1ff5252089c6cf4072b3
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- e5dd4c9: Add `defaultPage`, `defaultScale`, `defaultAutoSize`, and `defaultSidebarOpen` to the PDF viewer APIs. The corresponding `initial*` props remain supported as deprecated aliases.
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [b1bb84a]
|
|
12
|
+
- @osdk/client@2.64.1-main-e5dd4c9c26091761a0ff1ff5252089c6cf4072b3
|
|
13
|
+
- @osdk/api@2.64.1-main-e5dd4c9c26091761a0ff1ff5252089c6cf4072b3
|
|
14
|
+
- @osdk/react@2.64.1-main-e5dd4c9c26091761a0ff1ff5252089c6cf4072b3
|
|
15
|
+
|
|
3
16
|
## 0.56.0
|
|
4
17
|
|
|
5
18
|
### Minor Changes
|
|
@@ -40,10 +40,14 @@ export const BasePdfViewer = /*#__PURE__*/forwardRef(function ({
|
|
|
40
40
|
formData,
|
|
41
41
|
onFormSubmit,
|
|
42
42
|
onFormChange,
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
43
|
+
defaultPage,
|
|
44
|
+
initialPage,
|
|
45
|
+
defaultScale,
|
|
46
|
+
initialScale,
|
|
47
|
+
defaultAutoSize,
|
|
48
|
+
initialAutoSize,
|
|
49
|
+
defaultSidebarOpen,
|
|
50
|
+
initialSidebarOpen,
|
|
47
51
|
enableDownload = false,
|
|
48
52
|
downloadFileName,
|
|
49
53
|
sidebarMode: sidebarModeProp = "thumbnails",
|
|
@@ -52,10 +56,10 @@ export const BasePdfViewer = /*#__PURE__*/forwardRef(function ({
|
|
|
52
56
|
}, ref) {
|
|
53
57
|
const viewer = usePdfViewerState({
|
|
54
58
|
src,
|
|
55
|
-
initialPage,
|
|
56
|
-
initialScale,
|
|
57
|
-
initialAutoSize,
|
|
58
|
-
initialSidebarOpen,
|
|
59
|
+
defaultPage: defaultPage ?? initialPage,
|
|
60
|
+
defaultScale: defaultScale ?? initialScale,
|
|
61
|
+
defaultAutoSize: defaultAutoSize ?? initialAutoSize,
|
|
62
|
+
defaultSidebarOpen: defaultSidebarOpen ?? initialSidebarOpen,
|
|
59
63
|
sidebarMode: sidebarModeProp,
|
|
60
64
|
onDownload
|
|
61
65
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BasePdfViewer.js","names":["Error","ErrorIcon","Spin","classnames","React","forwardRef","useCallback","useImperativeHandle","PdfAnnotationOverlay","PdfViewerOutlineSidebar","PdfViewerSearchBar","PdfViewerSidebar","PdfViewerToolbar","EMPTY_ANNOTATION_ARRAY","usePdfAnnotationsByPage","usePdfFormFields","usePdfHighlightMode","usePdfViewerState","styles","BasePdfViewer","src","annotations","onAnnotationClick","onDownload","enableHighlight","onTextHighlight","onHighlightDelete","formData","onFormSubmit","onFormChange","initialPage","initialScale","initialAutoSize","initialSidebarOpen","enableDownload","downloadFileName","sidebarMode","sidebarModeProp","outlineIcons","className","ref","viewer","highlightModeActive","toggleHighlightMode","deleteHighlight","pdfViewerRef","document","enabled","scrollToPage","hasFormFields","submitFormData","eventBusRef","annotationsByPage","handleDownload","download","rootClassName","pdfViewer","loading","createElement","loadingContainer","spinnerIcon","error","errorContainer","errorIcon","message","currentPage","numPages","scale","autoSize","sidebarOpen","onPageChange","onZoomIn","zoomIn","onZoomOut","zoomOut","onAutoSizeToggle","toggleAutoSize","onSearchOpen","search","openSearch","onSidebarToggle","toggleSidebar","onRotateLeft","rotateLeft","onRotateRight","rotateRight","onHighlightToggle","enableFormSave","onFormSave","isSearchOpen","query","totalMatches","currentMatchIndex","onQueryChange","setQuery","onNext","nextMatch","onPrev","prevMatch","onClose","closeSearch","contentArea","onPageClick","onSidebarModeChange","setSidebarMode","outlineItems","onItemClick","scrollContainerWrapper","containerRef","scrollContainer","viewerRef","portalTargets","map","target","pageAnnotations","pageNumber","length","key"],"sources":["BasePdfViewer.tsx"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { Error as ErrorIcon, Spin } from \"@blueprintjs/icons\";\nimport classnames from \"classnames\";\n\nimport \"pdfjs-dist/web/pdf_viewer.css\";\nimport React, { forwardRef, useCallback, useImperativeHandle } from \"react\";\n\nimport { PdfAnnotationOverlay } from \"./components/PdfAnnotationOverlay.js\";\nimport { PdfViewerOutlineSidebar } from \"./components/PdfViewerOutlineSidebar.js\";\nimport { PdfViewerSearchBar } from \"./components/PdfViewerSearchBar.js\";\nimport { PdfViewerSidebar } from \"./components/PdfViewerSidebar.js\";\nimport { PdfViewerToolbar } from \"./components/PdfViewerToolbar.js\";\nimport { EMPTY_ANNOTATION_ARRAY } from \"./constants.js\";\nimport { usePdfAnnotationsByPage } from \"./hooks/usePdfAnnotationsByPage.js\";\nimport { usePdfFormFields } from \"./hooks/usePdfFormFields.js\";\nimport { usePdfHighlightMode } from \"./hooks/usePdfHighlightMode.js\";\nimport { usePdfViewerState } from \"./hooks/usePdfViewerState.js\";\nimport type { BasePdfViewerProps, PdfViewerHandle } from \"./PdfViewerApi.js\";\n\nimport styles from \"./BasePdfViewer.module.css\";\n\nexport const BasePdfViewer: React.ForwardRefExoticComponent<\n BasePdfViewerProps & React.RefAttributes<PdfViewerHandle>\n> = forwardRef<PdfViewerHandle, BasePdfViewerProps>(function BasePdfViewer(\n {\n src,\n annotations = EMPTY_ANNOTATION_ARRAY,\n onAnnotationClick,\n onDownload,\n enableHighlight = false,\n onTextHighlight,\n onHighlightDelete,\n formData,\n onFormSubmit,\n onFormChange,\n initialPage = 1,\n initialScale = 1.0,\n initialAutoSize = false,\n initialSidebarOpen = false,\n enableDownload = false,\n downloadFileName,\n sidebarMode: sidebarModeProp = \"thumbnails\",\n outlineIcons,\n className,\n },\n ref,\n) {\n const viewer = usePdfViewerState({\n src,\n initialPage,\n initialScale,\n initialAutoSize,\n initialSidebarOpen,\n sidebarMode: sidebarModeProp,\n onDownload,\n });\n\n const { highlightModeActive, toggleHighlightMode, deleteHighlight } =\n usePdfHighlightMode({\n pdfViewerRef: viewer.pdfViewerRef,\n document: viewer.document,\n enabled: enableHighlight,\n onTextHighlight,\n onHighlightDelete,\n });\n\n useImperativeHandle(\n ref,\n () => ({\n scrollToPage: viewer.scrollToPage,\n deleteHighlight,\n }),\n [viewer.scrollToPage, deleteHighlight],\n );\n\n const { hasFormFields, submitFormData } = usePdfFormFields({\n pdfViewerRef: viewer.pdfViewerRef,\n eventBusRef: viewer.eventBusRef,\n document: viewer.document,\n formData,\n onFormSubmit,\n onFormChange,\n });\n\n const annotationsByPage = usePdfAnnotationsByPage(annotations);\n\n const handleDownload = useCallback(() => {\n viewer.download(downloadFileName);\n }, [viewer, downloadFileName]);\n\n const rootClassName = classnames(styles.pdfViewer, className);\n\n if (viewer.loading) {\n return (\n <div className={rootClassName}>\n <div className={styles.loadingContainer}>\n <Spin className={styles.spinnerIcon} />\n Loading…\n </div>\n </div>\n );\n }\n\n if (viewer.error != null) {\n return (\n <div className={rootClassName}>\n <div className={styles.errorContainer}>\n <ErrorIcon className={styles.errorIcon} />\n Failed to load PDF: {viewer.error.message}\n </div>\n </div>\n );\n }\n\n if (viewer.document == null) {\n return (\n <div className={rootClassName}>\n <div className={styles.loadingContainer}>No document</div>\n </div>\n );\n }\n\n return (\n <div className={rootClassName}>\n <PdfViewerToolbar\n currentPage={viewer.currentPage}\n numPages={viewer.numPages}\n scale={viewer.scale}\n autoSize={viewer.autoSize}\n sidebarOpen={viewer.sidebarOpen}\n onPageChange={viewer.scrollToPage}\n onZoomIn={viewer.zoomIn}\n onZoomOut={viewer.zoomOut}\n onAutoSizeToggle={viewer.toggleAutoSize}\n onSearchOpen={viewer.search.openSearch}\n onSidebarToggle={viewer.toggleSidebar}\n onDownload={handleDownload}\n enableDownload={enableDownload}\n onRotateLeft={viewer.rotateLeft}\n onRotateRight={viewer.rotateRight}\n enableHighlight={enableHighlight}\n highlightModeActive={highlightModeActive}\n onHighlightToggle={toggleHighlightMode}\n enableFormSave={onFormSubmit != null && hasFormFields}\n onFormSave={submitFormData}\n />\n {viewer.search.isSearchOpen && (\n <PdfViewerSearchBar\n query={viewer.search.query}\n totalMatches={viewer.search.totalMatches}\n currentMatchIndex={viewer.search.currentMatchIndex}\n onQueryChange={viewer.search.setQuery}\n onNext={viewer.search.nextMatch}\n onPrev={viewer.search.prevMatch}\n onClose={viewer.search.closeSearch}\n />\n )}\n <div className={styles.contentArea}>\n {viewer.sidebarOpen && viewer.sidebarMode === \"thumbnails\" && (\n <PdfViewerSidebar\n document={viewer.document}\n numPages={viewer.numPages}\n currentPage={viewer.currentPage}\n onPageClick={viewer.scrollToPage}\n sidebarMode={viewer.sidebarMode}\n onSidebarModeChange={viewer.setSidebarMode}\n />\n )}\n {viewer.sidebarOpen && viewer.sidebarMode === \"outline\" && (\n <PdfViewerOutlineSidebar\n outlineItems={viewer.outlineItems}\n currentPage={viewer.currentPage}\n onItemClick={viewer.scrollToPage}\n sidebarMode={viewer.sidebarMode}\n onSidebarModeChange={viewer.setSidebarMode}\n outlineIcons={outlineIcons}\n />\n )}\n <div className={styles.scrollContainerWrapper}>\n <div ref={viewer.containerRef} className={styles.scrollContainer}>\n <div ref={viewer.viewerRef} className=\"pdfViewer\" />\n {viewer.portalTargets.map((target) => {\n const pageAnnotations =\n annotationsByPage[target.pageNumber] ?? EMPTY_ANNOTATION_ARRAY;\n if (pageAnnotations.length === 0) {\n return null;\n }\n return (\n <PdfAnnotationOverlay\n key={target.pageNumber}\n target={target}\n annotations={pageAnnotations}\n onAnnotationClick={onAnnotationClick}\n />\n );\n })}\n </div>\n </div>\n </div>\n </div>\n );\n});\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAASA,KAAK,IAAIC,SAAS,EAAEC,IAAI,QAAQ,oBAAoB;AAC7D,OAAOC,UAAU,MAAM,YAAY;AAEnC,OAAO,+BAA+B;AACtC,OAAOC,KAAK,IAAIC,UAAU,EAAEC,WAAW,EAAEC,mBAAmB,QAAQ,OAAO;AAE3E,SAASC,oBAAoB,QAAQ,sCAAsC;AAC3E,SAASC,uBAAuB,QAAQ,yCAAyC;AACjF,SAASC,kBAAkB,QAAQ,oCAAoC;AACvE,SAASC,gBAAgB,QAAQ,kCAAkC;AACnE,SAASC,gBAAgB,QAAQ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AAA;IAAKlB,GAAG,EAAEC,MAAM,CAACmE,YAAa;IAACrE,SAAS,EAAErB,MAAM,CAAC2F;EAAgB,gBAC/DzG,KAAA,CAAAsD,aAAA;IAAKlB,GAAG,EAAEC,MAAM,CAACqE,SAAU;IAACvE,SAAS,EAAC;EAAW,CAAE,CAAC,EACnDE,MAAM,CAACsE,aAAa,CAACC,GAAG,CAAEC,MAAM,IAAK;IACpC,MAAMC,eAAe,GACnB9D,iBAAiB,CAAC6D,MAAM,CAACE,UAAU,CAAC,IAAItG,sBAAsB;IAChE,IAAIqG,eAAe,CAACE,MAAM,KAAK,CAAC,EAAE;MAChC,OAAO,IAAI;IACb;IACA,oBACEhH,KAAA,CAAAsD,aAAA,CAAClD,oBAAoB;MACnB6G,GAAG,EAAEJ,MAAM,CAACE,UAAW;MACvBF,MAAM,EAAEA,MAAO;MACf5F,WAAW,EAAE6F,eAAgB;MAC7B5F,iBAAiB,EAAEA;IAAkB,CACtC,CAAC;EAEN,CAAC,CACE,CACF,CACF,CACF,CAAC;AAEV,CAAC,CAAC","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"BasePdfViewer.js","names":["Error","ErrorIcon","Spin","classnames","React","forwardRef","useCallback","useImperativeHandle","PdfAnnotationOverlay","PdfViewerOutlineSidebar","PdfViewerSearchBar","PdfViewerSidebar","PdfViewerToolbar","EMPTY_ANNOTATION_ARRAY","usePdfAnnotationsByPage","usePdfFormFields","usePdfHighlightMode","usePdfViewerState","styles","BasePdfViewer","src","annotations","onAnnotationClick","onDownload","enableHighlight","onTextHighlight","onHighlightDelete","formData","onFormSubmit","onFormChange","defaultPage","initialPage","defaultScale","initialScale","defaultAutoSize","initialAutoSize","defaultSidebarOpen","initialSidebarOpen","enableDownload","downloadFileName","sidebarMode","sidebarModeProp","outlineIcons","className","ref","viewer","highlightModeActive","toggleHighlightMode","deleteHighlight","pdfViewerRef","document","enabled","scrollToPage","hasFormFields","submitFormData","eventBusRef","annotationsByPage","handleDownload","download","rootClassName","pdfViewer","loading","createElement","loadingContainer","spinnerIcon","error","errorContainer","errorIcon","message","currentPage","numPages","scale","autoSize","sidebarOpen","onPageChange","onZoomIn","zoomIn","onZoomOut","zoomOut","onAutoSizeToggle","toggleAutoSize","onSearchOpen","search","openSearch","onSidebarToggle","toggleSidebar","onRotateLeft","rotateLeft","onRotateRight","rotateRight","onHighlightToggle","enableFormSave","onFormSave","isSearchOpen","query","totalMatches","currentMatchIndex","onQueryChange","setQuery","onNext","nextMatch","onPrev","prevMatch","onClose","closeSearch","contentArea","onPageClick","onSidebarModeChange","setSidebarMode","outlineItems","onItemClick","scrollContainerWrapper","containerRef","scrollContainer","viewerRef","portalTargets","map","target","pageAnnotations","pageNumber","length","key"],"sources":["BasePdfViewer.tsx"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { Error as ErrorIcon, Spin } from \"@blueprintjs/icons\";\nimport classnames from \"classnames\";\n\nimport \"pdfjs-dist/web/pdf_viewer.css\";\nimport React, { forwardRef, useCallback, useImperativeHandle } from \"react\";\n\nimport { PdfAnnotationOverlay } from \"./components/PdfAnnotationOverlay.js\";\nimport { PdfViewerOutlineSidebar } from \"./components/PdfViewerOutlineSidebar.js\";\nimport { PdfViewerSearchBar } from \"./components/PdfViewerSearchBar.js\";\nimport { PdfViewerSidebar } from \"./components/PdfViewerSidebar.js\";\nimport { PdfViewerToolbar } from \"./components/PdfViewerToolbar.js\";\nimport { EMPTY_ANNOTATION_ARRAY } from \"./constants.js\";\nimport { usePdfAnnotationsByPage } from \"./hooks/usePdfAnnotationsByPage.js\";\nimport { usePdfFormFields } from \"./hooks/usePdfFormFields.js\";\nimport { usePdfHighlightMode } from \"./hooks/usePdfHighlightMode.js\";\nimport { usePdfViewerState } from \"./hooks/usePdfViewerState.js\";\nimport type { BasePdfViewerProps, PdfViewerHandle } from \"./PdfViewerApi.js\";\n\nimport styles from \"./BasePdfViewer.module.css\";\n\nexport const BasePdfViewer: React.ForwardRefExoticComponent<\n BasePdfViewerProps & React.RefAttributes<PdfViewerHandle>\n> = forwardRef<PdfViewerHandle, BasePdfViewerProps>(function BasePdfViewer(\n {\n src,\n annotations = EMPTY_ANNOTATION_ARRAY,\n onAnnotationClick,\n onDownload,\n enableHighlight = false,\n onTextHighlight,\n onHighlightDelete,\n formData,\n onFormSubmit,\n onFormChange,\n defaultPage,\n initialPage,\n defaultScale,\n initialScale,\n defaultAutoSize,\n initialAutoSize,\n defaultSidebarOpen,\n initialSidebarOpen,\n enableDownload = false,\n downloadFileName,\n sidebarMode: sidebarModeProp = \"thumbnails\",\n outlineIcons,\n className,\n },\n ref,\n) {\n const viewer = usePdfViewerState({\n src,\n defaultPage: defaultPage ?? initialPage,\n defaultScale: defaultScale ?? initialScale,\n defaultAutoSize: defaultAutoSize ?? initialAutoSize,\n defaultSidebarOpen: defaultSidebarOpen ?? initialSidebarOpen,\n sidebarMode: sidebarModeProp,\n onDownload,\n });\n\n const { highlightModeActive, toggleHighlightMode, deleteHighlight } =\n usePdfHighlightMode({\n pdfViewerRef: viewer.pdfViewerRef,\n document: viewer.document,\n enabled: enableHighlight,\n onTextHighlight,\n onHighlightDelete,\n });\n\n useImperativeHandle(\n ref,\n () => ({\n scrollToPage: viewer.scrollToPage,\n deleteHighlight,\n }),\n [viewer.scrollToPage, deleteHighlight],\n );\n\n const { hasFormFields, submitFormData } = usePdfFormFields({\n pdfViewerRef: viewer.pdfViewerRef,\n eventBusRef: viewer.eventBusRef,\n document: viewer.document,\n formData,\n onFormSubmit,\n onFormChange,\n });\n\n const annotationsByPage = usePdfAnnotationsByPage(annotations);\n\n const handleDownload = useCallback(() => {\n viewer.download(downloadFileName);\n }, [viewer, downloadFileName]);\n\n const rootClassName = classnames(styles.pdfViewer, className);\n\n if (viewer.loading) {\n return (\n <div className={rootClassName}>\n <div className={styles.loadingContainer}>\n <Spin className={styles.spinnerIcon} />\n Loading…\n </div>\n </div>\n );\n }\n\n if (viewer.error != null) {\n return (\n <div className={rootClassName}>\n <div className={styles.errorContainer}>\n <ErrorIcon className={styles.errorIcon} />\n Failed to load PDF: {viewer.error.message}\n </div>\n </div>\n );\n }\n\n if (viewer.document == null) {\n return (\n <div className={rootClassName}>\n <div className={styles.loadingContainer}>No document</div>\n </div>\n );\n }\n\n return (\n <div className={rootClassName}>\n <PdfViewerToolbar\n currentPage={viewer.currentPage}\n numPages={viewer.numPages}\n scale={viewer.scale}\n autoSize={viewer.autoSize}\n sidebarOpen={viewer.sidebarOpen}\n onPageChange={viewer.scrollToPage}\n onZoomIn={viewer.zoomIn}\n onZoomOut={viewer.zoomOut}\n onAutoSizeToggle={viewer.toggleAutoSize}\n onSearchOpen={viewer.search.openSearch}\n onSidebarToggle={viewer.toggleSidebar}\n onDownload={handleDownload}\n enableDownload={enableDownload}\n onRotateLeft={viewer.rotateLeft}\n onRotateRight={viewer.rotateRight}\n enableHighlight={enableHighlight}\n highlightModeActive={highlightModeActive}\n onHighlightToggle={toggleHighlightMode}\n enableFormSave={onFormSubmit != null && hasFormFields}\n onFormSave={submitFormData}\n />\n {viewer.search.isSearchOpen && (\n <PdfViewerSearchBar\n query={viewer.search.query}\n totalMatches={viewer.search.totalMatches}\n currentMatchIndex={viewer.search.currentMatchIndex}\n onQueryChange={viewer.search.setQuery}\n onNext={viewer.search.nextMatch}\n onPrev={viewer.search.prevMatch}\n onClose={viewer.search.closeSearch}\n />\n )}\n <div className={styles.contentArea}>\n {viewer.sidebarOpen && viewer.sidebarMode === \"thumbnails\" && (\n <PdfViewerSidebar\n document={viewer.document}\n numPages={viewer.numPages}\n currentPage={viewer.currentPage}\n onPageClick={viewer.scrollToPage}\n sidebarMode={viewer.sidebarMode}\n onSidebarModeChange={viewer.setSidebarMode}\n />\n )}\n {viewer.sidebarOpen && viewer.sidebarMode === \"outline\" && (\n <PdfViewerOutlineSidebar\n outlineItems={viewer.outlineItems}\n currentPage={viewer.currentPage}\n onItemClick={viewer.scrollToPage}\n sidebarMode={viewer.sidebarMode}\n onSidebarModeChange={viewer.setSidebarMode}\n outlineIcons={outlineIcons}\n />\n )}\n <div className={styles.scrollContainerWrapper}>\n <div ref={viewer.containerRef} className={styles.scrollContainer}>\n <div ref={viewer.viewerRef} className=\"pdfViewer\" />\n {viewer.portalTargets.map((target) => {\n const pageAnnotations =\n annotationsByPage[target.pageNumber] ?? EMPTY_ANNOTATION_ARRAY;\n if (pageAnnotations.length === 0) {\n return null;\n }\n return (\n <PdfAnnotationOverlay\n key={target.pageNumber}\n target={target}\n annotations={pageAnnotations}\n onAnnotationClick={onAnnotationClick}\n />\n );\n })}\n </div>\n </div>\n </div>\n </div>\n );\n});\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAASA,KAAK,IAAIC,SAAS,EAAEC,IAAI,QAAQ,oBAAoB;AAC7D,OAAOC,UAAU,MAAM,YAAY;AAEnC,OAAO,+BAA+B;AACtC,OAAOC,KAAK,IAAIC,UAAU,EAAEC,WAAW,EAAEC,mBAAmB,QAAQ,OAAO;AAE3E,SAASC,oBAAoB,QAAQ,sCAAsC;AAC3E,SAASC,uBAAuB,QAAQ,yCAAyC;AACjF,SAASC,kBAAkB,QAAQ,oCAAoC;AACvE,SAASC,gBAAgB,QAAQ,kCAAkC;AACnE,SAASC,gBAAgB,QAAQ,kCAAkC;AACnE,SAASC,sBAAsB,QAAQ,gBAAgB;AACvD,SAASC,uBAAuB,QAAQ,oCAAoC;AAC5E,SAASC,gBAAgB,QAAQ,6BAA6B;AAC9D,SAASC,m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IAAKlB,GAAG,EAAEC,MAAM,CAACmE,YAAa;IAACrE,SAAS,EAAEzB,MAAM,CAAC+F;EAAgB,gBAC/D7G,KAAA,CAAA0D,aAAA;IAAKlB,GAAG,EAAEC,MAAM,CAACqE,SAAU;IAACvE,SAAS,EAAC;EAAW,CAAE,CAAC,EACnDE,MAAM,CAACsE,aAAa,CAACC,GAAG,CAAEC,MAAM,IAAK;IACpC,MAAMC,eAAe,GACnB9D,iBAAiB,CAAC6D,MAAM,CAACE,UAAU,CAAC,IAAI1G,sBAAsB;IAChE,IAAIyG,eAAe,CAACE,MAAM,KAAK,CAAC,EAAE;MAChC,OAAO,IAAI;IACb;IACA,oBACEpH,KAAA,CAAA0D,aAAA,CAACtD,oBAAoB;MACnBiH,GAAG,EAAEJ,MAAM,CAACE,UAAW;MACvBF,MAAM,EAAEA,MAAO;MACfhG,WAAW,EAAEiG,eAAgB;MAC7BhG,iBAAiB,EAAEA;IAAkB,CACtC,CAAC;EAEN,CAAC,CACE,CACF,CACF,CACF,CAAC;AAEV,CAAC,CAAC","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PdfViewerApi.js","names":[],"sources":["PdfViewerApi.ts"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { Media } from \"@osdk/api\";\nimport type React from \"react\";\n\n/** Which sidebar panel to display when the sidebar is open. */\nexport type SidebarMode = \"thumbnails\" | \"outline\";\n\n/** A single item in the PDF document outline (table of contents). */\nexport interface OutlineItem {\n title: string;\n depth: number;\n pageNumber: number;\n bold: boolean;\n italic: boolean;\n}\n\n/** The visual style of an annotation rendered on the PDF. */\nexport type AnnotationType =\n | \"highlight\"\n | \"underline\"\n | \"comment\"\n | \"pin\"\n | \"custom\";\n\n/** A rectangle in PDF coordinate space (origin: bottom-left of page). */\nexport interface PdfRect {\n x: number;\n y: number;\n width: number;\n height: number;\n}\n\n/** Props passed to a custom annotation renderer. */\nexport interface PdfAnnotationRenderProps {\n annotation: PdfAnnotation;\n scale: number;\n pageHeight: number;\n transform: number[];\n}\n\n/** Common fields shared by all annotation types. */\ninterface PdfAnnotationBase {\n /** Unique identifier for this annotation */\n id: string;\n /** Page number (1-indexed) */\n page: number;\n /** Coordinates in PDF points (origin: bottom-left of page) */\n rect: PdfRect;\n /** Additional rects for multi-line text highlights. When present, all rects are rendered. */\n rects?: PdfRect[];\n /** Optional label or tooltip text */\n label?: string;\n /** Optional color override (CSS color string) */\n color?: string;\n}\n\n/** A built-in annotation type (highlight, underline, comment, pin). */\ninterface PdfStandardAnnotation extends PdfAnnotationBase {\n /** The type of annotation to render */\n type: \"highlight\" | \"underline\" | \"comment\" | \"pin\";\n}\n\n/** A custom annotation with a user-provided renderer. */\nexport interface PdfCustomAnnotation extends PdfAnnotationBase {\n /** Must be \"custom\" for custom-rendered annotations */\n type: \"custom\";\n /** Render function for the custom annotation content (required for custom type) */\n render: (props: PdfAnnotationRenderProps) => React.ReactNode;\n}\n\n/** A single annotation positioned on a specific page of the PDF. */\nexport type PdfAnnotation = PdfStandardAnnotation | PdfCustomAnnotation;\n\n/** Result passed to the {@link BasePdfViewerProps.onDownload} callback. */\nexport type PdfDownloadResult =\n | { success: true; filename: string }\n | { success: false; error: Error };\n\n/** Possible values for a PDF form field. */\nexport type PdfFormFieldValue = string | boolean | string[];\n\n/** Data emitted when the user creates a text highlight via the highlight editor. */\nexport interface PdfTextHighlightEvent {\n /** Internal PDF.js editor ID. Use with `deleteHighlight` to programmatically remove. */\n editorId: string;\n /** Page number (1-indexed) */\n page: number;\n /** Bounding rects in PDF coordinate space (bottom-left origin) */\n rects: PdfRect[];\n /** The selected text content */\n selectedText: string;\n /** Highlight color as CSS color string */\n color: string;\n}\n\n/** Imperative handle for programmatic control of a {@link PdfViewer} or {@link BasePdfViewer}. */\nexport interface PdfViewerHandle {\n /** Scroll the viewer to the given page number (1-indexed). */\n scrollToPage: (page: number) => void;\n /** Programmatically delete a highlight by its `editorId` (from {@link PdfTextHighlightEvent}). */\n deleteHighlight: (editorId: string) => void;\n}\n\n/**\n * Options for {@link usePdfViewerInstance}.\n *\n * Derived from {@link BasePdfViewerProps} rather than restated, so the two\n * cannot drift. `className` is excluded as a rendering concern, and\n * `downloadFileName` because the hooks tier does not render the toolbar that\n * would use it.\n */\nexport type PdfViewerInstanceOptions = Omit<\n BasePdfViewerProps,\n \"className\" | \"downloadFileName\"\n> & {\n /**\n * Whether the highlight toggle button is shown in the toolbar.\n * @deprecated Use `enableHighlight` instead, which matches\n * {@link BasePdfViewerProps}. Ignored when `enableHighlight` is set.\n */\n highlightEnabled?: boolean;\n};\n\n/**\n * PDF source input.\n *\n * - `string` — a URL the PDF is fetched from\n * - `ArrayBuffer` / `Uint8Array` — raw PDF bytes already in memory (a Node\n * `Buffer` satisfies `Uint8Array` and is accepted as-is)\n * - `Blob` — read into an `ArrayBuffer` before rendering\n */\nexport type PdfSource = string | ArrayBuffer | Uint8Array | Blob;\n\n/** Props for the {@link BasePdfViewer} component. */\nexport interface BasePdfViewerProps {\n /** PDF source — URL string, ArrayBuffer, Uint8Array, or Blob */\n src: PdfSource;\n /** Annotations to overlay on the PDF */\n annotations?: PdfAnnotation[];\n /**\n * Callback fired when an annotation is clicked.\n *\n * @param annotation - The annotation that was clicked\n * @returns void\n */\n onAnnotationClick?: (annotation: PdfAnnotation) => void;\n /**\n * Callback fired when a download completes or fails.\n *\n * @param result - The download result indicating success with the filename, or failure with an error\n * @returns void\n */\n onDownload?: (result: PdfDownloadResult) => void;\n /**\n * Whether the highlight toggle button is shown in the toolbar.\n * @default false\n */\n enableHighlight?: boolean;\n /**\n * Callback fired when the user creates a text highlight.\n * Only fires when highlight mode is active.\n *\n * @param event - The highlight event with page, rects, text, and color\n * @returns void\n */\n onTextHighlight?: (event: PdfTextHighlightEvent) => void;\n /**\n * Callback fired when the user deletes a highlight via the PDF.js editor UI.\n *\n * @param event - The highlight event that was deleted\n * @returns void\n */\n onHighlightDelete?: (event: PdfTextHighlightEvent) => void;\n /** Initial page number (1-indexed, default 1) */\n initialPage?: number;\n /** Initial zoom scale (default 1.0) */\n initialScale?: number;\n /**\n * Whether auto-size (fit to width) is initially enabled.\n * When enabled, the PDF scales to fit the container width and\n * re-fits automatically on resize. Manual zoom disables auto-size.\n * Takes precedence over {@link
|
|
1
|
+
{"version":3,"file":"PdfViewerApi.js","names":[],"sources":["PdfViewerApi.ts"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { Media } from \"@osdk/api\";\nimport type React from \"react\";\n\n/** Which sidebar panel to display when the sidebar is open. */\nexport type SidebarMode = \"thumbnails\" | \"outline\";\n\n/** A single item in the PDF document outline (table of contents). */\nexport interface OutlineItem {\n title: string;\n depth: number;\n pageNumber: number;\n bold: boolean;\n italic: boolean;\n}\n\n/** The visual style of an annotation rendered on the PDF. */\nexport type AnnotationType =\n | \"highlight\"\n | \"underline\"\n | \"comment\"\n | \"pin\"\n | \"custom\";\n\n/** A rectangle in PDF coordinate space (origin: bottom-left of page). */\nexport interface PdfRect {\n x: number;\n y: number;\n width: number;\n height: number;\n}\n\n/** Props passed to a custom annotation renderer. */\nexport interface PdfAnnotationRenderProps {\n annotation: PdfAnnotation;\n scale: number;\n pageHeight: number;\n transform: number[];\n}\n\n/** Common fields shared by all annotation types. */\ninterface PdfAnnotationBase {\n /** Unique identifier for this annotation */\n id: string;\n /** Page number (1-indexed) */\n page: number;\n /** Coordinates in PDF points (origin: bottom-left of page) */\n rect: PdfRect;\n /** Additional rects for multi-line text highlights. When present, all rects are rendered. */\n rects?: PdfRect[];\n /** Optional label or tooltip text */\n label?: string;\n /** Optional color override (CSS color string) */\n color?: string;\n}\n\n/** A built-in annotation type (highlight, underline, comment, pin). */\ninterface PdfStandardAnnotation extends PdfAnnotationBase {\n /** The type of annotation to render */\n type: \"highlight\" | \"underline\" | \"comment\" | \"pin\";\n}\n\n/** A custom annotation with a user-provided renderer. */\nexport interface PdfCustomAnnotation extends PdfAnnotationBase {\n /** Must be \"custom\" for custom-rendered annotations */\n type: \"custom\";\n /** Render function for the custom annotation content (required for custom type) */\n render: (props: PdfAnnotationRenderProps) => React.ReactNode;\n}\n\n/** A single annotation positioned on a specific page of the PDF. */\nexport type PdfAnnotation = PdfStandardAnnotation | PdfCustomAnnotation;\n\n/** Result passed to the {@link BasePdfViewerProps.onDownload} callback. */\nexport type PdfDownloadResult =\n | { success: true; filename: string }\n | { success: false; error: Error };\n\n/** Possible values for a PDF form field. */\nexport type PdfFormFieldValue = string | boolean | string[];\n\n/** Data emitted when the user creates a text highlight via the highlight editor. */\nexport interface PdfTextHighlightEvent {\n /** Internal PDF.js editor ID. Use with `deleteHighlight` to programmatically remove. */\n editorId: string;\n /** Page number (1-indexed) */\n page: number;\n /** Bounding rects in PDF coordinate space (bottom-left origin) */\n rects: PdfRect[];\n /** The selected text content */\n selectedText: string;\n /** Highlight color as CSS color string */\n color: string;\n}\n\n/** Imperative handle for programmatic control of a {@link PdfViewer} or {@link BasePdfViewer}. */\nexport interface PdfViewerHandle {\n /** Scroll the viewer to the given page number (1-indexed). */\n scrollToPage: (page: number) => void;\n /** Programmatically delete a highlight by its `editorId` (from {@link PdfTextHighlightEvent}). */\n deleteHighlight: (editorId: string) => void;\n}\n\n/**\n * Options for {@link usePdfViewerInstance}.\n *\n * Derived from {@link BasePdfViewerProps} rather than restated, so the two\n * cannot drift. `className` is excluded as a rendering concern, and\n * `downloadFileName` because the hooks tier does not render the toolbar that\n * would use it.\n */\nexport type PdfViewerInstanceOptions = Omit<\n BasePdfViewerProps,\n \"className\" | \"downloadFileName\"\n> & {\n /**\n * Whether the highlight toggle button is shown in the toolbar.\n * @deprecated Use `enableHighlight` instead, which matches\n * {@link BasePdfViewerProps}. Ignored when `enableHighlight` is set.\n */\n highlightEnabled?: boolean;\n};\n\n/**\n * PDF source input.\n *\n * - `string` — a URL the PDF is fetched from\n * - `ArrayBuffer` / `Uint8Array` — raw PDF bytes already in memory (a Node\n * `Buffer` satisfies `Uint8Array` and is accepted as-is)\n * - `Blob` — read into an `ArrayBuffer` before rendering\n */\nexport type PdfSource = string | ArrayBuffer | Uint8Array | Blob;\n\n/** Props for the {@link BasePdfViewer} component. */\nexport interface BasePdfViewerProps {\n /** PDF source — URL string, ArrayBuffer, Uint8Array, or Blob */\n src: PdfSource;\n /** Annotations to overlay on the PDF */\n annotations?: PdfAnnotation[];\n /**\n * Callback fired when an annotation is clicked.\n *\n * @param annotation - The annotation that was clicked\n * @returns void\n */\n onAnnotationClick?: (annotation: PdfAnnotation) => void;\n /**\n * Callback fired when a download completes or fails.\n *\n * @param result - The download result indicating success with the filename, or failure with an error\n * @returns void\n */\n onDownload?: (result: PdfDownloadResult) => void;\n /**\n * Whether the highlight toggle button is shown in the toolbar.\n * @default false\n */\n enableHighlight?: boolean;\n /**\n * Callback fired when the user creates a text highlight.\n * Only fires when highlight mode is active.\n *\n * @param event - The highlight event with page, rects, text, and color\n * @returns void\n */\n onTextHighlight?: (event: PdfTextHighlightEvent) => void;\n /**\n * Callback fired when the user deletes a highlight via the PDF.js editor UI.\n *\n * @param event - The highlight event that was deleted\n * @returns void\n */\n onHighlightDelete?: (event: PdfTextHighlightEvent) => void;\n /** Initial page number (1-indexed, default 1) */\n defaultPage?: number;\n /** @deprecated Rename to `defaultPage`. */\n initialPage?: number;\n /** Initial zoom scale (default 1.0) */\n defaultScale?: number;\n /** @deprecated Rename to `defaultScale`. */\n initialScale?: number;\n /**\n * Whether auto-size (fit to width) is initially enabled.\n * When enabled, the PDF scales to fit the container width and\n * re-fits automatically on resize. Manual zoom disables auto-size.\n * Takes precedence over {@link defaultScale} when enabled.\n * @default false\n */\n defaultAutoSize?: boolean;\n /** @deprecated Rename to `defaultAutoSize`. */\n initialAutoSize?: boolean;\n /** Whether the sidebar is initially open (default false) */\n defaultSidebarOpen?: boolean;\n /** @deprecated Rename to `defaultSidebarOpen`. */\n initialSidebarOpen?: boolean;\n /**\n * Whether the download button is shown in the toolbar.\n * @default false\n */\n enableDownload?: boolean;\n /**\n * Filename used when the user downloads the PDF via the toolbar button.\n * If omitted, the name is derived from the `src` URL, falling back to \"document.pdf\".\n */\n downloadFileName?: string;\n /**\n * Which sidebar panel to show: thumbnails or document outline.\n * @default \"thumbnails\"\n */\n sidebarMode?: SidebarMode;\n /**\n * Custom icon components for each outline depth level (0-indexed).\n * Key 0 = top-level items, 1 = first nesting level, etc.\n * If omitted, no icons are rendered.\n */\n outlineIcons?: Partial<Record<number, React.ComponentType>>;\n /**\n * Initial form field values keyed by field name. Applied when the document loads.\n * Use this to pre-populate form fields when resuming a previously edited PDF.\n */\n formData?: Record<string, PdfFormFieldValue>;\n /**\n * Callback fired when the user clicks the save button in the toolbar.\n * Receives all current form field values keyed by field name.\n *\n * @param data - All form field values keyed by field name\n * @returns void\n */\n onFormSubmit?: (data: Record<string, PdfFormFieldValue>) => void;\n /**\n * Callback fired when any form field value changes.\n *\n * @param fieldName - The name of the field that changed\n * @param value - The new value\n * @returns void\n */\n onFormChange?: (fieldName: string, value: PdfFormFieldValue) => void;\n /** Additional CSS class name for the root element */\n className?: string;\n}\n\n/** Props for the {@link PdfViewer} component. */\nexport interface PdfViewerProps extends Omit<BasePdfViewerProps, \"src\"> {\n /** The Media object to fetch PDF contents from */\n media: Media;\n}\n"],"mappings":"","ignoreList":[]}
|
|
@@ -54,9 +54,13 @@ export function usePdfViewerContext() {
|
|
|
54
54
|
export function usePdfViewerInstance(options) {
|
|
55
55
|
const viewer = usePdfViewerState({
|
|
56
56
|
src: options.src,
|
|
57
|
+
defaultPage: options.defaultPage,
|
|
57
58
|
initialPage: options.initialPage,
|
|
59
|
+
defaultScale: options.defaultScale,
|
|
58
60
|
initialScale: options.initialScale,
|
|
61
|
+
defaultAutoSize: options.defaultAutoSize,
|
|
59
62
|
initialAutoSize: options.initialAutoSize,
|
|
63
|
+
defaultSidebarOpen: options.defaultSidebarOpen,
|
|
60
64
|
initialSidebarOpen: options.initialSidebarOpen,
|
|
61
65
|
sidebarMode: options.sidebarMode,
|
|
62
66
|
onDownload: options.onDownload
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PdfViewerContext.js","names":["React","createContext","useContext","useMemo","EMPTY_ANNOTATION_ARRAY","usePdfAnnotationsByPage","usePdfFormFields","usePdfHighlightMode","usePdfViewerState","PdfViewerContext","PdfViewerProvider","value","children","createElement","Provider","usePdfViewerContext","ctx","Error","usePdfViewerInstance","options","viewer","src","initialPage","initialScale","initialAutoSize","initialSidebarOpen","sidebarMode","onDownload","highlightModeActive","toggleHighlightMode","pdfViewerRef","document","enabled","enableHighlight","highlightEnabled","onTextHighlight","onHighlightDelete","hasFormFields","submitFormData","eventBusRef","formData","onFormSubmit","onFormChange","annotations","annotationsByPage","enableDownload","enableFormSave","onAnnotationClick","outlineIcons"],"sources":["PdfViewerContext.tsx"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { PDFDocumentProxy } from \"pdfjs-dist\";\nimport type {\n EventBus,\n PDFFindController,\n PDFViewer,\n} from \"pdfjs-dist/web/pdf_viewer.mjs\";\nimport React, { createContext, useContext, useMemo } from \"react\";\nimport type { RefObject } from \"react\";\n\nimport { EMPTY_ANNOTATION_ARRAY } from \"./constants.js\";\nimport type { AnnotationPortalTarget } from \"./hooks/usePdfAnnotationPortals.js\";\nimport { usePdfAnnotationsByPage } from \"./hooks/usePdfAnnotationsByPage.js\";\nimport { usePdfFormFields } from \"./hooks/usePdfFormFields.js\";\nimport { usePdfHighlightMode } from \"./hooks/usePdfHighlightMode.js\";\nimport type { UsePdfViewerSearchResult } from \"./hooks/usePdfViewerSearch.js\";\nimport { usePdfViewerState } from \"./hooks/usePdfViewerState.js\";\nimport type {\n OutlineItem,\n PdfAnnotation,\n PdfViewerInstanceOptions,\n SidebarMode,\n} from \"./PdfViewerApi.js\";\n\n/** The shape of the value provided by {@link PdfViewerProvider}. */\nexport interface PdfViewerContextValue {\n // From UsePdfViewerStateResult (core + state)\n document: PDFDocumentProxy | undefined;\n numPages: number;\n loading: boolean;\n error: Error | undefined;\n containerRef: RefObject<HTMLDivElement>;\n viewerRef: RefObject<HTMLDivElement>;\n currentPage: number;\n scrollToPage: (page: number) => void;\n scale: number;\n setScale: (scale: number) => void;\n autoSize: boolean;\n setAutoSize: (autoSize: boolean) => void;\n zoomIn: () => void;\n zoomOut: () => void;\n toggleAutoSize: () => void;\n rotation: number;\n rotateLeft: () => void;\n rotateRight: () => void;\n sidebarOpen: boolean;\n sidebarMode: SidebarMode;\n setSidebarMode: (mode: SidebarMode) => void;\n toggleSidebar: () => void;\n search: UsePdfViewerSearchResult;\n outlineItems: OutlineItem[];\n download: (filename?: string) => void;\n portalTargets: AnnotationPortalTarget[];\n\n // From UsePdfHighlightModeResult\n highlightEnabled: boolean;\n highlightModeActive: boolean;\n toggleHighlightMode: () => void;\n\n // From UsePdfFormFieldsResult\n hasFormFields: boolean;\n submitFormData: () => void;\n\n // Annotations\n annotations: PdfAnnotation[];\n annotationsByPage: Record<number, PdfAnnotation[]>;\n onAnnotationClick: ((annotation: PdfAnnotation) => void) | undefined;\n\n // Config props passed through\n enableDownload: boolean;\n enableFormSave: boolean;\n outlineIcons: Partial<Record<number, React.ComponentType>> | undefined;\n\n // Internal refs (for advanced consumers)\n pdfViewerRef: RefObject<PDFViewer | null>;\n eventBusRef: RefObject<EventBus | null>;\n findControllerRef: RefObject<PDFFindController | null>;\n}\n\nconst PdfViewerContext = createContext<PdfViewerContextValue | null>(null);\n\nexport interface PdfViewerProviderProps {\n value: PdfViewerContextValue;\n children: React.ReactNode;\n}\n\n/** Provides {@link PdfViewerContextValue} to descendant components. */\nexport function PdfViewerProvider({\n value,\n children,\n}: PdfViewerProviderProps): React.ReactElement {\n return (\n <PdfViewerContext.Provider value={value}>\n {children}\n </PdfViewerContext.Provider>\n );\n}\n\n/**\n * Returns the nearest {@link PdfViewerContextValue} from a {@link PdfViewerProvider}.\n * Throws if called outside a provider.\n */\nexport function usePdfViewerContext(): PdfViewerContextValue {\n const ctx = useContext(PdfViewerContext);\n if (ctx == null) {\n throw new Error(\n \"usePdfViewerContext must be used within a PdfViewerProvider\",\n );\n }\n return ctx;\n}\n\n/**\n * Consumer-facing setup hook analogous to react-hook-form's `useForm()`.\n * Accepts viewer options and returns a {@link PdfViewerContextValue} suitable\n * for passing to {@link PdfViewerProvider}.\n */\nexport function usePdfViewerInstance(\n options: PdfViewerInstanceOptions,\n): PdfViewerContextValue {\n const viewer = usePdfViewerState({\n src: options.src,\n initialPage: options.initialPage,\n initialScale: options.initialScale,\n initialAutoSize: options.initialAutoSize,\n initialSidebarOpen: options.initialSidebarOpen,\n sidebarMode: options.sidebarMode,\n onDownload: options.onDownload,\n });\n\n const { highlightModeActive, toggleHighlightMode } = usePdfHighlightMode({\n pdfViewerRef: viewer.pdfViewerRef,\n document: viewer.document,\n enabled: options.enableHighlight ?? options.highlightEnabled ?? false,\n onTextHighlight: options.onTextHighlight,\n onHighlightDelete: options.onHighlightDelete,\n });\n\n const { hasFormFields, submitFormData } = usePdfFormFields({\n pdfViewerRef: viewer.pdfViewerRef,\n eventBusRef: viewer.eventBusRef,\n document: viewer.document,\n formData: options.formData,\n onFormSubmit: options.onFormSubmit,\n onFormChange: options.onFormChange,\n });\n\n const annotations = options.annotations ?? EMPTY_ANNOTATION_ARRAY;\n const annotationsByPage = usePdfAnnotationsByPage(annotations);\n\n // `highlightEnabled` is the deprecated spelling of `enableHighlight`.\n const highlightEnabled =\n options.enableHighlight ?? options.highlightEnabled ?? false;\n const enableDownload = options.enableDownload ?? false;\n const enableFormSave = options.onFormSubmit != null && hasFormFields;\n const { onAnnotationClick, outlineIcons } = options;\n\n return useMemo(\n () => ({\n ...viewer,\n highlightEnabled,\n highlightModeActive,\n toggleHighlightMode,\n hasFormFields,\n submitFormData,\n annotations,\n annotationsByPage,\n onAnnotationClick,\n enableDownload,\n enableFormSave,\n outlineIcons,\n }),\n [\n viewer,\n highlightEnabled,\n highlightModeActive,\n toggleHighlightMode,\n hasFormFields,\n submitFormData,\n annotations,\n annotationsByPage,\n onAnnotationClick,\n enableDownload,\n enableFormSave,\n outlineIcons,\n ],\n );\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAQA,OAAOA,KAAK,IAAIC,aAAa,EAAEC,UAAU,EAAEC,OAAO,QAAQ,OAAO;AAGjE,SAASC,sBAAsB,QAAQ,gBAAgB;AAEvD,SAASC,uBAAuB,QAAQ,oCAAoC;AAC5E,SAASC,gBAAgB,QAAQ,6BAA6B;AAC9D,SAASC,mBAAmB,QAAQ,gCAAgC;AAEpE,SAASC,iBAAiB,QAAQ,8BAA8B;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,aAAa;IAAEC;EAAe,CAAC,GAAGhC,gBAAgB,CAAC;IACzDwB,YAAY,EAAEV,MAAM,CAACU,YAAY;IACjCS,WAAW,EAAEnB,MAAM,CAACmB,WAAW;IAC/BR,QAAQ,EAAEX,MAAM,CAACW,QAAQ;IACzBS,QAAQ,EAAErB,OAAO,CAACqB,QAAQ;IAC1BC,YAAY,EAAEtB,OAAO,CAACsB,YAAY;IAClCC,YAAY,EAAEvB,OAAO,CAACuB;EACxB,CAAC,CAAC;EAEF,MAAMC,WAAW,GAAGxB,OAAO,CAACwB,WAAW,IAAIvC,sBAAsB;EACjE,MAAMwC,iBAAiB,GAAGvC,uBAAuB,CAACsC,WAAW,CAAC;;EAE9D;EACA,MAAMT,gBAAgB,GACpBf,OAAO,CAACc,eAAe,IAAId,OAAO,CAACe,gBAAgB,IAAI,KAAK;EAC9D,MAAMW,cAAc,GAAG1B,OAAO,CAAC0B,cAAc,IAAI,KAAK;EACtD,MAAMC,cAAc,GAAG3B,OAAO,CAACsB,YAAY,IAAI,IAAI,IAAIJ,aAAa;EACpE,MAAM;IAAEU,iBAAiB;IAAEC;EAAa,CAAC,GAAG7B,OAAO;EAEnD,OAAOhB,OAAO,CACZ,OAAO;IACL,GAAGiB,MAAM;IACTc,gBAAgB;IAChBN,mBAAmB;IACnBC,mBAAmB;IACnBQ,aAAa;IACbC,cAAc;IACdK,WAAW;IACXC,iBAAiB;IACjBG,iBAAiB;IACjBF,cAAc;IACdC,cAAc;IACdE;EACF,CAAC,CAAC,EACF,CACE5B,MAAM,EACNc,gBAAgB,EAChBN,mBAAmB,EACnBC,mBAAmB,EACnBQ,aAAa,EACbC,cAAc,EACdK,WAAW,EACXC,iBAAiB,EACjBG,iBAAiB,EACjBF,cAAc,EACdC,cAAc,EACdE,YAAY,CAEhB,CAAC;AACH","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"PdfViewerContext.js","names":["React","createContext","useContext","useMemo","EMPTY_ANNOTATION_ARRAY","usePdfAnnotationsByPage","usePdfFormFields","usePdfHighlightMode","usePdfViewerState","PdfViewerContext","PdfViewerProvider","value","children","createElement","Provider","usePdfViewerContext","ctx","Error","usePdfViewerInstance","options","viewer","src","defaultPage","initialPage","defaultScale","initialScale","defaultAutoSize","initialAutoSize","defaultSidebarOpen","initialSidebarOpen","sidebarMode","onDownload","highlightModeActive","toggleHighlightMode","pdfViewerRef","document","enabled","enableHighlight","highlightEnabled","onTextHighlight","onHighlightDelete","hasFormFields","submitFormData","eventBusRef","formData","onFormSubmit","onFormChange","annotations","annotationsByPage","enableDownload","enableFormSave","onAnnotationClick","outlineIcons"],"sources":["PdfViewerContext.tsx"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { PDFDocumentProxy } from \"pdfjs-dist\";\nimport type {\n EventBus,\n PDFFindController,\n PDFViewer,\n} from \"pdfjs-dist/web/pdf_viewer.mjs\";\nimport React, { createContext, useContext, useMemo } from \"react\";\nimport type { RefObject } from \"react\";\n\nimport { EMPTY_ANNOTATION_ARRAY } from \"./constants.js\";\nimport type { AnnotationPortalTarget } from \"./hooks/usePdfAnnotationPortals.js\";\nimport { usePdfAnnotationsByPage } from \"./hooks/usePdfAnnotationsByPage.js\";\nimport { usePdfFormFields } from \"./hooks/usePdfFormFields.js\";\nimport { usePdfHighlightMode } from \"./hooks/usePdfHighlightMode.js\";\nimport type { UsePdfViewerSearchResult } from \"./hooks/usePdfViewerSearch.js\";\nimport { usePdfViewerState } from \"./hooks/usePdfViewerState.js\";\nimport type {\n OutlineItem,\n PdfAnnotation,\n PdfViewerInstanceOptions,\n SidebarMode,\n} from \"./PdfViewerApi.js\";\n\n/** The shape of the value provided by {@link PdfViewerProvider}. */\nexport interface PdfViewerContextValue {\n // From UsePdfViewerStateResult (core + state)\n document: PDFDocumentProxy | undefined;\n numPages: number;\n loading: boolean;\n error: Error | undefined;\n containerRef: RefObject<HTMLDivElement>;\n viewerRef: RefObject<HTMLDivElement>;\n currentPage: number;\n scrollToPage: (page: number) => void;\n scale: number;\n setScale: (scale: number) => void;\n autoSize: boolean;\n setAutoSize: (autoSize: boolean) => void;\n zoomIn: () => void;\n zoomOut: () => void;\n toggleAutoSize: () => void;\n rotation: number;\n rotateLeft: () => void;\n rotateRight: () => void;\n sidebarOpen: boolean;\n sidebarMode: SidebarMode;\n setSidebarMode: (mode: SidebarMode) => void;\n toggleSidebar: () => void;\n search: UsePdfViewerSearchResult;\n outlineItems: OutlineItem[];\n download: (filename?: string) => void;\n portalTargets: AnnotationPortalTarget[];\n\n // From UsePdfHighlightModeResult\n highlightEnabled: boolean;\n highlightModeActive: boolean;\n toggleHighlightMode: () => void;\n\n // From UsePdfFormFieldsResult\n hasFormFields: boolean;\n submitFormData: () => void;\n\n // Annotations\n annotations: PdfAnnotation[];\n annotationsByPage: Record<number, PdfAnnotation[]>;\n onAnnotationClick: ((annotation: PdfAnnotation) => void) | undefined;\n\n // Config props passed through\n enableDownload: boolean;\n enableFormSave: boolean;\n outlineIcons: Partial<Record<number, React.ComponentType>> | undefined;\n\n // Internal refs (for advanced consumers)\n pdfViewerRef: RefObject<PDFViewer | null>;\n eventBusRef: RefObject<EventBus | null>;\n findControllerRef: RefObject<PDFFindController | null>;\n}\n\nconst PdfViewerContext = createContext<PdfViewerContextValue | null>(null);\n\nexport interface PdfViewerProviderProps {\n value: PdfViewerContextValue;\n children: React.ReactNode;\n}\n\n/** Provides {@link PdfViewerContextValue} to descendant components. */\nexport function PdfViewerProvider({\n value,\n children,\n}: PdfViewerProviderProps): React.ReactElement {\n return (\n <PdfViewerContext.Provider value={value}>\n {children}\n </PdfViewerContext.Provider>\n );\n}\n\n/**\n * Returns the nearest {@link PdfViewerContextValue} from a {@link PdfViewerProvider}.\n * Throws if called outside a provider.\n */\nexport function usePdfViewerContext(): PdfViewerContextValue {\n const ctx = useContext(PdfViewerContext);\n if (ctx == null) {\n throw new Error(\n \"usePdfViewerContext must be used within a PdfViewerProvider\",\n );\n }\n return ctx;\n}\n\n/**\n * Consumer-facing setup hook analogous to react-hook-form's `useForm()`.\n * Accepts viewer options and returns a {@link PdfViewerContextValue} suitable\n * for passing to {@link PdfViewerProvider}.\n */\nexport function usePdfViewerInstance(\n options: PdfViewerInstanceOptions,\n): PdfViewerContextValue {\n const viewer = usePdfViewerState({\n src: options.src,\n defaultPage: options.defaultPage,\n initialPage: options.initialPage,\n defaultScale: options.defaultScale,\n initialScale: options.initialScale,\n defaultAutoSize: options.defaultAutoSize,\n initialAutoSize: options.initialAutoSize,\n defaultSidebarOpen: options.defaultSidebarOpen,\n initialSidebarOpen: options.initialSidebarOpen,\n sidebarMode: options.sidebarMode,\n onDownload: options.onDownload,\n });\n\n const { highlightModeActive, toggleHighlightMode } = usePdfHighlightMode({\n pdfViewerRef: viewer.pdfViewerRef,\n document: viewer.document,\n enabled: options.enableHighlight ?? options.highlightEnabled ?? false,\n onTextHighlight: options.onTextHighlight,\n onHighlightDelete: options.onHighlightDelete,\n });\n\n const { hasFormFields, submitFormData } = usePdfFormFields({\n pdfViewerRef: viewer.pdfViewerRef,\n eventBusRef: viewer.eventBusRef,\n document: viewer.document,\n formData: options.formData,\n onFormSubmit: options.onFormSubmit,\n onFormChange: options.onFormChange,\n });\n\n const annotations = options.annotations ?? EMPTY_ANNOTATION_ARRAY;\n const annotationsByPage = usePdfAnnotationsByPage(annotations);\n\n // `highlightEnabled` is the deprecated spelling of `enableHighlight`.\n const highlightEnabled =\n options.enableHighlight ?? options.highlightEnabled ?? false;\n const enableDownload = options.enableDownload ?? false;\n const enableFormSave = options.onFormSubmit != null && hasFormFields;\n const { onAnnotationClick, outlineIcons } = options;\n\n return useMemo(\n () => ({\n ...viewer,\n highlightEnabled,\n highlightModeActive,\n toggleHighlightMode,\n hasFormFields,\n submitFormData,\n annotations,\n annotationsByPage,\n onAnnotationClick,\n enableDownload,\n enableFormSave,\n outlineIcons,\n }),\n [\n viewer,\n highlightEnabled,\n highlightModeActive,\n toggleHighlightMode,\n hasFormFields,\n submitFormData,\n annotations,\n annotationsByPage,\n onAnnotationClick,\n enableDownload,\n enableFormSave,\n outlineIcons,\n ],\n );\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAQA,OAAOA,KAAK,IAAIC,aAAa,EAAEC,UAAU,EAAEC,OAAO,QAAQ,OAAO;AAGjE,SAASC,sBAAsB,QAAQ,gBAAgB;AAEvD,SAASC,uBAAuB,QAAQ,oCAAoC;AAC5E,SAASC,gBAAgB,QAAQ,6BAA6B;AAC9D,SAASC,mBAAmB,QAAQ,gCAAgC;AAEpE,SAASC,iBAAiB,QAAQ,8BAA8B;;AAQhE;;AAuDA,MAAMC,gBAAgB,gBAAGR,aAAa,CAA+B,IAAI,CAAC;AAO1E;AACA,OAAO,SAASS,iBAAiBA,CAAC;EAChCC,KAAK;EACLC;AACsB,CAAC,EAAsB;EAC7C,oBACEZ,KAAA,CAAAa,aAAA,CAACJ,gBAAgB,CAACK,QAAQ;IAACH,KAAK,EAAEA;EAAM,GACrCC,QACwB,CAAC;AAEhC;;AAEA;AACA;AACA;AACA;AACA,OAAO,SAASG,mBAAmBA,CAAA,EAA0B;EAC3D,MAAMC,GAAG,GAAGd,UAAU,CAACO,gBAAgB,CAAC;EACxC,IAAIO,GAAG,IAAI,IAAI,EAAE;IACf,MAAM,IAAIC,KAAK,CACb,6DACF,CAAC;EACH;EACA,OAAOD,GAAG;AACZ;;AAEA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASE,oBAAoBA,CAClCC,OAAiC,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AAM4C,iBAAiB,GAAG3C,uBAAuB,CAAC0C,WAAW,CAAC;;EAE9D;EACA,MAAMT,gBAAgB,GACpBnB,OAAO,CAACkB,eAAe,IAAIlB,OAAO,CAACmB,gBAAgB,IAAI,KAAK;EAC9D,MAAMW,cAAc,GAAG9B,OAAO,CAAC8B,cAAc,IAAI,KAAK;EACtD,MAAMC,cAAc,GAAG/B,OAAO,CAAC0B,YAAY,IAAI,IAAI,IAAIJ,aAAa;EACpE,MAAM;IAAEU,iBAAiB;IAAEC;EAAa,CAAC,GAAGjC,OAAO;EAEnD,OAAOhB,OAAO,CACZ,OAAO;IACL,GAAGiB,MAAM;IACTkB,gBAAgB;IAChBN,mBAAmB;IACnBC,mBAAmB;IACnBQ,aAAa;IACbC,cAAc;IACdK,WAAW;IACXC,iBAAiB;IACjBG,iBAAiB;IACjBF,cAAc;IACdC,cAAc;IACdE;EACF,CAAC,CAAC,EACF,CACEhC,MAAM,EACNkB,gBAAgB,EAChBN,mBAAmB,EACnBC,mBAAmB,EACnBQ,aAAa,EACbC,cAAc,EACdK,WAAW,EACXC,iBAAiB,EACjBG,iBAAiB,EACjBF,cAAc,EACdC,cAAc,EACdE,YAAY,CAEhB,CAAC;AACH","ignoreList":[]}
|
|
@@ -28,8 +28,10 @@ export function PdfViewerContent({
|
|
|
28
28
|
src,
|
|
29
29
|
annotations = EMPTY_ANNOTATION_ARRAY,
|
|
30
30
|
onAnnotationClick,
|
|
31
|
-
|
|
32
|
-
|
|
31
|
+
defaultPage,
|
|
32
|
+
initialPage,
|
|
33
|
+
defaultScale,
|
|
34
|
+
initialScale,
|
|
33
35
|
onPageChange: onPageChangeProp,
|
|
34
36
|
onScaleChange: onScaleChangeProp,
|
|
35
37
|
formData,
|
|
@@ -38,7 +40,9 @@ export function PdfViewerContent({
|
|
|
38
40
|
}) {
|
|
39
41
|
const viewer = usePdfViewerCore({
|
|
40
42
|
src,
|
|
43
|
+
defaultPage,
|
|
41
44
|
initialPage,
|
|
45
|
+
defaultScale,
|
|
42
46
|
initialScale
|
|
43
47
|
});
|
|
44
48
|
const annotationsByPage = usePdfAnnotationsByPage(annotations);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PdfViewerContent.js","names":["Error","ErrorIcon","Spin","classnames","React","useEffect","useRef","EMPTY_ANNOTATION_ARRAY","usePdfAnnotationsByPage","usePdfFormFields","usePdfViewerCore","PdfAnnotationOverlay","styles","PdfViewerContent","src","annotations","onAnnotationClick","initialPage","initialScale","onPageChange","onPageChangeProp","onScaleChange","onScaleChangeProp","formData","onFormChange","className","viewer","annotationsByPage","pdfViewerRef","eventBusRef","document","onPageChangeRef","current","onScaleChangeRef","isInitialMountRef","currentPage","scale","rootClassName","pdfViewer","loading","createElement","loadingContainer","spinnerIcon","error","errorContainer","errorIcon","message","scrollContainerWrapper","ref","containerRef","scrollContainer","viewerRef","portalTargets","map","target","pageAnnotations","pageNumber","length","key"],"sources":["PdfViewerContent.tsx"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { Error as ErrorIcon, Spin } from \"@blueprintjs/icons\";\nimport classnames from \"classnames\";\n\nimport \"pdfjs-dist/web/pdf_viewer.css\";\nimport React, { useEffect, useRef } from \"react\";\n\nimport { EMPTY_ANNOTATION_ARRAY } from \"../constants.js\";\nimport { usePdfAnnotationsByPage } from \"../hooks/usePdfAnnotationsByPage.js\";\nimport { usePdfFormFields } from \"../hooks/usePdfFormFields.js\";\nimport { usePdfViewerCore } from \"../hooks/usePdfViewerCore.js\";\nimport type {\n PdfAnnotation,\n PdfFormFieldValue,\n PdfSource,\n} from \"../PdfViewerApi.js\";\nimport { PdfAnnotationOverlay } from \"./PdfAnnotationOverlay.js\";\n\nimport styles from \"../BasePdfViewer.module.css\";\n\nexport interface PdfViewerContentProps {\n /** PDF source — URL string, ArrayBuffer, Uint8Array, or Blob */\n src: PdfSource;\n /** Annotations to overlay on the PDF */\n annotations?: PdfAnnotation[];\n /** Callback fired when an annotation is clicked */\n onAnnotationClick?: (annotation: PdfAnnotation) => void;\n /** Initial page number (1-indexed, default 1) */\n initialPage?: number;\n /** Initial zoom scale (default 1.0) */\n initialScale?: number;\n /** Callback fired when the current page changes during scrolling */\n onPageChange?: (page: number) => void;\n /** Callback fired when the zoom scale changes */\n onScaleChange?: (scale: number) => void;\n /** Initial form field values keyed by field name. Applied when the document loads. */\n formData?: Record<string, PdfFormFieldValue>;\n /** Callback fired when any form field value changes. */\n onFormChange?: (fieldName: string, value: PdfFormFieldValue) => void;\n /** Additional CSS class name for the root element */\n className?: string;\n}\n\nexport function PdfViewerContent({\n src,\n annotations = EMPTY_ANNOTATION_ARRAY,\n onAnnotationClick,\n initialPage
|
|
1
|
+
{"version":3,"file":"PdfViewerContent.js","names":["Error","ErrorIcon","Spin","classnames","React","useEffect","useRef","EMPTY_ANNOTATION_ARRAY","usePdfAnnotationsByPage","usePdfFormFields","usePdfViewerCore","PdfAnnotationOverlay","styles","PdfViewerContent","src","annotations","onAnnotationClick","defaultPage","initialPage","defaultScale","initialScale","onPageChange","onPageChangeProp","onScaleChange","onScaleChangeProp","formData","onFormChange","className","viewer","annotationsByPage","pdfViewerRef","eventBusRef","document","onPageChangeRef","current","onScaleChangeRef","isInitialMountRef","currentPage","scale","rootClassName","pdfViewer","loading","createElement","loadingContainer","spinnerIcon","error","errorContainer","errorIcon","message","scrollContainerWrapper","ref","containerRef","scrollContainer","viewerRef","portalTargets","map","target","pageAnnotations","pageNumber","length","key"],"sources":["PdfViewerContent.tsx"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { Error as ErrorIcon, Spin } from \"@blueprintjs/icons\";\nimport classnames from \"classnames\";\n\nimport \"pdfjs-dist/web/pdf_viewer.css\";\nimport React, { useEffect, useRef } from \"react\";\n\nimport { EMPTY_ANNOTATION_ARRAY } from \"../constants.js\";\nimport { usePdfAnnotationsByPage } from \"../hooks/usePdfAnnotationsByPage.js\";\nimport { usePdfFormFields } from \"../hooks/usePdfFormFields.js\";\nimport { usePdfViewerCore } from \"../hooks/usePdfViewerCore.js\";\nimport type {\n PdfAnnotation,\n PdfFormFieldValue,\n PdfSource,\n} from \"../PdfViewerApi.js\";\nimport { PdfAnnotationOverlay } from \"./PdfAnnotationOverlay.js\";\n\nimport styles from \"../BasePdfViewer.module.css\";\n\nexport interface PdfViewerContentProps {\n /** PDF source — URL string, ArrayBuffer, Uint8Array, or Blob */\n src: PdfSource;\n /** Annotations to overlay on the PDF */\n annotations?: PdfAnnotation[];\n /** Callback fired when an annotation is clicked */\n onAnnotationClick?: (annotation: PdfAnnotation) => void;\n /** Initial page number (1-indexed, default 1) */\n defaultPage?: number;\n /** @deprecated Rename to `defaultPage`. */\n initialPage?: number;\n /** Initial zoom scale (default 1.0) */\n defaultScale?: number;\n /** @deprecated Rename to `defaultScale`. */\n initialScale?: number;\n /** Callback fired when the current page changes during scrolling */\n onPageChange?: (page: number) => void;\n /** Callback fired when the zoom scale changes */\n onScaleChange?: (scale: number) => void;\n /** Initial form field values keyed by field name. Applied when the document loads. */\n formData?: Record<string, PdfFormFieldValue>;\n /** Callback fired when any form field value changes. */\n onFormChange?: (fieldName: string, value: PdfFormFieldValue) => void;\n /** Additional CSS class name for the root element */\n className?: string;\n}\n\nexport function PdfViewerContent({\n src,\n annotations = EMPTY_ANNOTATION_ARRAY,\n onAnnotationClick,\n defaultPage,\n initialPage,\n defaultScale,\n initialScale,\n onPageChange: onPageChangeProp,\n onScaleChange: onScaleChangeProp,\n formData,\n onFormChange,\n className,\n}: PdfViewerContentProps): React.ReactElement {\n const viewer = usePdfViewerCore({\n src,\n defaultPage,\n initialPage,\n defaultScale,\n initialScale,\n });\n const annotationsByPage = usePdfAnnotationsByPage(annotations);\n\n usePdfFormFields({\n pdfViewerRef: viewer.pdfViewerRef,\n eventBusRef: viewer.eventBusRef,\n document: viewer.document,\n formData,\n onFormChange,\n });\n\n // Use refs for callbacks to avoid firing on initial mount\n const onPageChangeRef = useRef(onPageChangeProp);\n onPageChangeRef.current = onPageChangeProp;\n const onScaleChangeRef = useRef(onScaleChangeProp);\n onScaleChangeRef.current = onScaleChangeProp;\n const isInitialMountRef = useRef(true);\n\n useEffect(\n function notifyPageChange() {\n if (isInitialMountRef.current) {\n return;\n }\n onPageChangeRef.current?.(viewer.currentPage);\n },\n [viewer.currentPage],\n );\n\n useEffect(\n function notifyScaleChange() {\n if (isInitialMountRef.current) {\n return;\n }\n onScaleChangeRef.current?.(viewer.scale);\n },\n [viewer.scale],\n );\n\n useEffect(function clearInitialMount() {\n isInitialMountRef.current = false;\n }, []);\n\n const rootClassName = classnames(styles.pdfViewer, className);\n\n if (viewer.loading) {\n return (\n <div className={rootClassName}>\n <div className={styles.loadingContainer}>\n <Spin className={styles.spinnerIcon} />\n Loading…\n </div>\n </div>\n );\n }\n\n if (viewer.error != null) {\n return (\n <div className={rootClassName}>\n <div className={styles.errorContainer}>\n <ErrorIcon className={styles.errorIcon} />\n Failed to load PDF: {viewer.error.message}\n </div>\n </div>\n );\n }\n\n if (viewer.document == null) {\n return (\n <div className={rootClassName}>\n <div className={styles.loadingContainer}>No document</div>\n </div>\n );\n }\n\n return (\n <div className={rootClassName}>\n <div className={styles.scrollContainerWrapper}>\n <div ref={viewer.containerRef} className={styles.scrollContainer}>\n <div ref={viewer.viewerRef} className=\"pdfViewer\" />\n {viewer.portalTargets.map((target) => {\n const pageAnnotations =\n annotationsByPage[target.pageNumber] ?? EMPTY_ANNOTATION_ARRAY;\n if (pageAnnotations.length === 0) {\n return null;\n }\n return (\n <PdfAnnotationOverlay\n key={target.pageNumber}\n target={target}\n annotations={pageAnnotations}\n onAnnotationClick={onAnnotationClick}\n />\n );\n })}\n </div>\n </div>\n </div>\n );\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAASA,KAAK,IAAIC,SAAS,EAAEC,IAAI,QAAQ,oBAAoB;AAC7D,OAAOC,UAAU,MAAM,YAAY;AAEnC,OAAO,+BAA+B;AACtC,OAAOC,KAAK,IAAIC,SAAS,EAAEC,MAAM,QAAQ,OAAO;AAEhD,SAASC,sBAAsB,QAAQ,iBAAiB;AACxD,SAASC,uBAAuB,QAAQ,qCAAqC;AAC7E,SAASC,gBAAgB,QAAQ,8BAA8B;AAC/D,SAASC,gBAAgB,QAAQ,8BAA8B;AAM/D,SAASC,oBAAoB,QAAQ,2BAA2B;AAEhE,OAAOC,MAAM,MAAM,6BAA6B;AA6BhD,OAAO,SAASC,gBAAgBA,CAAC;EAC/BC,GAAG;EACHC,WAAW,GAAGR,sBAAsB;EACpCS,iBAAiB;EACjBC,WAAW;EACXC,WAAW;EACXC,YAAY;EACZC,YAAY;EACZC,YAAY,EAAEC,gBAAgB;EAC9BC,aAAa,EAAEC,iBAAiB;EAChCC,QAAQ;EACRC,YAAY;EACZC;AACqB,CAAC,EAAsB;EAC5C,MAAMC,MAAM,GAAGlB,gBAAgB,CAAC;IAC9BI,GAAG;IACHG,WAAW;IACXC,WAAW;IACXC,YAAY;IACZC;EACF,CAAC,CAAC;EACF,MAAMS,i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IAAI;IACb;IACA,oBACEvD,KAAA,CAAAsC,aAAA,CAAC/B,oBAAoB;MACnBiD,GAAG,EAAEJ,MAAM,CAACE,UAAW;MACvBF,MAAM,EAAEA,MAAO;MACfzC,WAAW,EAAE0C,eAAgB;MAC7BzC,iBAAiB,EAAEA;IAAkB,CACtC,CAAC;EAEN,CAAC,CACE,CACF,CACF,CAAC;AAEV","ignoreList":[]}
|
|
@@ -21,26 +21,32 @@ import { usePdfViewer } from "./usePdfViewer.js";
|
|
|
21
21
|
import { usePdfViewerSync } from "./usePdfViewerSync.js";
|
|
22
22
|
export function usePdfViewerCore({
|
|
23
23
|
src,
|
|
24
|
+
defaultPage,
|
|
25
|
+
// TODO: Move these defaults to the default* props when the initial* aliases are removed.
|
|
24
26
|
initialPage = 1,
|
|
27
|
+
defaultScale,
|
|
25
28
|
initialScale = 1.0,
|
|
29
|
+
defaultAutoSize,
|
|
26
30
|
initialAutoSize = false
|
|
27
31
|
}) {
|
|
32
|
+
const seededPage = defaultPage ?? initialPage;
|
|
33
|
+
const seededScale = defaultScale ?? initialScale;
|
|
28
34
|
const {
|
|
29
35
|
document,
|
|
30
36
|
numPages,
|
|
31
37
|
loading,
|
|
32
38
|
error
|
|
33
39
|
} = usePdfDocument(src);
|
|
34
|
-
const [scale, setScale] = useState(
|
|
35
|
-
const [currentPage, setCurrentPage] = useState(
|
|
36
|
-
const [autoSize, setAutoSize] = useState(initialAutoSize);
|
|
40
|
+
const [scale, setScale] = useState(seededScale);
|
|
41
|
+
const [currentPage, setCurrentPage] = useState(seededPage);
|
|
42
|
+
const [autoSize, setAutoSize] = useState(defaultAutoSize ?? initialAutoSize);
|
|
37
43
|
const containerRef = useRef(null);
|
|
38
44
|
const viewerRef = useRef(null);
|
|
39
45
|
const {
|
|
40
46
|
pdfViewerRef,
|
|
41
47
|
eventBusRef,
|
|
42
48
|
findControllerRef
|
|
43
|
-
} = usePdfViewer(containerRef, viewerRef, document,
|
|
49
|
+
} = usePdfViewer(containerRef, viewerRef, document, seededScale, seededPage);
|
|
44
50
|
const handleScaleChange = useCallback(newScale => {
|
|
45
51
|
setScale(newScale);
|
|
46
52
|
}, []);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usePdfViewerCore.js","names":["useCallback","useMemo","useRef","useState","usePdfAnnotationPortals","usePdfDocument","usePdfViewer","usePdfViewerSync","usePdfViewerCore","src","initialPage","initialScale","initialAutoSize","document","numPages","loading","error","scale","setScale","currentPage","setCurrentPage","autoSize","setAutoSize","containerRef","viewerRef","pdfViewerRef","eventBusRef","findControllerRef","handleScaleChange","newScale","handlePageChange","page","scrollToPage","syncScrollToPage","onScaleChange","onPageChange","portalTargets"],"sources":["usePdfViewerCore.ts"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { PDFDocumentProxy } from \"pdfjs-dist\";\nimport type {\n EventBus,\n PDFFindController,\n PDFViewer,\n} from \"pdfjs-dist/web/pdf_viewer.mjs\";\nimport type { RefObject } from \"react\";\nimport { useCallback, useMemo, useRef, useState } from \"react\";\n\nimport type { PdfSource } from \"../PdfViewerApi.js\";\nimport type { AnnotationPortalTarget } from \"./usePdfAnnotationPortals.js\";\nimport { usePdfAnnotationPortals } from \"./usePdfAnnotationPortals.js\";\nimport { usePdfDocument } from \"./usePdfDocument.js\";\nimport { usePdfViewer } from \"./usePdfViewer.js\";\nimport { usePdfViewerSync } from \"./usePdfViewerSync.js\";\n\nexport interface UsePdfViewerCoreOptions {\n /** PDF source — URL string, ArrayBuffer, Uint8Array, or Blob */\n src: PdfSource;\n /** Initial page number (1-indexed, default 1) */\n initialPage?: number;\n /** Initial zoom scale (default 1.0) */\n initialScale?: number;\n /** Whether auto-size (fit to width) is initially enabled (default false) */\n initialAutoSize?: boolean;\n}\n\nexport interface UsePdfViewerCoreResult {\n /** The loaded PDF document, or undefined while loading */\n document: PDFDocumentProxy | undefined;\n /** Total number of pages in the document */\n numPages: number;\n /** Whether the document is currently loading */\n loading: boolean;\n /** Error encountered while loading the document */\n error: Error | undefined;\n\n /** Ref to attach to the scroll-container div */\n containerRef: RefObject<HTMLDivElement>;\n /** Ref to attach to the inner viewer div (className=\"pdfViewer\") */\n viewerRef: RefObject<HTMLDivElement>;\n\n /** Current page number (1-indexed) */\n currentPage: number;\n /** Navigate to a specific page (updates state and scrolls the viewer) */\n scrollToPage: (page: number) => void;\n\n /** Current zoom scale */\n scale: number;\n /** Set the zoom scale directly */\n setScale: (scale: number) => void;\n\n /** Whether auto-size (fit to width) is active */\n autoSize: boolean;\n /** Enable or disable auto-size */\n setAutoSize: (autoSize: boolean) => void;\n\n /** Portal targets for rendering annotation overlays on each page */\n portalTargets: AnnotationPortalTarget[];\n\n /** Ref to the internal pdfjs PDFViewer instance */\n pdfViewerRef: RefObject<PDFViewer | null>;\n /** Ref to the internal pdfjs EventBus instance */\n eventBusRef: RefObject<EventBus | null>;\n /** Ref to the internal pdfjs PDFFindController instance */\n findControllerRef: RefObject<PDFFindController | null>;\n}\n\nexport function usePdfViewerCore({\n src,\n initialPage = 1,\n initialScale = 1.0,\n initialAutoSize = false,\n}: UsePdfViewerCoreOptions): UsePdfViewerCoreResult {\n const { document, numPages, loading, error } = usePdfDocument(src);\n const [scale, setScale] = useState(
|
|
1
|
+
{"version":3,"file":"usePdfViewerCore.js","names":["useCallback","useMemo","useRef","useState","usePdfAnnotationPortals","usePdfDocument","usePdfViewer","usePdfViewerSync","usePdfViewerCore","src","defaultPage","initialPage","defaultScale","initialScale","defaultAutoSize","initialAutoSize","seededPage","seededScale","document","numPages","loading","error","scale","setScale","currentPage","setCurrentPage","autoSize","setAutoSize","containerRef","viewerRef","pdfViewerRef","eventBusRef","findControllerRef","handleScaleChange","newScale","handlePageChange","page","scrollToPage","syncScrollToPage","onScaleChange","onPageChange","portalTargets"],"sources":["usePdfViewerCore.ts"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { PDFDocumentProxy } from \"pdfjs-dist\";\nimport type {\n EventBus,\n PDFFindController,\n PDFViewer,\n} from \"pdfjs-dist/web/pdf_viewer.mjs\";\nimport type { RefObject } from \"react\";\nimport { useCallback, useMemo, useRef, useState } from \"react\";\n\nimport type { PdfSource } from \"../PdfViewerApi.js\";\nimport type { AnnotationPortalTarget } from \"./usePdfAnnotationPortals.js\";\nimport { usePdfAnnotationPortals } from \"./usePdfAnnotationPortals.js\";\nimport { usePdfDocument } from \"./usePdfDocument.js\";\nimport { usePdfViewer } from \"./usePdfViewer.js\";\nimport { usePdfViewerSync } from \"./usePdfViewerSync.js\";\n\nexport interface UsePdfViewerCoreOptions {\n /** PDF source — URL string, ArrayBuffer, Uint8Array, or Blob */\n src: PdfSource;\n /** Initial page number (1-indexed, default 1) */\n defaultPage?: number;\n /** @deprecated Rename to `defaultPage`. */\n initialPage?: number;\n /** Initial zoom scale (default 1.0) */\n defaultScale?: number;\n /** @deprecated Rename to `defaultScale`. */\n initialScale?: number;\n /** Whether auto-size (fit to width) is initially enabled (default false) */\n defaultAutoSize?: boolean;\n /** @deprecated Rename to `defaultAutoSize`. */\n initialAutoSize?: boolean;\n}\n\nexport interface UsePdfViewerCoreResult {\n /** The loaded PDF document, or undefined while loading */\n document: PDFDocumentProxy | undefined;\n /** Total number of pages in the document */\n numPages: number;\n /** Whether the document is currently loading */\n loading: boolean;\n /** Error encountered while loading the document */\n error: Error | undefined;\n\n /** Ref to attach to the scroll-container div */\n containerRef: RefObject<HTMLDivElement>;\n /** Ref to attach to the inner viewer div (className=\"pdfViewer\") */\n viewerRef: RefObject<HTMLDivElement>;\n\n /** Current page number (1-indexed) */\n currentPage: number;\n /** Navigate to a specific page (updates state and scrolls the viewer) */\n scrollToPage: (page: number) => void;\n\n /** Current zoom scale */\n scale: number;\n /** Set the zoom scale directly */\n setScale: (scale: number) => void;\n\n /** Whether auto-size (fit to width) is active */\n autoSize: boolean;\n /** Enable or disable auto-size */\n setAutoSize: (autoSize: boolean) => void;\n\n /** Portal targets for rendering annotation overlays on each page */\n portalTargets: AnnotationPortalTarget[];\n\n /** Ref to the internal pdfjs PDFViewer instance */\n pdfViewerRef: RefObject<PDFViewer | null>;\n /** Ref to the internal pdfjs EventBus instance */\n eventBusRef: RefObject<EventBus | null>;\n /** Ref to the internal pdfjs PDFFindController instance */\n findControllerRef: RefObject<PDFFindController | null>;\n}\n\nexport function usePdfViewerCore({\n src,\n defaultPage,\n // TODO: Move these defaults to the default* props when the initial* aliases are removed.\n initialPage = 1,\n defaultScale,\n initialScale = 1.0,\n defaultAutoSize,\n initialAutoSize = false,\n}: UsePdfViewerCoreOptions): UsePdfViewerCoreResult {\n const seededPage = defaultPage ?? initialPage;\n const seededScale = defaultScale ?? initialScale;\n const seededAutoSize = defaultAutoSize ?? initialAutoSize;\n const { document, numPages, loading, error } = usePdfDocument(src);\n const [scale, setScale] = useState(seededScale);\n const [currentPage, setCurrentPage] = useState(seededPage);\n const [autoSize, setAutoSize] = useState(seededAutoSize);\n const containerRef = useRef<HTMLDivElement>(null);\n const viewerRef = useRef<HTMLDivElement>(null);\n\n const { pdfViewerRef, eventBusRef, findControllerRef } = usePdfViewer(\n containerRef,\n viewerRef,\n document,\n seededScale,\n seededPage,\n );\n\n const handleScaleChange = useCallback((newScale: number) => {\n setScale(newScale);\n }, []);\n\n const handlePageChange = useCallback((page: number) => {\n setCurrentPage(page);\n }, []);\n\n const { scrollToPage: syncScrollToPage } = usePdfViewerSync({\n pdfViewerRef,\n eventBusRef,\n containerRef,\n document,\n scale,\n autoSize,\n onScaleChange: handleScaleChange,\n onPageChange: handlePageChange,\n });\n\n const scrollToPage = useCallback(\n (page: number) => {\n setCurrentPage(page);\n syncScrollToPage(page);\n },\n [syncScrollToPage],\n );\n\n const portalTargets = usePdfAnnotationPortals(\n pdfViewerRef,\n eventBusRef,\n document,\n );\n\n return useMemo(\n (): UsePdfViewerCoreResult => ({\n document,\n numPages,\n loading,\n error,\n containerRef,\n viewerRef,\n currentPage,\n scrollToPage,\n scale,\n setScale,\n autoSize,\n setAutoSize,\n portalTargets,\n pdfViewerRef,\n eventBusRef,\n findControllerRef,\n }),\n [\n document,\n numPages,\n loading,\n error,\n currentPage,\n scrollToPage,\n scale,\n setScale,\n autoSize,\n setAutoSize,\n portalTargets,\n ],\n );\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AASA,SAASA,WAAW,EAAEC,OAAO,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,OAAO;AAI9D,SAASC,uBAAuB,QAAQ,8BAA8B;AACtE,SAASC,cAAc,QAAQ,qBAAqB;AACpD,SAASC,YAAY,QAAQ,mBAAmB;AAChD,SAASC,gBAAgB,QAAQ,uBAAuB;AA4DxD,OAAO,SAASC,gBAAgBA,CAAC;EAC/BC,GAAG;EACHC,WAAW;EACX;EACAC,WAAW,GAAG,CAAC;EACfC,YAAY;EACZC,YAAY,GAAG,GAAG;EAClBC,eAAe;EACfC,eAAe,GAAG;AACK,CAAC,EAA0B;EAClD,MAAMC,UAAU,GAAGN,WAAW,IAAIC,WAAW;EAC7C,MAAMM,WAAW,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gBAAgB,CACnB,CAAC;EAED,MAAMG,aAAa,GAAGrC,uBAAuB,CAC3C0B,YAAY,EACZC,WAAW,EACXb,QACF,CAAC;EAED,OAAOjB,OAAO,CACZ,OAA+B;IAC7BiB,QAAQ;IACRC,QAAQ;IACRC,OAAO;IACPC,KAAK;IACLO,YAAY;IACZC,SAAS;IACTL,WAAW;IACXa,YAAY;IACZf,KAAK;IACLC,QAAQ;IACRG,QAAQ;IACRC,WAAW;IACXc,aAAa;IACbX,YAAY;IACZC,WAAW;IACXC;EACF,CAAC,CAAC,EACF,CACEd,QAAQ,EACRC,QAAQ,EACRC,OAAO,EACPC,KAAK,EACLG,WAAW,EACXa,YAAY,EACZf,KAAK,EACLC,QAAQ,EACRG,QAAQ,EACRC,WAAW,EACXc,aAAa,CAEjB,CAAC;AACH","ignoreList":[]}
|
|
@@ -21,21 +21,29 @@ import { usePdfViewerCore } from "./usePdfViewerCore.js";
|
|
|
21
21
|
import { usePdfViewerSearch } from "./usePdfViewerSearch.js";
|
|
22
22
|
export function usePdfViewerState({
|
|
23
23
|
src,
|
|
24
|
+
defaultPage,
|
|
24
25
|
initialPage,
|
|
26
|
+
defaultScale,
|
|
25
27
|
initialScale,
|
|
28
|
+
defaultAutoSize,
|
|
26
29
|
initialAutoSize,
|
|
30
|
+
defaultSidebarOpen,
|
|
31
|
+
// TODO: Move this default to defaultSidebarOpen when initialSidebarOpen is removed.
|
|
27
32
|
initialSidebarOpen = false,
|
|
28
33
|
sidebarMode: sidebarModeProp = "thumbnails",
|
|
29
34
|
onDownload
|
|
30
35
|
}) {
|
|
31
36
|
const core = usePdfViewerCore({
|
|
32
37
|
src,
|
|
38
|
+
defaultPage,
|
|
33
39
|
initialPage,
|
|
40
|
+
defaultScale,
|
|
34
41
|
initialScale,
|
|
42
|
+
defaultAutoSize,
|
|
35
43
|
initialAutoSize
|
|
36
44
|
});
|
|
37
45
|
const [rotation, setRotation] = useState(0);
|
|
38
|
-
const [sidebarOpen, setSidebarOpen] = useState(initialSidebarOpen);
|
|
46
|
+
const [sidebarOpen, setSidebarOpen] = useState(defaultSidebarOpen ?? initialSidebarOpen);
|
|
39
47
|
const [sidebarMode, setSidebarMode] = useState(sidebarModeProp);
|
|
40
48
|
const search = usePdfViewerSearch(core.eventBusRef, core.findControllerRef, core.document);
|
|
41
49
|
const outlineItems = usePdfOutline(core.document);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usePdfViewerState.js","names":["useCallback","useEffect","useMemo","useRef","useState","MAX_SCALE","MIN_SCALE","PAGE_WIDTH_SCALE_VALUE","SCALE_STEP","usePdfOutline","usePdfViewerCore","usePdfViewerSearch","usePdfViewerState","src","initialPage","initialScale","initialAutoSize","initialSidebarOpen","sidebarMode","sidebarModeProp","onDownload","core","rotation","setRotation","sidebarOpen","setSidebarOpen","setSidebarMode","search","eventBusRef","findControllerRef","document","outlineItems","pdfViewer","pdfViewerRef","current","pagesRotation","prevRotationRef","autoSize","currentScaleValue","handleKeyDown","e","ctrlKey","metaKey","key","preventDefault","openSearch","window","addEventListener","removeEventListener","zoomIn","setAutoSize","setScale","Math","min","scale","zoomOut","max","toggleAutoSize","rotateLeft","prev","rotateRight","toggleSidebar","download","filename","getData","then","data","blob","Blob","buffer","type","url","URL","createObjectURL","resolvedFilename","resolveDownloadFilename","a","globalThis","createElement","href","click","revokeObjectURL","success","catch","err","error","Error","split","pop"],"sources":["usePdfViewerState.ts"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { useCallback, useEffect, useMemo, useRef, useState } from \"react\";\n\nimport {\n MAX_SCALE,\n MIN_SCALE,\n PAGE_WIDTH_SCALE_VALUE,\n SCALE_STEP,\n} from \"../constants.js\";\nimport type {\n PdfDownloadResult,\n PdfSource,\n SidebarMode,\n} from \"../PdfViewerApi.js\";\nimport { usePdfOutline } from \"./usePdfOutline.js\";\nimport type {\n UsePdfViewerCoreOptions,\n UsePdfViewerCoreResult,\n} from \"./usePdfViewerCore.js\";\nimport { usePdfViewerCore } from \"./usePdfViewerCore.js\";\nimport type { UsePdfViewerSearchResult } from \"./usePdfViewerSearch.js\";\nimport { usePdfViewerSearch } from \"./usePdfViewerSearch.js\";\n\nexport interface UsePdfViewerStateOptions extends UsePdfViewerCoreOptions {\n /** Whether the sidebar is initially open (default false) */\n initialSidebarOpen?: boolean;\n /** Which sidebar panel to show (default \"thumbnails\") */\n sidebarMode?: SidebarMode;\n /** Callback fired when a download completes or fails */\n onDownload?: (result: PdfDownloadResult) => void;\n}\n\nexport interface UsePdfViewerStateResult extends UsePdfViewerCoreResult {\n /** Zoom in by one step (disables auto-size) */\n zoomIn: () => void;\n /** Zoom out by one step (disables auto-size) */\n zoomOut: () => void;\n /** Toggle auto-size (fit to width) on or off */\n toggleAutoSize: () => void;\n\n /** Current rotation in degrees (0, 90, 180, 270) */\n rotation: number;\n /** Rotate 90 degrees counter-clockwise */\n rotateLeft: () => void;\n /** Rotate 90 degrees clockwise */\n rotateRight: () => void;\n\n /** Whether the sidebar panel is open */\n sidebarOpen: boolean;\n /** Which sidebar panel is active */\n sidebarMode: SidebarMode;\n /** Change the active sidebar panel */\n setSidebarMode: (mode: SidebarMode) => void;\n /** Toggle sidebar open/closed */\n toggleSidebar: () => void;\n\n /** Search state and actions */\n search: UsePdfViewerSearchResult;\n\n /** Document outline items (from bookmarks or text extraction) */\n outlineItems: ReturnType<typeof usePdfOutline>;\n\n /** Download the PDF as a file */\n download: (filename?: string) => void;\n}\n\nexport function usePdfViewerState({\n src,\n initialPage,\n initialScale,\n initialAutoSize,\n initialSidebarOpen = false,\n sidebarMode: sidebarModeProp = \"thumbnails\",\n onDownload,\n}: UsePdfViewerStateOptions): UsePdfViewerStateResult {\n const core = usePdfViewerCore({\n src,\n initialPage,\n initialScale,\n initialAutoSize,\n });\n\n const [rotation, setRotation] = useState(0);\n const [sidebarOpen, setSidebarOpen] = useState(initialSidebarOpen);\n const [sidebarMode, setSidebarMode] = useState<SidebarMode>(sidebarModeProp);\n\n const search = usePdfViewerSearch(\n core.eventBusRef,\n core.findControllerRef,\n core.document,\n );\n\n const outlineItems = usePdfOutline(core.document);\n\n // Sync sidebarMode prop changes to state\n useEffect(\n function syncSidebarMode() {\n setSidebarMode(sidebarModeProp);\n },\n [sidebarModeProp],\n );\n\n // Sync rotation → PDFViewer\n useEffect(\n function syncRotationToViewer() {\n const pdfViewer = core.pdfViewerRef.current;\n if (pdfViewer != null) {\n pdfViewer.pagesRotation = rotation;\n }\n },\n [core.pdfViewerRef, rotation],\n );\n\n // Re-apply page-width after rotation changes while auto-size is active.\n // Rotation changes the effective page width, so auto-size must re-fit.\n const prevRotationRef = useRef(rotation);\n useEffect(\n function reapplyAutoSizeAfterRotation() {\n if (prevRotationRef.current === rotation) {\n return;\n }\n prevRotationRef.current = rotation;\n const pdfViewer = core.pdfViewerRef.current;\n if (pdfViewer == null || !core.autoSize) {\n return;\n }\n pdfViewer.currentScaleValue = PAGE_WIDTH_SCALE_VALUE;\n },\n [core.pdfViewerRef, core.autoSize, rotation],\n );\n\n // Ctrl+F keyboard shortcut\n useEffect(\n function registerSearchShortcut() {\n const handleKeyDown = (e: KeyboardEvent) => {\n if ((e.ctrlKey || e.metaKey) && e.key === \"f\") {\n e.preventDefault();\n search.openSearch();\n }\n };\n window.addEventListener(\"keydown\", handleKeyDown);\n return () => {\n window.removeEventListener(\"keydown\", handleKeyDown);\n };\n },\n [search.openSearch],\n );\n\n const zoomIn = useCallback(() => {\n core.setAutoSize(false);\n core.setScale(Math.min(core.scale + SCALE_STEP, MAX_SCALE));\n }, [core.scale, core.setScale, core.setAutoSize]);\n\n const zoomOut = useCallback(() => {\n core.setAutoSize(false);\n core.setScale(Math.max(core.scale - SCALE_STEP, MIN_SCALE));\n }, [core.scale, core.setScale, core.setAutoSize]);\n\n const toggleAutoSize = useCallback(() => {\n core.setAutoSize(!core.autoSize);\n }, [core.autoSize, core.setAutoSize]);\n\n const rotateLeft = useCallback(() => {\n setRotation((prev) => (prev - 90 + 360) % 360);\n }, []);\n\n const rotateRight = useCallback(() => {\n setRotation((prev) => (prev + 90) % 360);\n }, []);\n\n const toggleSidebar = useCallback(() => {\n setSidebarOpen((prev) => !prev);\n }, []);\n\n const download = useCallback(\n (filename?: string) => {\n if (core.document == null) {\n return;\n }\n void core.document\n .getData()\n .then((data) => {\n const blob = new Blob([data.buffer as ArrayBuffer], {\n type: \"application/pdf\",\n });\n const url = URL.createObjectURL(blob);\n const resolvedFilename = resolveDownloadFilename(src, filename);\n const a = globalThis.document.createElement(\"a\");\n a.href = url;\n a.download = resolvedFilename;\n a.click();\n URL.revokeObjectURL(url);\n onDownload?.({ success: true, filename: resolvedFilename });\n })\n .catch((err: unknown) => {\n onDownload?.({\n success: false,\n error:\n err instanceof Error ? err : new Error(\"Failed to download PDF\"),\n });\n });\n },\n [core.document, src, onDownload],\n );\n\n return useMemo(\n (): UsePdfViewerStateResult => ({\n ...core,\n zoomIn,\n zoomOut,\n toggleAutoSize,\n rotation,\n rotateLeft,\n rotateRight,\n sidebarOpen,\n sidebarMode,\n setSidebarMode,\n toggleSidebar,\n search,\n outlineItems,\n download,\n }),\n [\n core,\n zoomIn,\n zoomOut,\n toggleAutoSize,\n rotation,\n rotateLeft,\n rotateRight,\n sidebarOpen,\n sidebarMode,\n setSidebarMode,\n toggleSidebar,\n search,\n outlineItems,\n download,\n ],\n );\n}\n\n/** Derive a download filename from an explicit name, the src URL, or a fallback. */\nfunction resolveDownloadFilename(\n src: PdfSource,\n filename: string | undefined,\n): string {\n if (filename != null) {\n return filename;\n }\n if (typeof src === \"string\") {\n return src.split(\"/\").pop()?.split(\"?\")[0] || \"document.pdf\";\n }\n return \"document.pdf\";\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAASA,WAAW,EAAEC,SAAS,EAAEC,OAAO,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,OAAO;AAEzE,SACEC,SAAS,EACTC,SAAS,EACTC,sBAAsB,EACtBC,UAAU,QACL,iBAAiB;AAMxB,SAASC,aAAa,QAAQ,oBAAoB;AAKlD,SAASC,gBAAgB,QAAQ,uBAAuB;AAExD,SAASC,kBAAkB,QAAQ,yBAAyB;AA6C5D,OAAO,SAASC,iBAAiBA,CAAC;EAChCC,GAAG;EACHC,WAAW;EACXC,YAAY;EACZC,eAAe;EACfC,kBAAkB,GAAG,KAAK;EAC1BC,WAAW,EAAEC,eAAe,GAAG,YAAY;EAC3CC;AACwB,CAAC,EAA2B;EACpD,MAAMC,IAAI,GAAGX,gBAAgB,CAAC;IAC5BG,GAAG;IACHC,WAAW;IACXC,YAAY;IACZC;EACF,CAAC,CAAC;EAEF,MAAM,CAACM,QAAQ,EAAEC,WAAW,CAAC,GAAGnB,QAAQ,CAAC,CAAC,CAAC;EAC3C,MAAM,CAACoB,WAAW,EAAEC,cAAc,CAAC,GAAGrB,QAAQ,CAACa,kBAAkB,CAAC;EAClE,MAAM,CAACC,WAAW,EAAEQ,cAAc,CAAC,GAAGtB,QAAQ,CAAce,eAAe,CAAC;EAE5E,MAAMQ,MAAM,GAAGhB,kBAAkB,CAC/BU,IAAI,CAACO,WAAW,EAChBP,IAAI,CAACQ,iBAAiB,EACtBR,IAAI,CAACS,QACP,CAAC;EAED,MAAMC,YAAY,GAAGtB,aAAa,CAACY,IAAI,CAACS,QAAQ,CAAC;;EAEjD;EACA7B,SAAS,CACP,YAA2B;IACzByB,cAAc,CAACP,eAAe,CAAC;EACjC,CAAC,EACD,CAACA,eAAe,C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IACRoC,UAAU;IACVE,WAAW;IACXpC,WAAW;IACXN,WAAW;IACXQ,cAAc;IACdmC,aAAa;IACblC,MAAM;IACNI,YAAY;IACZ+B;EACF,CAAC,CAAC,EACF,CACEzC,IAAI,EACJ4B,MAAM,EACNM,OAAO,EACPE,cAAc,EACdnC,QAAQ,EACRoC,UAAU,EACVE,WAAW,EACXpC,WAAW,EACXN,WAAW,EACXQ,cAAc,EACdmC,aAAa,EACblC,MAAM,EACNI,YAAY,EACZ+B,QAAQ,CAEZ,CAAC;AACH;;AAEA;AACA,SAASa,uBAAuBA,CAC9B9D,GAAc,EACdkD,QAA4B,EACpB;EACR,IAAIA,QAAQ,IAAI,IAAI,EAAE;IACpB,OAAOA,QAAQ;EACjB;EACA,IAAI,OAAOlD,GAAG,KAAK,QAAQ,EAAE;IAC3B,OAAOA,GAAG,CAAC0E,KAAK,CAAC,GAAG,CAAC,CAACC,GAAG,CAAC,CAAC,EAAED,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,cAAc;EAC9D;EACA,OAAO,cAAc;AACvB","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"usePdfViewerState.js","names":["useCallback","useEffect","useMemo","useRef","useState","MAX_SCALE","MIN_SCALE","PAGE_WIDTH_SCALE_VALUE","SCALE_STEP","usePdfOutline","usePdfViewerCore","usePdfViewerSearch","usePdfViewerState","src","defaultPage","initialPage","defaultScale","initialScale","defaultAutoSize","initialAutoSize","defaultSidebarOpen","initialSidebarOpen","sidebarMode","sidebarModeProp","onDownload","core","rotation","setRotation","sidebarOpen","setSidebarOpen","setSidebarMode","search","eventBusRef","findControllerRef","document","outlineItems","pdfViewer","pdfViewerRef","current","pagesRotation","prevRotationRef","autoSize","currentScaleValue","handleKeyDown","e","ctrlKey","metaKey","key","preventDefault","openSearch","window","addEventListener","removeEventListener","zoomIn","setAutoSize","setScale","Math","min","scale","zoomOut","max","toggleAutoSize","rotateLeft","prev","rotateRight","toggleSidebar","download","filename","getData","then","data","blob","Blob","buffer","type","url","URL","createObjectURL","resolvedFilename","resolveDownloadFilename","a","globalThis","createElement","href","click","revokeObjectURL","success","catch","err","error","Error","split","pop"],"sources":["usePdfViewerState.ts"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { useCallback, useEffect, useMemo, useRef, useState } from \"react\";\n\nimport {\n MAX_SCALE,\n MIN_SCALE,\n PAGE_WIDTH_SCALE_VALUE,\n SCALE_STEP,\n} from \"../constants.js\";\nimport type {\n PdfDownloadResult,\n PdfSource,\n SidebarMode,\n} from \"../PdfViewerApi.js\";\nimport { usePdfOutline } from \"./usePdfOutline.js\";\nimport type {\n UsePdfViewerCoreOptions,\n UsePdfViewerCoreResult,\n} from \"./usePdfViewerCore.js\";\nimport { usePdfViewerCore } from \"./usePdfViewerCore.js\";\nimport type { UsePdfViewerSearchResult } from \"./usePdfViewerSearch.js\";\nimport { usePdfViewerSearch } from \"./usePdfViewerSearch.js\";\n\nexport interface UsePdfViewerStateOptions extends UsePdfViewerCoreOptions {\n /** Whether the sidebar is initially open (default false) */\n defaultSidebarOpen?: boolean;\n /** @deprecated Rename to `defaultSidebarOpen`. */\n initialSidebarOpen?: boolean;\n /** Which sidebar panel to show (default \"thumbnails\") */\n sidebarMode?: SidebarMode;\n /** Callback fired when a download completes or fails */\n onDownload?: (result: PdfDownloadResult) => void;\n}\n\nexport interface UsePdfViewerStateResult extends UsePdfViewerCoreResult {\n /** Zoom in by one step (disables auto-size) */\n zoomIn: () => void;\n /** Zoom out by one step (disables auto-size) */\n zoomOut: () => void;\n /** Toggle auto-size (fit to width) on or off */\n toggleAutoSize: () => void;\n\n /** Current rotation in degrees (0, 90, 180, 270) */\n rotation: number;\n /** Rotate 90 degrees counter-clockwise */\n rotateLeft: () => void;\n /** Rotate 90 degrees clockwise */\n rotateRight: () => void;\n\n /** Whether the sidebar panel is open */\n sidebarOpen: boolean;\n /** Which sidebar panel is active */\n sidebarMode: SidebarMode;\n /** Change the active sidebar panel */\n setSidebarMode: (mode: SidebarMode) => void;\n /** Toggle sidebar open/closed */\n toggleSidebar: () => void;\n\n /** Search state and actions */\n search: UsePdfViewerSearchResult;\n\n /** Document outline items (from bookmarks or text extraction) */\n outlineItems: ReturnType<typeof usePdfOutline>;\n\n /** Download the PDF as a file */\n download: (filename?: string) => void;\n}\n\nexport function usePdfViewerState({\n src,\n defaultPage,\n initialPage,\n defaultScale,\n initialScale,\n defaultAutoSize,\n initialAutoSize,\n defaultSidebarOpen,\n // TODO: Move this default to defaultSidebarOpen when initialSidebarOpen is removed.\n initialSidebarOpen = false,\n sidebarMode: sidebarModeProp = \"thumbnails\",\n onDownload,\n}: UsePdfViewerStateOptions): UsePdfViewerStateResult {\n const core = usePdfViewerCore({\n src,\n defaultPage,\n initialPage,\n defaultScale,\n initialScale,\n defaultAutoSize,\n initialAutoSize,\n });\n\n const [rotation, setRotation] = useState(0);\n const [sidebarOpen, setSidebarOpen] = useState(\n defaultSidebarOpen ?? initialSidebarOpen,\n );\n const [sidebarMode, setSidebarMode] = useState<SidebarMode>(sidebarModeProp);\n\n const search = usePdfViewerSearch(\n core.eventBusRef,\n core.findControllerRef,\n core.document,\n );\n\n const outlineItems = usePdfOutline(core.document);\n\n // Sync sidebarMode prop changes to state\n useEffect(\n function syncSidebarMode() {\n setSidebarMode(sidebarModeProp);\n },\n [sidebarModeProp],\n );\n\n // Sync rotation → PDFViewer\n useEffect(\n function syncRotationToViewer() {\n const pdfViewer = core.pdfViewerRef.current;\n if (pdfViewer != null) {\n pdfViewer.pagesRotation = rotation;\n }\n },\n [core.pdfViewerRef, rotation],\n );\n\n // Re-apply page-width after rotation changes while auto-size is active.\n // Rotation changes the effective page width, so auto-size must re-fit.\n const prevRotationRef = useRef(rotation);\n useEffect(\n function reapplyAutoSizeAfterRotation() {\n if (prevRotationRef.current === rotation) {\n return;\n }\n prevRotationRef.current = rotation;\n const pdfViewer = core.pdfViewerRef.current;\n if (pdfViewer == null || !core.autoSize) {\n return;\n }\n pdfViewer.currentScaleValue = PAGE_WIDTH_SCALE_VALUE;\n },\n [core.pdfViewerRef, core.autoSize, rotation],\n );\n\n // Ctrl+F keyboard shortcut\n useEffect(\n function registerSearchShortcut() {\n const handleKeyDown = (e: KeyboardEvent) => {\n if ((e.ctrlKey || e.metaKey) && e.key === \"f\") {\n e.preventDefault();\n search.openSearch();\n }\n };\n window.addEventListener(\"keydown\", handleKeyDown);\n return () => {\n window.removeEventListener(\"keydown\", handleKeyDown);\n };\n },\n [search.openSearch],\n );\n\n const zoomIn = useCallback(() => {\n core.setAutoSize(false);\n core.setScale(Math.min(core.scale + SCALE_STEP, MAX_SCALE));\n }, [core.scale, core.setScale, core.setAutoSize]);\n\n const zoomOut = useCallback(() => {\n core.setAutoSize(false);\n core.setScale(Math.max(core.scale - SCALE_STEP, MIN_SCALE));\n }, [core.scale, core.setScale, core.setAutoSize]);\n\n const toggleAutoSize = useCallback(() => {\n core.setAutoSize(!core.autoSize);\n }, [core.autoSize, core.setAutoSize]);\n\n const rotateLeft = useCallback(() => {\n setRotation((prev) => (prev - 90 + 360) % 360);\n }, []);\n\n const rotateRight = useCallback(() => {\n setRotation((prev) => (prev + 90) % 360);\n }, []);\n\n const toggleSidebar = useCallback(() => {\n setSidebarOpen((prev) => !prev);\n }, []);\n\n const download = useCallback(\n (filename?: string) => {\n if (core.document == null) {\n return;\n }\n void core.document\n .getData()\n .then((data) => {\n const blob = new Blob([data.buffer as ArrayBuffer], {\n type: \"application/pdf\",\n });\n const url = URL.createObjectURL(blob);\n const resolvedFilename = resolveDownloadFilename(src, filename);\n const a = globalThis.document.createElement(\"a\");\n a.href = url;\n a.download = resolvedFilename;\n a.click();\n URL.revokeObjectURL(url);\n onDownload?.({ success: true, filename: resolvedFilename });\n })\n .catch((err: unknown) => {\n onDownload?.({\n success: false,\n error:\n err instanceof Error ? err : new Error(\"Failed to download PDF\"),\n });\n });\n },\n [core.document, src, onDownload],\n );\n\n return useMemo(\n (): UsePdfViewerStateResult => ({\n ...core,\n zoomIn,\n zoomOut,\n toggleAutoSize,\n rotation,\n rotateLeft,\n rotateRight,\n sidebarOpen,\n sidebarMode,\n setSidebarMode,\n toggleSidebar,\n search,\n outlineItems,\n download,\n }),\n [\n core,\n zoomIn,\n zoomOut,\n toggleAutoSize,\n rotation,\n rotateLeft,\n rotateRight,\n sidebarOpen,\n sidebarMode,\n setSidebarMode,\n toggleSidebar,\n search,\n outlineItems,\n download,\n ],\n );\n}\n\n/** Derive a download filename from an explicit name, the src URL, or a fallback. */\nfunction resolveDownloadFilename(\n src: PdfSource,\n filename: string | undefined,\n): string {\n if (filename != null) {\n return filename;\n }\n if (typeof src === \"string\") {\n return src.split(\"/\").pop()?.split(\"?\")[0] || \"document.pdf\";\n }\n return \"document.pdf\";\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAASA,WAAW,EAAEC,SAAS,EAAEC,OAAO,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,OAAO;AAEzE,SACEC,SAAS,EACTC,SAAS,EACTC,sBAAsB,EACtBC,UAAU,QACL,iBAAiB;AAMxB,SAASC,aAAa,QAAQ,oBAAoB;AAKlD,SAASC,gBAAgB,QAAQ,uBAAuB;AAExD,SAASC,kBAAkB,QAAQ,yBAAyB;AA+C5D,OAAO,SAASC,iBAAiBA,CAAC;EAChCC,GAAG;EACHC,WAAW;EACXC,WAAW;EACXC,YAAY;EACZC,YAAY;EACZC,eAAe;EACfC,eAAe;EACfC,k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AAOA,QAAQ;EACjB;EACA,IAAI,OAAOtD,GAAG,KAAK,QAAQ,EAAE;IAC3B,OAAOA,GAAG,CAAC8E,KAAK,CAAC,GAAG,CAAC,CAACC,GAAG,CAAC,CAAC,EAAED,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,cAAc;EAC9D;EACA,OAAO,cAAc;AACvB","ignoreList":[]}
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
|
-
const PACKAGE_USER_AGENT = `osdk-react-components/${"0.
|
|
17
|
+
const PACKAGE_USER_AGENT = `osdk-react-components/${"0.57.0-main-e5dd4c9c26091761a0ff1ff5252089c6cf4072b3"}`;
|
|
18
18
|
export function componentUserAgent(componentName) {
|
|
19
19
|
return `${PACKAGE_USER_AGENT}/${componentName}`;
|
|
20
20
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UserAgent.js","names":["PACKAGE_USER_AGENT","componentUserAgent","componentName"],"sources":["UserAgent.ts"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nconst PACKAGE_USER_AGENT = `osdk-react-components/${process.env.PACKAGE_VERSION}`;\n\nexport function componentUserAgent(componentName: string): string {\n return `${PACKAGE_USER_AGENT}/${componentName}`;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,MAAMA,kBAAkB,GAAG,
|
|
1
|
+
{"version":3,"file":"UserAgent.js","names":["PACKAGE_USER_AGENT","componentUserAgent","componentName"],"sources":["UserAgent.ts"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nconst PACKAGE_USER_AGENT = `osdk-react-components/${process.env.PACKAGE_VERSION}`;\n\nexport function componentUserAgent(componentName: string): string {\n return `${PACKAGE_USER_AGENT}/${componentName}`;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,MAAMA,kBAAkB,GAAG,iFAAsD;AAEjF,OAAO,SAASC,kBAAkBA,CAACC,aAAqB,EAAU;EAChE,OAAO,GAAGF,kBAAkB,IAAIE,aAAa,EAAE;AACjD","ignoreList":[]}
|
|
@@ -152,18 +152,26 @@ interface BasePdfViewerProps {
|
|
|
152
152
|
*/
|
|
153
153
|
onHighlightDelete?: (event: PdfTextHighlightEvent) => void;
|
|
154
154
|
/** Initial page number (1-indexed, default 1) */
|
|
155
|
+
defaultPage?: number;
|
|
156
|
+
/** @deprecated Rename to `defaultPage`. */
|
|
155
157
|
initialPage?: number;
|
|
156
158
|
/** Initial zoom scale (default 1.0) */
|
|
159
|
+
defaultScale?: number;
|
|
160
|
+
/** @deprecated Rename to `defaultScale`. */
|
|
157
161
|
initialScale?: number;
|
|
158
162
|
/**
|
|
159
163
|
* Whether auto-size (fit to width) is initially enabled.
|
|
160
164
|
* When enabled, the PDF scales to fit the container width and
|
|
161
165
|
* re-fits automatically on resize. Manual zoom disables auto-size.
|
|
162
|
-
* Takes precedence over {@link
|
|
166
|
+
* Takes precedence over {@link defaultScale} when enabled.
|
|
163
167
|
* @default false
|
|
164
168
|
*/
|
|
169
|
+
defaultAutoSize?: boolean;
|
|
170
|
+
/** @deprecated Rename to `defaultAutoSize`. */
|
|
165
171
|
initialAutoSize?: boolean;
|
|
166
172
|
/** Whether the sidebar is initially open (default false) */
|
|
173
|
+
defaultSidebarOpen?: boolean;
|
|
174
|
+
/** @deprecated Rename to `defaultSidebarOpen`. */
|
|
167
175
|
initialSidebarOpen?: boolean;
|
|
168
176
|
/**
|
|
169
177
|
* Whether the download button is shown in the toolbar.
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var chunkDTYFQRFD_cjs = require('./chunk-DTYFQRFD.cjs');
|
|
4
|
-
var
|
|
4
|
+
var chunkE27ABWSC_cjs = require('./chunk-E27ABWSC.cjs');
|
|
5
5
|
|
|
6
6
|
// src/public/experimental/tiff-renderer.ts
|
|
7
|
-
var TiffViewer2 =
|
|
7
|
+
var TiffViewer2 = chunkE27ABWSC_cjs.withOsdkMetrics(chunkDTYFQRFD_cjs.TiffViewer, "TiffViewer");
|
|
8
8
|
var TiffRenderer = chunkDTYFQRFD_cjs.BaseTiffViewer;
|
|
9
9
|
var TiffViewerMedia = TiffViewer2;
|
|
10
10
|
|
|
11
11
|
exports.TiffRenderer = TiffRenderer;
|
|
12
12
|
exports.TiffViewer = TiffViewer2;
|
|
13
13
|
exports.TiffViewerMedia = TiffViewerMedia;
|
|
14
|
-
//# sourceMappingURL=chunk-
|
|
15
|
-
//# sourceMappingURL=chunk-
|
|
14
|
+
//# sourceMappingURL=chunk-32L4XMOU.cjs.map
|
|
15
|
+
//# sourceMappingURL=chunk-32L4XMOU.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/public/experimental/tiff-renderer.ts"],"names":["TiffViewer","withOsdkMetrics","BaseTiffViewer"],"mappings":";;;;;;AA4BO,IAAMA,WAAAA,GAAaC,iCAAA,CAAgBD,4BAAA,EAAa,YAAY;AAO5D,IAAM,YAAA,GAAeE;AAKrB,IAAM,eAAA,GAAkBF","file":"chunk-
|
|
1
|
+
{"version":3,"sources":["../../src/public/experimental/tiff-renderer.ts"],"names":["TiffViewer","withOsdkMetrics","BaseTiffViewer"],"mappings":";;;;;;AA4BO,IAAMA,WAAAA,GAAaC,iCAAA,CAAgBD,4BAAA,EAAa,YAAY;AAO5D,IAAM,YAAA,GAAeE;AAKrB,IAAM,eAAA,GAAkBF","file":"chunk-32L4XMOU.cjs","sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n// This subpath keeps its `tiff-renderer` name for now even though the\n// components it exports are named `TiffViewer`. It gets renamed when the\n// `experimental/` prefix is dropped, so consumers change import paths once\n// rather than twice.\n\nimport { BaseTiffViewer as _BaseTiffViewer } from \"../../images/tiff-viewer/BaseTiffViewer.js\";\nimport { TiffViewer as _TiffViewer } from \"../../images/tiff-viewer/TiffViewer.js\";\nimport { withOsdkMetrics } from \"../../util/withOsdkMetrics.js\";\n\n// BaseTiffViewer\nexport { BaseTiffViewer } from \"../../images/tiff-viewer/BaseTiffViewer.js\";\n// TiffViewer (Media wrapper)\nexport const TiffViewer = withOsdkMetrics(_TiffViewer, \"TiffViewer\");\n\n// Deprecated `Renderer` aliases of the same values, cleared in a later pass.\n// `TiffViewerMediaProps` has none: the `Media` drop is a uniform break because\n// pdf's old name was reused for a different type.\n\n/** @deprecated Use `BaseTiffViewer` instead. */\nexport const TiffRenderer = _BaseTiffViewer;\n\n/** @deprecated Use `BaseTiffViewerProps` instead. */\n\n/** @deprecated Use `TiffViewer` instead. */\nexport const TiffViewerMedia = TiffViewer;"]}
|