@osdk/react-components 0.2.0-beta.24 → 0.2.0-beta.25

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.
Files changed (115) hide show
  1. package/AGENTS.md +3 -0
  2. package/CHANGELOG.md +17 -0
  3. package/build/browser/action-form/FormFieldApi.js.map +1 -1
  4. package/build/browser/action-form/fields/{TextInputField.module.css → BaseInput.module.css} +2 -2
  5. package/build/browser/action-form/fields/BaseInput.module.css.js +6 -0
  6. package/build/browser/action-form/fields/FormFieldRenderer.js +26 -8
  7. package/build/browser/action-form/fields/FormFieldRenderer.js.map +1 -1
  8. package/build/browser/action-form/fields/RadioButtonsField.js +57 -0
  9. package/build/browser/action-form/fields/RadioButtonsField.js.map +1 -0
  10. package/build/browser/action-form/fields/RadioButtonsField.module.css +83 -0
  11. package/build/browser/action-form/fields/RadioButtonsField.module.css.js +10 -0
  12. package/build/browser/action-form/fields/TextAreaField.js +50 -0
  13. package/build/browser/action-form/fields/TextAreaField.js.map +1 -0
  14. package/build/browser/action-form/fields/TextInputField.js +3 -3
  15. package/build/browser/action-form/fields/TextInputField.js.map +1 -1
  16. package/build/browser/pdf-viewer/PdfViewer.js +40 -4
  17. package/build/browser/pdf-viewer/PdfViewer.js.map +1 -1
  18. package/build/browser/pdf-viewer/components/PdfViewerAnnotationLayer.js +85 -18
  19. package/build/browser/pdf-viewer/components/PdfViewerAnnotationLayer.js.map +1 -1
  20. package/build/browser/pdf-viewer/components/PdfViewerAnnotationLayer.module.css +18 -0
  21. package/build/browser/pdf-viewer/components/PdfViewerAnnotationLayer.module.css.js +1 -0
  22. package/build/browser/pdf-viewer/components/PdfViewerContent.js +15 -3
  23. package/build/browser/pdf-viewer/components/PdfViewerContent.js.map +1 -1
  24. package/build/browser/pdf-viewer/components/PdfViewerOutlineSidebar.module.css +1 -1
  25. package/build/browser/pdf-viewer/components/PdfViewerSidebar.module.css +1 -1
  26. package/build/browser/pdf-viewer/components/PdfViewerSidebarHeader.module.css +1 -1
  27. package/build/browser/pdf-viewer/components/PdfViewerToolbar.js +29 -2
  28. package/build/browser/pdf-viewer/components/PdfViewerToolbar.js.map +1 -1
  29. package/build/browser/pdf-viewer/components/PdfViewerToolbar.module.css +5 -0
  30. package/build/browser/pdf-viewer/components/PdfViewerToolbar.module.css.js +1 -0
  31. package/build/browser/pdf-viewer/constants.js +2 -1
  32. package/build/browser/pdf-viewer/constants.js.map +1 -1
  33. package/build/browser/pdf-viewer/hooks/usePdfAnnotationsByPage.js +30 -0
  34. package/build/browser/pdf-viewer/hooks/usePdfAnnotationsByPage.js.map +1 -0
  35. package/build/browser/pdf-viewer/hooks/usePdfFormFields.js +326 -0
  36. package/build/browser/pdf-viewer/hooks/usePdfFormFields.js.map +1 -0
  37. package/build/browser/pdf-viewer/hooks/usePdfHighlightMode.js +199 -0
  38. package/build/browser/pdf-viewer/hooks/usePdfHighlightMode.js.map +1 -0
  39. package/build/browser/pdf-viewer/hooks/usePdfViewer.js +16 -10
  40. package/build/browser/pdf-viewer/hooks/usePdfViewer.js.map +1 -1
  41. package/build/browser/pdf-viewer/types.js.map +1 -1
  42. package/build/browser/public/experimental.js +3 -0
  43. package/build/browser/public/experimental.js.map +1 -1
  44. package/build/browser/styles.css +144 -35
  45. package/build/cjs/public/experimental.cjs +1735 -1109
  46. package/build/cjs/public/experimental.cjs.map +1 -1
  47. package/build/cjs/public/experimental.css +82 -5
  48. package/build/cjs/public/experimental.css.map +1 -1
  49. package/build/cjs/public/experimental.d.cts +154 -20
  50. package/build/esm/action-form/FormFieldApi.js.map +1 -1
  51. package/build/esm/action-form/fields/{TextInputField.module.css → BaseInput.module.css} +2 -2
  52. package/build/esm/action-form/fields/FormFieldRenderer.js +26 -8
  53. package/build/esm/action-form/fields/FormFieldRenderer.js.map +1 -1
  54. package/build/esm/action-form/fields/RadioButtonsField.js +57 -0
  55. package/build/esm/action-form/fields/RadioButtonsField.js.map +1 -0
  56. package/build/esm/action-form/fields/RadioButtonsField.module.css +83 -0
  57. package/build/esm/action-form/fields/TextAreaField.js +50 -0
  58. package/build/esm/action-form/fields/TextAreaField.js.map +1 -0
  59. package/build/esm/action-form/fields/TextInputField.js +3 -3
  60. package/build/esm/action-form/fields/TextInputField.js.map +1 -1
  61. package/build/esm/pdf-viewer/PdfViewer.js +40 -4
  62. package/build/esm/pdf-viewer/PdfViewer.js.map +1 -1
  63. package/build/esm/pdf-viewer/components/PdfViewerAnnotationLayer.js +85 -18
  64. package/build/esm/pdf-viewer/components/PdfViewerAnnotationLayer.js.map +1 -1
  65. package/build/esm/pdf-viewer/components/PdfViewerAnnotationLayer.module.css +18 -0
  66. package/build/esm/pdf-viewer/components/PdfViewerContent.js +15 -3
  67. package/build/esm/pdf-viewer/components/PdfViewerContent.js.map +1 -1
  68. package/build/esm/pdf-viewer/components/PdfViewerOutlineSidebar.module.css +1 -1
  69. package/build/esm/pdf-viewer/components/PdfViewerSidebar.module.css +1 -1
  70. package/build/esm/pdf-viewer/components/PdfViewerSidebarHeader.module.css +1 -1
  71. package/build/esm/pdf-viewer/components/PdfViewerToolbar.js +29 -2
  72. package/build/esm/pdf-viewer/components/PdfViewerToolbar.js.map +1 -1
  73. package/build/esm/pdf-viewer/components/PdfViewerToolbar.module.css +5 -0
  74. package/build/esm/pdf-viewer/constants.js +2 -1
  75. package/build/esm/pdf-viewer/constants.js.map +1 -1
  76. package/build/esm/pdf-viewer/hooks/usePdfAnnotationsByPage.js +30 -0
  77. package/build/esm/pdf-viewer/hooks/usePdfAnnotationsByPage.js.map +1 -0
  78. package/build/esm/pdf-viewer/hooks/usePdfFormFields.js +326 -0
  79. package/build/esm/pdf-viewer/hooks/usePdfFormFields.js.map +1 -0
  80. package/build/esm/pdf-viewer/hooks/usePdfHighlightMode.js +199 -0
  81. package/build/esm/pdf-viewer/hooks/usePdfHighlightMode.js.map +1 -0
  82. package/build/esm/pdf-viewer/hooks/usePdfViewer.js +16 -10
  83. package/build/esm/pdf-viewer/hooks/usePdfViewer.js.map +1 -1
  84. package/build/esm/pdf-viewer/types.js.map +1 -1
  85. package/build/esm/public/experimental.js +3 -0
  86. package/build/esm/public/experimental.js.map +1 -1
  87. package/build/types/action-form/FormFieldApi.d.ts +8 -2
  88. package/build/types/action-form/FormFieldApi.d.ts.map +1 -1
  89. package/build/types/action-form/fields/FormFieldRenderer.d.ts.map +1 -1
  90. package/build/types/action-form/fields/RadioButtonsField.d.ts +3 -0
  91. package/build/types/action-form/fields/RadioButtonsField.d.ts.map +1 -0
  92. package/build/types/action-form/fields/TextAreaField.d.ts +3 -0
  93. package/build/types/action-form/fields/TextAreaField.d.ts.map +1 -0
  94. package/build/types/pdf-viewer/PdfViewer.d.ts +1 -1
  95. package/build/types/pdf-viewer/PdfViewer.d.ts.map +1 -1
  96. package/build/types/pdf-viewer/components/PdfViewerAnnotationLayer.d.ts.map +1 -1
  97. package/build/types/pdf-viewer/components/PdfViewerContent.d.ts +8 -4
  98. package/build/types/pdf-viewer/components/PdfViewerContent.d.ts.map +1 -1
  99. package/build/types/pdf-viewer/components/PdfViewerToolbar.d.ts +6 -1
  100. package/build/types/pdf-viewer/components/PdfViewerToolbar.d.ts.map +1 -1
  101. package/build/types/pdf-viewer/constants.d.ts +1 -1
  102. package/build/types/pdf-viewer/constants.d.ts.map +1 -1
  103. package/build/types/pdf-viewer/hooks/usePdfAnnotationsByPage.d.ts +5 -0
  104. package/build/types/pdf-viewer/hooks/usePdfAnnotationsByPage.d.ts.map +1 -0
  105. package/build/types/pdf-viewer/hooks/usePdfFormFields.d.ts +24 -0
  106. package/build/types/pdf-viewer/hooks/usePdfFormFields.d.ts.map +1 -0
  107. package/build/types/pdf-viewer/hooks/usePdfHighlightMode.d.ts +35 -0
  108. package/build/types/pdf-viewer/hooks/usePdfHighlightMode.d.ts.map +1 -0
  109. package/build/types/pdf-viewer/hooks/usePdfViewer.d.ts.map +1 -1
  110. package/build/types/pdf-viewer/types.d.ts +90 -13
  111. package/build/types/pdf-viewer/types.d.ts.map +1 -1
  112. package/build/types/public/experimental.d.ts +4 -1
  113. package/build/types/public/experimental.d.ts.map +1 -1
  114. package/package.json +5 -5
  115. package/build/browser/action-form/fields/TextInputField.module.css.js +0 -6
@@ -0,0 +1,50 @@
1
+ function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
2
+ /*
3
+ * Copyright 2026 Palantir Technologies, Inc. All rights reserved.
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+
18
+ import { Input } from "@base-ui/react/input";
19
+ import React, { useCallback } from "react";
20
+ import styles from "./BaseInput.module.css";
21
+ const TEXTAREA_STYLE = {
22
+ resize: "vertical"
23
+ };
24
+ export function TextAreaField({
25
+ id,
26
+ value,
27
+ onChange,
28
+ placeholder,
29
+ rows,
30
+ wrap,
31
+ minLength,
32
+ maxLength
33
+ }) {
34
+ const renderTextarea = useCallback(props => /*#__PURE__*/React.createElement("textarea", _extends({}, props, {
35
+ rows: rows,
36
+ wrap: wrap,
37
+ style: TEXTAREA_STYLE
38
+ })), [rows, wrap]);
39
+ return /*#__PURE__*/React.createElement(Input, {
40
+ id: id,
41
+ className: styles.osdkBaseInput,
42
+ value: value ?? "",
43
+ onValueChange: onChange,
44
+ placeholder: placeholder,
45
+ minLength: minLength,
46
+ maxLength: maxLength,
47
+ render: renderTextarea
48
+ });
49
+ }
50
+ //# sourceMappingURL=TextAreaField.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TextAreaField.js","names":["Input","React","useCallback","styles","TEXTAREA_STYLE","resize","TextAreaField","id","value","onChange","placeholder","rows","wrap","minLength","maxLength","renderTextarea","props","createElement","_extends","style","className","osdkBaseInput","onValueChange","render"],"sources":["TextAreaField.tsx"],"sourcesContent":["/*\n * Copyright 2026 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 { Input } from \"@base-ui/react/input\";\nimport React, { useCallback } from \"react\";\nimport type { TextAreaFieldProps } from \"../FormFieldApi.js\";\nimport styles from \"./BaseInput.module.css\";\n\nconst TEXTAREA_STYLE: React.CSSProperties = { resize: \"vertical\" };\n\nexport function TextAreaField({\n id,\n value,\n onChange,\n placeholder,\n rows,\n wrap,\n minLength,\n maxLength,\n}: TextAreaFieldProps): React.ReactElement {\n const renderTextarea = useCallback(\n (props: React.ComponentPropsWithRef<\"textarea\">) => (\n <textarea {...props} rows={rows} wrap={wrap} style={TEXTAREA_STYLE} />\n ),\n [rows, wrap],\n );\n\n return (\n <Input\n id={id}\n className={styles.osdkBaseInput}\n value={value ?? \"\"}\n onValueChange={onChange}\n placeholder={placeholder}\n minLength={minLength}\n maxLength={maxLength}\n render={renderTextarea}\n />\n );\n}\n"],"mappings":";AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAASA,KAAK,QAAQ,sBAAsB;AAC5C,OAAOC,KAAK,IAAIC,WAAW,QAAQ,OAAO;AAE1C,OAAOC,MAAM,MAAM,wBAAwB;AAE3C,MAAMC,cAAmC,GAAG;EAAEC,MAAM,EAAE;AAAW,CAAC;AAElE,OAAO,SAASC,aAAaA,CAAC;EAC5BC,EAAE;EACFC,KAAK;EACLC,QAAQ;EACRC,WAAW;EACXC,IAAI;EACJC,IAAI;EACJC,SAAS;EACTC;AACkB,CAAC,EAAsB;EACzC,MAAMC,cAAc,GAAGb,WAAW,CAC/Bc,KAA8C,iBAC7Cf,KAAA,CAAAgB,aAAA,aAAAC,QAAA,KAAcF,KAAK;IAAEL,IAAI,EAAEA,IAAK;IAACC,IAAI,EAAEA,IAAK;IAACO,KAAK,EAAEf;EAAe,EAAE,CACtE,EACD,CAACO,IAAI,EAAEC,IAAI,CACb,CAAC;EAED,oBACEX,KAAA,CAAAgB,aAAA,CAACjB,KAAK;IACJO,EAAE,EAAEA,EAAG;IACPa,SAAS,EAAEjB,MAAM,CAACkB,aAAc;IAChCb,KAAK,EAAEA,KAAK,IAAI,EAAG;IACnBc,aAAa,EAAEb,QAAS;IACxBC,WAAW,EAAEA,WAAY;IACzBG,SAAS,EAAEA,SAAU;IACrBC,SAAS,EAAEA,SAAU;IACrBS,MAAM,EAAER;EAAe,CACxB,CAAC;AAEN","ignoreList":[]}
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright 2025 Palantir Technologies, Inc. All rights reserved.
2
+ * Copyright 2026 Palantir Technologies, Inc. All rights reserved.
3
3
  *
4
4
  * Licensed under the Apache License, Version 2.0 (the "License");
5
5
  * you may not use this file except in compliance with the License.
@@ -16,7 +16,7 @@
16
16
 
17
17
  import { Input } from "@base-ui/react/input";
18
18
  import React from "react";
19
- import styles from "./TextInputField.module.css";
19
+ import styles from "./BaseInput.module.css";
20
20
  export function TextInputField({
21
21
  id,
22
22
  value,
@@ -27,7 +27,7 @@ export function TextInputField({
27
27
  }) {
28
28
  return /*#__PURE__*/React.createElement(Input, {
29
29
  id: id,
30
- className: styles.osdkTextInput,
30
+ className: styles.osdkBaseInput,
31
31
  type: "text",
32
32
  value: value ?? "",
33
33
  onValueChange: onChange,
@@ -1 +1 @@
1
- {"version":3,"file":"TextInputField.js","names":["Input","React","styles","TextInputField","id","value","onChange","placeholder","minLength","maxLength","createElement","className","osdkTextInput","type","onValueChange"],"sources":["TextInputField.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 { Input } from \"@base-ui/react/input\";\nimport React from \"react\";\nimport type { TextInputFieldProps } from \"../FormFieldApi.js\";\nimport styles from \"./TextInputField.module.css\";\n\nexport function TextInputField({\n id,\n value,\n onChange,\n placeholder,\n minLength,\n maxLength,\n}: TextInputFieldProps & { id?: string }): React.ReactElement {\n return (\n <Input\n id={id}\n className={styles.osdkTextInput}\n type=\"text\"\n value={value ?? \"\"}\n onValueChange={onChange}\n placeholder={placeholder}\n minLength={minLength}\n maxLength={maxLength}\n />\n );\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAASA,KAAK,QAAQ,sBAAsB;AAC5C,OAAOC,KAAK,MAAM,OAAO;AAEzB,OAAOC,MAAM,MAAM,6BAA6B;AAEhD,OAAO,SAASC,cAAcA,CAAC;EAC7BC,EAAE;EACFC,KAAK;EACLC,QAAQ;EACRC,WAAW;EACXC,SAAS;EACTC;AACqC,CAAC,EAAsB;EAC5D,oBACER,KAAA,CAAAS,aAAA,CAACV,KAAK;IACJI,EAAE,EAAEA,EAAG;IACPO,SAAS,EAAET,MAAM,CAACU,aAAc;IAChCC,IAAI,EAAC,MAAM;IACXR,KAAK,EAAEA,KAAK,IAAI,EAAG;IACnBS,aAAa,EAAER,QAAS;IACxBC,WAAW,EAAEA,WAAY;IACzBC,SAAS,EAAEA,SAAU;IACrBC,SAAS,EAAEA;EAAU,CACtB,CAAC;AAEN","ignoreList":[]}
1
+ {"version":3,"file":"TextInputField.js","names":["Input","React","styles","TextInputField","id","value","onChange","placeholder","minLength","maxLength","createElement","className","osdkBaseInput","type","onValueChange"],"sources":["TextInputField.tsx"],"sourcesContent":["/*\n * Copyright 2026 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 { Input } from \"@base-ui/react/input\";\nimport React from \"react\";\nimport type { TextInputFieldProps } from \"../FormFieldApi.js\";\nimport styles from \"./BaseInput.module.css\";\n\nexport function TextInputField({\n id,\n value,\n onChange,\n placeholder,\n minLength,\n maxLength,\n}: TextInputFieldProps & { id?: string }): React.ReactElement {\n return (\n <Input\n id={id}\n className={styles.osdkBaseInput}\n type=\"text\"\n value={value ?? \"\"}\n onValueChange={onChange}\n placeholder={placeholder}\n minLength={minLength}\n maxLength={maxLength}\n />\n );\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAASA,KAAK,QAAQ,sBAAsB;AAC5C,OAAOC,KAAK,MAAM,OAAO;AAEzB,OAAOC,MAAM,MAAM,wBAAwB;AAE3C,OAAO,SAASC,cAAcA,CAAC;EAC7BC,EAAE;EACFC,KAAK;EACLC,QAAQ;EACRC,WAAW;EACXC,SAAS;EACTC;AACqC,CAAC,EAAsB;EAC5D,oBACER,KAAA,CAAAS,aAAA,CAACV,KAAK;IACJI,EAAE,EAAEA,EAAG;IACPO,SAAS,EAAET,MAAM,CAACU,aAAc;IAChCC,IAAI,EAAC,MAAM;IACXR,KAAK,EAAEA,KAAK,IAAI,EAAG;IACnBS,aAAa,EAAER,QAAS;IACxBC,WAAW,EAAEA,WAAY;IACzBC,SAAS,EAAEA,SAAU;IACrBC,SAAS,EAAEA;EAAU,CACtB,CAAC;AAEN","ignoreList":[]}
@@ -24,14 +24,23 @@ import { PdfViewerOutlineSidebar } from "./components/PdfViewerOutlineSidebar.js
24
24
  import { PdfViewerSearchBar } from "./components/PdfViewerSearchBar.js";
25
25
  import { PdfViewerSidebar } from "./components/PdfViewerSidebar.js";
26
26
  import { PdfViewerToolbar } from "./components/PdfViewerToolbar.js";
27
- import { EMPTY_ANNOTATION_ARRAY, EMPTY_ANNOTATIONS } from "./constants.js";
27
+ import { EMPTY_ANNOTATION_ARRAY } from "./constants.js";
28
+ import { usePdfAnnotationsByPage } from "./hooks/usePdfAnnotationsByPage.js";
29
+ import { usePdfFormFields } from "./hooks/usePdfFormFields.js";
30
+ import { usePdfHighlightMode } from "./hooks/usePdfHighlightMode.js";
28
31
  import { usePdfViewerState } from "./hooks/usePdfViewerState.js";
29
32
  import styles from "./PdfViewer.module.css";
30
33
  export function BasePdfViewer({
31
34
  src,
32
- annotations = EMPTY_ANNOTATIONS,
35
+ annotations = EMPTY_ANNOTATION_ARRAY,
33
36
  onAnnotationClick,
34
37
  onDownload,
38
+ enableHighlight = false,
39
+ onTextHighlight,
40
+ onHighlightDelete,
41
+ formData,
42
+ onFormSubmit,
43
+ onFormChange,
35
44
  initialPage = 1,
36
45
  initialScale = 1.0,
37
46
  initialSidebarOpen = false,
@@ -48,6 +57,28 @@ export function BasePdfViewer({
48
57
  sidebarMode: sidebarModeProp,
49
58
  onDownload
50
59
  });
60
+ const {
61
+ highlightModeActive,
62
+ toggleHighlightMode
63
+ } = usePdfHighlightMode({
64
+ pdfViewerRef: viewer.pdfViewerRef,
65
+ document: viewer.document,
66
+ enabled: enableHighlight,
67
+ onTextHighlight,
68
+ onHighlightDelete
69
+ });
70
+ const {
71
+ hasFormFields,
72
+ submitFormData
73
+ } = usePdfFormFields({
74
+ pdfViewerRef: viewer.pdfViewerRef,
75
+ eventBusRef: viewer.eventBusRef,
76
+ document: viewer.document,
77
+ formData,
78
+ onFormSubmit,
79
+ onFormChange
80
+ });
81
+ const annotationsByPage = usePdfAnnotationsByPage(annotations);
51
82
  const rootClassName = classnames(styles.pdfViewer, className);
52
83
  if (viewer.loading) {
53
84
  return /*#__PURE__*/React.createElement("div", {
@@ -88,7 +119,12 @@ export function BasePdfViewer({
88
119
  onDownload: viewer.download,
89
120
  enableDownload: enableDownload,
90
121
  onRotateLeft: viewer.rotateLeft,
91
- onRotateRight: viewer.rotateRight
122
+ onRotateRight: viewer.rotateRight,
123
+ enableHighlight: enableHighlight,
124
+ highlightModeActive: highlightModeActive,
125
+ onHighlightToggle: toggleHighlightMode,
126
+ enableFormSave: onFormSubmit != null && hasFormFields,
127
+ onFormSave: submitFormData
92
128
  }), viewer.search.isSearchOpen && /*#__PURE__*/React.createElement(PdfViewerSearchBar, {
93
129
  query: viewer.search.query,
94
130
  totalMatches: viewer.search.totalMatches,
@@ -122,7 +158,7 @@ export function BasePdfViewer({
122
158
  ref: viewer.viewerRef,
123
159
  className: "pdfViewer"
124
160
  }), viewer.portalTargets.map(target => {
125
- const pageAnnotations = annotations[target.pageNumber] ?? EMPTY_ANNOTATION_ARRAY;
161
+ const pageAnnotations = annotationsByPage[target.pageNumber] ?? EMPTY_ANNOTATION_ARRAY;
126
162
  if (pageAnnotations.length === 0) {
127
163
  return null;
128
164
  }
@@ -1 +1 @@
1
- {"version":3,"file":"PdfViewer.js","names":["Error","ErrorIcon","Spin","classnames","React","createPortal","PdfViewerAnnotationLayer","PdfViewerOutlineSidebar","PdfViewerSearchBar","PdfViewerSidebar","PdfViewerToolbar","EMPTY_ANNOTATION_ARRAY","EMPTY_ANNOTATIONS","usePdfViewerState","styles","BasePdfViewer","src","annotations","onAnnotationClick","onDownload","initialPage","initialScale","initialSidebarOpen","enableDownload","sidebarMode","sidebarModeProp","outlineIcons","className","viewer","rootClassName","pdfViewer","loading","createElement","loadingContainer","spinnerIcon","error","errorContainer","errorIcon","message","document","currentPage","numPages","scale","sidebarOpen","onPageChange","scrollToPage","onScaleChange","setScale","onSearchOpen","search","openSearch","onSidebarToggle","toggleSidebar","download","onRotateLeft","rotateLeft","onRotateRight","rotateRight","isSearchOpen","query","totalMatches","currentMatchIndex","onQueryChange","setQuery","onNext","nextMatch","onPrev","prevMatch","onClose","closeSearch","contentArea","onPageClick","onSidebarModeChange","setSidebarMode","outlineItems","onItemClick","scrollContainerWrapper","ref","containerRef","scrollContainer","viewerRef","portalTargets","map","target","pageAnnotations","pageNumber","length","key","pageHeight","container"],"sources":["PdfViewer.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\";\nimport \"pdfjs-dist/web/pdf_viewer.css\";\nimport React from \"react\";\nimport { createPortal } from \"react-dom\";\nimport { PdfViewerAnnotationLayer } from \"./components/PdfViewerAnnotationLayer.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, EMPTY_ANNOTATIONS } from \"./constants.js\";\nimport { usePdfViewerState } from \"./hooks/usePdfViewerState.js\";\nimport styles from \"./PdfViewer.module.css\";\nimport type { PdfViewerProps } from \"./types.js\";\n\nexport function BasePdfViewer({\n src,\n annotations = EMPTY_ANNOTATIONS,\n onAnnotationClick,\n onDownload,\n initialPage = 1,\n initialScale = 1.0,\n initialSidebarOpen = false,\n enableDownload = false,\n sidebarMode: sidebarModeProp = \"thumbnails\",\n outlineIcons,\n className,\n}: PdfViewerProps): React.ReactElement {\n const viewer = usePdfViewerState({\n src,\n initialPage,\n initialScale,\n initialSidebarOpen,\n sidebarMode: sidebarModeProp,\n onDownload,\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 <PdfViewerToolbar\n currentPage={viewer.currentPage}\n numPages={viewer.numPages}\n scale={viewer.scale}\n sidebarOpen={viewer.sidebarOpen}\n onPageChange={viewer.scrollToPage}\n onScaleChange={viewer.setScale}\n onSearchOpen={viewer.search.openSearch}\n onSidebarToggle={viewer.toggleSidebar}\n onDownload={viewer.download}\n enableDownload={enableDownload}\n onRotateLeft={viewer.rotateLeft}\n onRotateRight={viewer.rotateRight}\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 = annotations[target.pageNumber]\n ?? EMPTY_ANNOTATION_ARRAY;\n if (pageAnnotations.length === 0) {\n return null;\n }\n return createPortal(\n <PdfViewerAnnotationLayer\n key={target.pageNumber}\n annotations={pageAnnotations}\n pageHeight={target.pageHeight}\n scale={target.scale}\n onAnnotationClick={onAnnotationClick}\n />,\n target.container,\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;AACnC,OAAO,+BAA+B;AACtC,OAAOC,KAAK,MAAM,OAAO;AACzB,SAASC,YAAY,QAAQ,WAAW;AACxC,SAASC,wBAAwB,QAAQ,0CAA0C;AACnF,SAASC,uBAAuB,QAAQ,yCAAyC;AACjF,SAASC,kBAAkB,QA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AACoD,SAAU;IAACrD,SAAS,EAAC;EAAW,CAAE,CAAC,EACnDC,MAAM,CAACqD,aAAa,CAACC,GAAG,CAAEC,MAAM,IAAK;IACpC,MAAMC,eAAe,GAAGnE,WAAW,CAACkE,MAAM,CAACE,UAAU,CAAC,IACjD1E,sBAAsB;IAC3B,IAAIyE,eAAe,CAACE,MAAM,KAAK,CAAC,EAAE;MAChC,OAAO,IAAI;IACb;IACA,oBAAOjF,YAAY,cACjBD,KAAA,CAAA4B,aAAA,CAAC1B,wBAAwB;MACvBiF,GAAG,EAAEJ,MAAM,CAACE,UAAW;MACvBpE,WAAW,EAAEmE,eAAgB;MAC7BI,UAAU,EAAEL,MAAM,CAACK,UAAW;MAC9B9C,KAAK,EAAEyC,MAAM,CAACzC,KAAM;MACpBxB,iBAAiB,EAAEA;IAAkB,CACtC,CAAC,EACFiE,MAAM,CAACM,SACT,CAAC;EACH,CAAC,CACE,CACF,CACF,CACF,CAAC;AAEV","ignoreList":[]}
1
+ {"version":3,"file":"PdfViewer.js","names":["Error","ErrorIcon","Spin","classnames","React","createPortal","PdfViewerAnnotationLayer","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","initialSidebarOpen","enableDownload","sidebarMode","sidebarModeProp","outlineIcons","className","viewer","highlightModeActive","toggleHighlightMode","pdfViewerRef","document","enabled","hasFormFields","submitFormData","eventBusRef","annotationsByPage","rootClassName","pdfViewer","loading","createElement","loadingContainer","spinnerIcon","error","errorContainer","errorIcon","message","currentPage","numPages","scale","sidebarOpen","onPageChange","scrollToPage","onScaleChange","setScale","onSearchOpen","search","openSearch","onSidebarToggle","toggleSidebar","download","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","ref","containerRef","scrollContainer","viewerRef","portalTargets","map","target","pageAnnotations","pageNumber","length","key","pageHeight","container"],"sources":["PdfViewer.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\";\nimport \"pdfjs-dist/web/pdf_viewer.css\";\nimport React from \"react\";\nimport { createPortal } from \"react-dom\";\nimport { PdfViewerAnnotationLayer } from \"./components/PdfViewerAnnotationLayer.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 styles from \"./PdfViewer.module.css\";\nimport type { PdfViewerProps } from \"./types.js\";\n\nexport function BasePdfViewer({\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 initialSidebarOpen = false,\n enableDownload = false,\n sidebarMode: sidebarModeProp = \"thumbnails\",\n outlineIcons,\n className,\n}: PdfViewerProps): React.ReactElement {\n const viewer = usePdfViewerState({\n src,\n initialPage,\n initialScale,\n initialSidebarOpen,\n sidebarMode: sidebarModeProp,\n onDownload,\n });\n\n const { highlightModeActive, toggleHighlightMode } = usePdfHighlightMode({\n pdfViewerRef: viewer.pdfViewerRef,\n document: viewer.document,\n enabled: enableHighlight,\n onTextHighlight,\n onHighlightDelete,\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 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 sidebarOpen={viewer.sidebarOpen}\n onPageChange={viewer.scrollToPage}\n onScaleChange={viewer.setScale}\n onSearchOpen={viewer.search.openSearch}\n onSidebarToggle={viewer.toggleSidebar}\n onDownload={viewer.download}\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 = annotationsByPage[target.pageNumber]\n ?? EMPTY_ANNOTATION_ARRAY;\n if (pageAnnotations.length === 0) {\n return null;\n }\n return createPortal(\n <PdfViewerAnnotationLayer\n key={target.pageNumber}\n annotations={pageAnnotations}\n pageHeight={target.pageHeight}\n scale={target.scale}\n onAnnotationClick={onAnnotationClick}\n />,\n target.container,\n );\n })}\n </div>\n </div>\n </div>\n </div>\n );\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;A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AAM,CAAC+D,SAAU;IAAChE,SAAS,EAAC;EAAW,CAAE,CAAC,EACnDC,MAAM,CAACgE,aAAa,CAACC,GAAG,CAAEC,MAAM,IAAK;IACpC,MAAMC,eAAe,GAAG1D,iBAAiB,CAACyD,MAAM,CAACE,UAAU,CAAC,IACvD7F,sBAAsB;IAC3B,IAAI4F,eAAe,CAACE,MAAM,KAAK,CAAC,EAAE;MAChC,OAAO,IAAI;IACb;IACA,oBAAOpG,YAAY,cACjBD,KAAA,CAAA6C,aAAA,CAAC3C,wBAAwB;MACvBoG,GAAG,EAAEJ,MAAM,CAACE,UAAW;MACvBrF,WAAW,EAAEoF,eAAgB;MAC7BI,UAAU,EAAEL,MAAM,CAACK,UAAW;MAC9BjD,KAAK,EAAE4C,MAAM,CAAC5C,KAAM;MACpBtC,iBAAiB,EAAEA;IAAkB,CACtC,CAAC,EACFkF,MAAM,CAACM,SACT,CAAC;EACH,CAAC,CACE,CACF,CACF,CACF,CAAC;AAEV","ignoreList":[]}
@@ -17,12 +17,19 @@
17
17
  import classnames from "classnames";
18
18
  import React, { useCallback, useMemo } from "react";
19
19
  import styles from "./PdfViewerAnnotationLayer.module.css";
20
- function AnnotationItem({
21
- annotation,
22
- pageHeight,
23
- scale,
24
- onClick
25
- }) {
20
+ /** Convert a single PDF rect (bottom-left origin) to CSS positioning (top-left origin). */
21
+ function computeRectStyle(rect, pageHeight, scale, color) {
22
+ return {
23
+ left: rect.x * scale,
24
+ top: (pageHeight - rect.y - rect.height) * scale,
25
+ width: rect.width * scale,
26
+ height: rect.height * scale,
27
+ ...(color != null ? {
28
+ "--osdk-pdf-annotation-color": color
29
+ } : {})
30
+ };
31
+ }
32
+ function useAnnotationHandlers(annotation, onClick) {
26
33
  const handleClick = useCallback(() => {
27
34
  onClick?.(annotation);
28
35
  }, [onClick, annotation]);
@@ -32,18 +39,45 @@ function AnnotationItem({
32
39
  onClick?.(annotation);
33
40
  }
34
41
  }, [onClick, annotation]);
35
-
36
- // Convert PDF coordinates (bottom-left origin) to CSS (top-left origin)
37
- const style = useMemo(() => ({
38
- left: annotation.rect.x * scale,
39
- top: (pageHeight - annotation.rect.y - annotation.rect.height) * scale,
40
- width: annotation.rect.width * scale,
41
- height: annotation.rect.height * scale,
42
- ...(annotation.color != null ? {
43
- "--osdk-pdf-annotation-color": annotation.color
44
- } : {})
45
- }), [annotation, pageHeight, scale]);
42
+ return {
43
+ handleClick,
44
+ handleKeyDown
45
+ };
46
+ }
47
+ function AnnotationItem({
48
+ annotation,
49
+ pageHeight,
50
+ scale,
51
+ onClick
52
+ }) {
53
+ const {
54
+ handleClick,
55
+ handleKeyDown
56
+ } = useAnnotationHandlers(annotation, onClick);
46
57
  const className = classnames(styles.annotation, styles[annotation.type]);
58
+ const multiRects = annotation.rects;
59
+ const hasMultipleRects = multiRects != null && multiRects.length > 1;
60
+ const style = useMemo(() => computeRectStyle(annotation.rect, pageHeight, scale, annotation.color), [annotation, pageHeight, scale]);
61
+
62
+ // Multi-rect: render a group wrapper with one div per rect
63
+ if (hasMultipleRects) {
64
+ return /*#__PURE__*/React.createElement("div", {
65
+ className: styles.annotationGroup,
66
+ onClick: handleClick,
67
+ onKeyDown: handleKeyDown,
68
+ role: "button",
69
+ tabIndex: 0,
70
+ title: annotation.label,
71
+ "data-annotation-id": annotation.id
72
+ }, multiRects.map((rect, i) => /*#__PURE__*/React.createElement("div", {
73
+ key: i,
74
+ className: className,
75
+ style: computeRectStyle(rect, pageHeight, scale, annotation.color)
76
+ })));
77
+ }
78
+
79
+ // Single rect: existing behavior
80
+
47
81
  return /*#__PURE__*/React.createElement("div", {
48
82
  className: className,
49
83
  style: style,
@@ -55,6 +89,33 @@ function AnnotationItem({
55
89
  "data-annotation-id": annotation.id
56
90
  });
57
91
  }
92
+ function CustomAnnotationItem({
93
+ annotation,
94
+ pageHeight,
95
+ scale,
96
+ onClick
97
+ }) {
98
+ const {
99
+ handleClick,
100
+ handleKeyDown
101
+ } = useAnnotationHandlers(annotation, onClick);
102
+ const style = useMemo(() => computeRectStyle(annotation.rect, pageHeight, scale, undefined), [annotation, pageHeight, scale]);
103
+ const renderProps = useMemo(() => ({
104
+ annotation,
105
+ scale,
106
+ pageHeight
107
+ }), [annotation, scale, pageHeight]);
108
+ return /*#__PURE__*/React.createElement("div", {
109
+ className: styles.annotation,
110
+ style: style,
111
+ onClick: handleClick,
112
+ onKeyDown: handleKeyDown,
113
+ role: "button",
114
+ tabIndex: 0,
115
+ title: annotation.label,
116
+ "data-annotation-id": annotation.id
117
+ }, annotation.render(renderProps));
118
+ }
58
119
  export function PdfViewerAnnotationLayer({
59
120
  annotations,
60
121
  pageHeight,
@@ -63,7 +124,13 @@ export function PdfViewerAnnotationLayer({
63
124
  }) {
64
125
  return /*#__PURE__*/React.createElement("div", {
65
126
  className: styles.annotationLayer
66
- }, annotations.map(annotation => /*#__PURE__*/React.createElement(AnnotationItem, {
127
+ }, annotations.map(annotation => annotation.type === "custom" ? /*#__PURE__*/React.createElement(CustomAnnotationItem, {
128
+ key: annotation.id,
129
+ annotation: annotation,
130
+ pageHeight: pageHeight,
131
+ scale: scale,
132
+ onClick: onAnnotationClick
133
+ }) : /*#__PURE__*/React.createElement(AnnotationItem, {
67
134
  key: annotation.id,
68
135
  annotation: annotation,
69
136
  pageHeight: pageHeight,
@@ -1 +1 @@
1
- {"version":3,"file":"PdfViewerAnnotationLayer.js","names":["classnames","React","useCallback","useMemo","styles","AnnotationItem","annotation","pageHeight","scale","onClick","handleClick","handleKeyDown","e","key","preventDefault","style","left","rect","x","top","y","height","width","color","className","type","createElement","onKeyDown","role","tabIndex","title","label","id","PdfViewerAnnotationLayer","annotations","onAnnotationClick","annotationLayer","map"],"sources":["PdfViewerAnnotationLayer.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 classnames from \"classnames\";\nimport React, { useCallback, useMemo } from \"react\";\nimport type { PdfAnnotation } from \"../types.js\";\nimport styles from \"./PdfViewerAnnotationLayer.module.css\";\n\nexport interface PdfViewerAnnotationLayerProps {\n annotations: PdfAnnotation[];\n pageHeight: number;\n scale: number;\n onAnnotationClick?: (annotation: PdfAnnotation) => void;\n}\n\ninterface AnnotationItemProps {\n annotation: PdfAnnotation;\n pageHeight: number;\n scale: number;\n onClick?: (annotation: PdfAnnotation) => void;\n}\n\nfunction AnnotationItem({\n annotation,\n pageHeight,\n scale,\n onClick,\n}: AnnotationItemProps): React.ReactElement {\n const handleClick = useCallback(() => {\n onClick?.(annotation);\n }, [onClick, annotation]);\n\n const handleKeyDown = useCallback(\n (e: React.KeyboardEvent) => {\n if (e.key === \"Enter\") {\n e.preventDefault();\n onClick?.(annotation);\n }\n },\n [onClick, annotation],\n );\n\n // Convert PDF coordinates (bottom-left origin) to CSS (top-left origin)\n const style = useMemo(\n () => ({\n left: annotation.rect.x * scale,\n top: (pageHeight - annotation.rect.y - annotation.rect.height) * scale,\n width: annotation.rect.width * scale,\n height: annotation.rect.height * scale,\n ...(annotation.color != null\n ? {\n \"--osdk-pdf-annotation-color\": annotation.color,\n } as React.CSSProperties\n : {}),\n }),\n [annotation, pageHeight, scale],\n );\n\n const className = classnames(\n styles.annotation,\n styles[annotation.type],\n );\n\n return (\n <div\n className={className}\n style={style}\n onClick={handleClick}\n onKeyDown={handleKeyDown}\n role=\"button\"\n tabIndex={0}\n title={annotation.label}\n data-annotation-id={annotation.id}\n />\n );\n}\n\nexport function PdfViewerAnnotationLayer({\n annotations,\n pageHeight,\n scale,\n onAnnotationClick,\n}: PdfViewerAnnotationLayerProps): React.ReactElement {\n return (\n <div className={styles.annotationLayer}>\n {annotations.map((annotation) => (\n <AnnotationItem\n key={annotation.id}\n annotation={annotation}\n pageHeight={pageHeight}\n scale={scale}\n onClick={onAnnotationClick}\n />\n ))}\n </div>\n );\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,OAAOA,UAAU,MAAM,YAAY;AACnC,OAAOC,KAAK,IAAIC,WAAW,EAAEC,OAAO,QAAQ,OAAO;AAEnD,OAAOC,MAAM,MAAM,uCAAuC;AAgB1D,SAASC,cAAcA,CAAC;EACtBC,UAAU;EACVC,UAAU;EACVC,KAAK;EACLC;AACmB,CAAC,EAAsB;EAC1C,MAAMC,WAAW,GAAGR,WAAW,CAAC,MAAM;IACpCO,OAAO,GAAGH,UAAU,CAAC;EACvB,CAAC,EAAE,CAACG,OAAO,EAAEH,UAAU,CAAC,CAAC;EAEzB,MAAMK,aAAa,GAAGT,WAAW,CAC9BU,CAAsB,IAAK;IAC1B,IAAIA,CAAC,CAACC,GAAG,KAAK,OAAO,EAAE;MACrBD,CAAC,CAACE,cAAc,CAAC,CAAC;MAClBL,OAAO,GAAGH,UAAU,CAAC;IACvB;EACF,CAAC,EACD,CAACG,OAAO,EAAEH,UAAU,CACtB,CAAC;;EAED;EACA,MAAMS,KAAK,GAAGZ,OAAO,CACnB,OAAO;IACLa,IAAI,EAAEV,UAAU,CAACW,IAAI,CAACC,CAAC,GAAGV,KAAK;IAC/BW,GAAG,EAAE,CAACZ,UAAU,GAAGD,UAAU,CAACW,IAAI,CAACG,CAAC,GAAGd,UAAU,CAACW,IAAI,CAACI,MAAM,IAAIb,KAAK;IACtEc,KAAK,EAAEhB,UAAU,CAACW,IAAI,CAACK,KAAK,GAAGd,KAAK;IACpCa,MAAM,EAAEf,UAAU,CAACW,IAAI,CAACI,MAAM,GAAGb,KAAK;IACtC,IAAIF,UAAU,CAACiB,KAAK,IAAI,IAAI,GACxB;MACA,6BAA6B,EAAEjB,UAAU,CAACiB;IAC5C,CAAC,GACC,CAAC,CAAC;EACR,CAAC,CAAC,EACF,CAACjB,UAAU,EAAEC,UAAU,EAAEC,KAAK,CAChC,CAAC;EAED,MAAMgB,SAAS,GAAGxB,UAAU,CAC1BI,MAAM,CAACE,UAAU,EACjBF,MAAM,CAACE,UAAU,CAACmB,IAAI,CACxB,CAAC;EAED,oBACExB,KAAA,CAAAyB,aAAA;IACEF,SAAS,EAAEA,SAAU;IACrBT,KAAK,EAAEA,KAAM;IACbN,OAAO,EAAEC,WAAY;IACrBiB,SAAS,EAAEhB,aAAc;IACzBiB,IAAI,EAAC,QAAQ;IACbC,QAAQ,EAAE,CAAE;IACZC,KAAK,EAAExB,UAAU,CAACyB,KAAM;IACxB,sBAAoBzB,UAAU,CAAC0B;EAAG,CACnC,CAAC;AAEN;AAEA,OAAO,SAASC,wBAAwBA,CAAC;EACvCC,WAAW;EACX3B,UAAU;EACVC,KAAK;EACL2B;AAC6B,CAAC,EAAsB;EACpD,oBACElC,KAAA,CAAAyB,aAAA;IAAKF,SAAS,EAAEpB,MAAM,CAACgC;EAAgB,GACpCF,WAAW,CAACG,GAAG,CAAE/B,UAAU,iBAC1BL,KAAA,CAAAyB,aAAA,CAACrB,cAAc;IACbQ,GAAG,EAAEP,UAAU,CAAC0B,EAAG;IACnB1B,UAAU,EAAEA,UAAW;IACvBC,UAAU,EAAEA,UAAW;IACvBC,KAAK,EAAEA,KAAM;IACbC,OAAO,EAAE0B;EAAkB,CAC5B,CACF,CACE,CAAC;AAEV","ignoreList":[]}
1
+ {"version":3,"file":"PdfViewerAnnotationLayer.js","names":["classnames","React","useCallback","useMemo","styles","computeRectStyle","rect","pageHeight","scale","color","left","x","top","y","height","width","useAnnotationHandlers","annotation","onClick","handleClick","handleKeyDown","e","key","preventDefault","AnnotationItem","className","type","multiRects","rects","hasMultipleRects","length","style","createElement","annotationGroup","onKeyDown","role","tabIndex","title","label","id","map","i","CustomAnnotationItem","undefined","renderProps","render","PdfViewerAnnotationLayer","annotations","onAnnotationClick","annotationLayer"],"sources":["PdfViewerAnnotationLayer.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 classnames from \"classnames\";\nimport React, { useCallback, useMemo } from \"react\";\nimport type { PdfAnnotation, PdfCustomAnnotation, PdfRect } from \"../types.js\";\nimport styles from \"./PdfViewerAnnotationLayer.module.css\";\n\nexport interface PdfViewerAnnotationLayerProps {\n annotations: PdfAnnotation[];\n pageHeight: number;\n scale: number;\n onAnnotationClick?: (annotation: PdfAnnotation) => void;\n}\n\ninterface AnnotationItemProps {\n annotation: PdfAnnotation;\n pageHeight: number;\n scale: number;\n onClick?: (annotation: PdfAnnotation) => void;\n}\n\n/** Convert a single PDF rect (bottom-left origin) to CSS positioning (top-left origin). */\nfunction computeRectStyle(\n rect: PdfRect,\n pageHeight: number,\n scale: number,\n color: string | undefined,\n): React.CSSProperties {\n return {\n left: rect.x * scale,\n top: (pageHeight - rect.y - rect.height) * scale,\n width: rect.width * scale,\n height: rect.height * scale,\n ...(color != null\n ? { \"--osdk-pdf-annotation-color\": color } as React.CSSProperties\n : {}),\n };\n}\n\nfunction useAnnotationHandlers(\n annotation: PdfAnnotation,\n onClick?: (annotation: PdfAnnotation) => void,\n) {\n const handleClick = useCallback(() => {\n onClick?.(annotation);\n }, [onClick, annotation]);\n\n const handleKeyDown = useCallback(\n (e: React.KeyboardEvent) => {\n if (e.key === \"Enter\") {\n e.preventDefault();\n onClick?.(annotation);\n }\n },\n [onClick, annotation],\n );\n\n return { handleClick, handleKeyDown };\n}\n\nfunction AnnotationItem({\n annotation,\n pageHeight,\n scale,\n onClick,\n}: AnnotationItemProps): React.ReactElement {\n const { handleClick, handleKeyDown } = useAnnotationHandlers(\n annotation,\n onClick,\n );\n\n const className = classnames(\n styles.annotation,\n styles[annotation.type],\n );\n\n const multiRects = annotation.rects;\n const hasMultipleRects = multiRects != null && multiRects.length > 1;\n\n const style = useMemo(\n () =>\n computeRectStyle(annotation.rect, pageHeight, scale, annotation.color),\n [annotation, pageHeight, scale],\n );\n\n // Multi-rect: render a group wrapper with one div per rect\n if (hasMultipleRects) {\n return (\n <div\n className={styles.annotationGroup}\n onClick={handleClick}\n onKeyDown={handleKeyDown}\n role=\"button\"\n tabIndex={0}\n title={annotation.label}\n data-annotation-id={annotation.id}\n >\n {multiRects.map((rect, i) => (\n <div\n key={i}\n className={className}\n style={computeRectStyle(\n rect,\n pageHeight,\n scale,\n annotation.color,\n )}\n />\n ))}\n </div>\n );\n }\n\n // Single rect: existing behavior\n\n return (\n <div\n className={className}\n style={style}\n onClick={handleClick}\n onKeyDown={handleKeyDown}\n role=\"button\"\n tabIndex={0}\n title={annotation.label}\n data-annotation-id={annotation.id}\n />\n );\n}\n\nfunction CustomAnnotationItem({\n annotation,\n pageHeight,\n scale,\n onClick,\n}: AnnotationItemProps & {\n annotation: PdfCustomAnnotation;\n}): React.ReactElement {\n const { handleClick, handleKeyDown } = useAnnotationHandlers(\n annotation,\n onClick,\n );\n\n const style = useMemo(\n () => computeRectStyle(annotation.rect, pageHeight, scale, undefined),\n [annotation, pageHeight, scale],\n );\n\n const renderProps = useMemo(\n () => ({ annotation, scale, pageHeight }),\n [annotation, scale, pageHeight],\n );\n\n return (\n <div\n className={styles.annotation}\n style={style}\n onClick={handleClick}\n onKeyDown={handleKeyDown}\n role=\"button\"\n tabIndex={0}\n title={annotation.label}\n data-annotation-id={annotation.id}\n >\n {annotation.render(renderProps)}\n </div>\n );\n}\n\nexport function PdfViewerAnnotationLayer({\n annotations,\n pageHeight,\n scale,\n onAnnotationClick,\n}: PdfViewerAnnotationLayerProps): React.ReactElement {\n return (\n <div className={styles.annotationLayer}>\n {annotations.map((annotation) =>\n annotation.type === \"custom\"\n ? (\n <CustomAnnotationItem\n key={annotation.id}\n annotation={annotation}\n pageHeight={pageHeight}\n scale={scale}\n onClick={onAnnotationClick}\n />\n )\n : (\n <AnnotationItem\n key={annotation.id}\n annotation={annotation}\n pageHeight={pageHeight}\n scale={scale}\n onClick={onAnnotationClick}\n />\n )\n )}\n </div>\n );\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,OAAOA,UAAU,MAAM,YAAY;AACnC,OAAOC,KAAK,IAAIC,WAAW,EAAEC,OAAO,QAAQ,OAAO;AAEnD,OAAOC,MAAM,MAAM,uCAAuC;AAgB1D;AACA,SAASC,gBAAgBA,CACvBC,IAAa,EACbC,UAAkB,EAClBC,KAAa,EACbC,KAAyB,EACJ;EACrB,OAAO;IACLC,IAAI,EAAEJ,IAAI,CAACK,CAAC,GAAGH,KAAK;IACpBI,GAAG,EAAE,CAACL,UAAU,GAAGD,IAAI,CAACO,CAAC,GAAGP,IAAI,CAACQ,MAAM,IAAIN,KAAK;IAChDO,KAAK,EAAET,IAAI,CAACS,KAAK,GAAGP,KAAK;IACzBM,MAAM,EAAER,IAAI,CAACQ,MAAM,GAAGN,KAAK;IAC3B,IAAIC,KAAK,IAAI,IAAI,GACb;MAAE,6BAA6B,EAAEA;IAAM,CAAC,GACxC,CAAC,CAAC;EACR,CAAC;AACH;AAEA,SAASO,qBAAqBA,CAC5BC,UAAyB,EACzBC,OAA6C,EAC7C;EACA,MAAMC,WAAW,GAAGjB,WAAW,CAAC,MAAM;IACpCgB,OAAO,GAAGD,UAAU,CAAC;EACvB,CAAC,EAAE,CAACC,OAAO,EAAED,UAAU,CAAC,CAAC;EAEzB,MAAMG,aAAa,GAAGlB,WAAW,CAC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IACxB,sBAAoBrB,UAAU,CAACsB;EAAG,GAEjCtB,UAAU,CAAC4B,MAAM,CAACD,WAAW,CAC3B,CAAC;AAEV;AAEA,OAAO,SAASE,wBAAwBA,CAAC;EACvCC,WAAW;EACXxC,UAAU;EACVC,KAAK;EACLwC;AAC6B,CAAC,EAAsB;EACpD,oBACE/C,KAAA,CAAA+B,aAAA;IAAKP,SAAS,EAAErB,MAAM,CAAC6C;EAAgB,GACpCF,WAAW,CAACP,GAAG,CAAEvB,UAAU,IAC1BA,UAAU,CAACS,IAAI,KAAK,QAAQ,gBAExBzB,KAAA,CAAA+B,aAAA,CAACU,oBAAoB;IACnBpB,GAAG,EAAEL,UAAU,CAACsB,EAAG;IACnBtB,UAAU,EAAEA,UAAW;IACvBV,UAAU,EAAEA,UAAW;IACvBC,KAAK,EAAEA,KAAM;IACbU,OAAO,EAAE8B;EAAkB,CAC5B,CAAC,gBAGF/C,KAAA,CAAA+B,aAAA,CAACR,cAAc;IACbF,GAAG,EAAEL,UAAU,CAACsB,EAAG;IACnBtB,UAAU,EAAEA,UAAW;IACvBV,UAAU,EAAEA,UAAW;IACvBC,KAAK,EAAEA,KAAM;IACbU,OAAO,EAAE8B;EAAkB,CAC5B,CAEP,CACG,CAAC;AAEV","ignoreList":[]}
@@ -8,6 +8,24 @@
8
8
  z-index: 3;
9
9
  }
10
10
 
11
+ .annotationGroup {
12
+ position: absolute;
13
+ top: 0;
14
+ left: 0;
15
+ width: 100%;
16
+ height: 100%;
17
+ pointer-events: none;
18
+ }
19
+
20
+ .annotationGroup:focus-visible {
21
+ outline: var(--osdk-focus-outline);
22
+ outline-offset: var(--osdk-focus-visible-outline-offset);
23
+ }
24
+
25
+ .annotationGroup .annotation {
26
+ pointer-events: auto;
27
+ }
28
+
11
29
  .annotation {
12
30
  position: absolute;
13
31
  pointer-events: auto;
@@ -19,18 +19,22 @@ import classnames from "classnames";
19
19
  import "pdfjs-dist/web/pdf_viewer.css";
20
20
  import React, { useEffect, useRef } from "react";
21
21
  import { createPortal } from "react-dom";
22
- import { EMPTY_ANNOTATION_ARRAY, EMPTY_ANNOTATIONS } from "../constants.js";
22
+ import { EMPTY_ANNOTATION_ARRAY } from "../constants.js";
23
+ import { usePdfAnnotationsByPage } from "../hooks/usePdfAnnotationsByPage.js";
24
+ import { usePdfFormFields } from "../hooks/usePdfFormFields.js";
23
25
  import { usePdfViewerCore } from "../hooks/usePdfViewerCore.js";
24
26
  import styles from "../PdfViewer.module.css";
25
27
  import { PdfViewerAnnotationLayer } from "./PdfViewerAnnotationLayer.js";
26
28
  export function PdfViewerContent({
27
29
  src,
28
- annotations = EMPTY_ANNOTATIONS,
30
+ annotations = EMPTY_ANNOTATION_ARRAY,
29
31
  onAnnotationClick,
30
32
  initialPage = 1,
31
33
  initialScale = 1.0,
32
34
  onPageChange: onPageChangeProp,
33
35
  onScaleChange: onScaleChangeProp,
36
+ formData,
37
+ onFormChange,
34
38
  className
35
39
  }) {
36
40
  const viewer = usePdfViewerCore({
@@ -38,6 +42,14 @@ export function PdfViewerContent({
38
42
  initialPage,
39
43
  initialScale
40
44
  });
45
+ const annotationsByPage = usePdfAnnotationsByPage(annotations);
46
+ usePdfFormFields({
47
+ pdfViewerRef: viewer.pdfViewerRef,
48
+ eventBusRef: viewer.eventBusRef,
49
+ document: viewer.document,
50
+ formData,
51
+ onFormChange
52
+ });
41
53
 
42
54
  // Use refs for callbacks to avoid firing on initial mount
43
55
  const onPageChangeRef = useRef(onPageChangeProp);
@@ -97,7 +109,7 @@ export function PdfViewerContent({
97
109
  ref: viewer.viewerRef,
98
110
  className: "pdfViewer"
99
111
  }), viewer.portalTargets.map(target => {
100
- const pageAnnotations = annotations[target.pageNumber] ?? EMPTY_ANNOTATION_ARRAY;
112
+ const pageAnnotations = annotationsByPage[target.pageNumber] ?? EMPTY_ANNOTATION_ARRAY;
101
113
  if (pageAnnotations.length === 0) {
102
114
  return null;
103
115
  }
@@ -1 +1 @@
1
- {"version":3,"file":"PdfViewerContent.js","names":["Error","ErrorIcon","Spin","classnames","React","useEffect","useRef","createPortal","EMPTY_ANNOTATION_ARRAY","EMPTY_ANNOTATIONS","usePdfViewerCore","styles","PdfViewerAnnotationLayer","PdfViewerContent","src","annotations","onAnnotationClick","initialPage","initialScale","onPageChange","onPageChangeProp","onScaleChange","onScaleChangeProp","className","viewer","onPageChangeRef","current","onScaleChangeRef","isInitialMountRef","currentPage","scale","rootClassName","pdfViewer","loading","createElement","loadingContainer","spinnerIcon","error","errorContainer","errorIcon","message","document","scrollContainerWrapper","ref","containerRef","scrollContainer","viewerRef","portalTargets","map","target","pageAnnotations","pageNumber","length","key","pageHeight","container"],"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\";\nimport \"pdfjs-dist/web/pdf_viewer.css\";\nimport React, { useEffect, useRef } from \"react\";\nimport { createPortal } from \"react-dom\";\nimport { EMPTY_ANNOTATION_ARRAY, EMPTY_ANNOTATIONS } from \"../constants.js\";\nimport { usePdfViewerCore } from \"../hooks/usePdfViewerCore.js\";\nimport styles from \"../PdfViewer.module.css\";\nimport type { PdfAnnotation } from \"../types.js\";\nimport { PdfViewerAnnotationLayer } from \"./PdfViewerAnnotationLayer.js\";\n\nexport interface PdfViewerContentProps {\n /** PDF source — URL string or ArrayBuffer */\n src: string | ArrayBuffer;\n /** Annotations to overlay on the PDF, keyed by page number (1-indexed) */\n annotations?: Record<number, 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 /** Additional CSS class name for the root element */\n className?: string;\n}\n\nexport function PdfViewerContent({\n src,\n annotations = EMPTY_ANNOTATIONS,\n onAnnotationClick,\n initialPage = 1,\n initialScale = 1.0,\n onPageChange: onPageChangeProp,\n onScaleChange: onScaleChangeProp,\n className,\n}: PdfViewerContentProps): React.ReactElement {\n const viewer = usePdfViewerCore({ src, initialPage, initialScale });\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(function notifyPageChange() {\n if (isInitialMountRef.current) {\n return;\n }\n onPageChangeRef.current?.(viewer.currentPage);\n }, [viewer.currentPage]);\n\n useEffect(function notifyScaleChange() {\n if (isInitialMountRef.current) {\n return;\n }\n onScaleChangeRef.current?.(viewer.scale);\n }, [viewer.scale]);\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 = annotations[target.pageNumber]\n ?? EMPTY_ANNOTATION_ARRAY;\n if (pageAnnotations.length === 0) {\n return null;\n }\n return createPortal(\n <PdfViewerAnnotationLayer\n key={target.pageNumber}\n annotations={pageAnnotations}\n pageHeight={target.pageHeight}\n scale={target.scale}\n onAnnotationClick={onAnnotationClick}\n />,\n target.container,\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;AACnC,OAAO,+BAA+B;AACtC,OAAOC,KAAK,IAAIC,SAAS,EAAEC,MAAM,QAAQ,OAAO;AAChD,SAASC,YAAY,QAAQ,WAAW;AACxC,SAASC,sBAAsB,EAAEC,iBAAiB,QAAQ,iBAAiB;AAC3E,SAASC,gBAAgB,QAAQ,8BAA8B;AAC/D,OAAOC,MAAM,MAAM,yBAAyB;AAE5C,SAASC,wBAAwB,QAAQ,+BAA+B;AAqBxE,OAAO,SAASC,gBAAgBA,CAAC;EAC/BC,GAAG;EACHC,WAAW,GAAGN,iBAAiB;EAC/BO,iBAAiB;EACjBC,WAAW,GAAG,CAAC;EACfC,YAAY,GAAG,GAAG;EAClBC,YAAY,EAAEC,gBAAgB;EAC9BC,aAAa,EAAEC,iBAAiB;EAChCC;AACqB,CAAC,EAAsB;EAC5C,MAAMC,MAAM,GAAGd,gBAAgB,CAAC;IAAEI,GAAG;IAAEG,WAAW;IAAEC;EAAa,CAAC,CAAC;;EAEnE;EACA,MAAMO,eAAe,GAAGnB,MAAM,CAACc,gBAAgB,CAAC;EAChDK,eAAe,CAACC,OAAO,GA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AAC,CACE,CACF,CACF,CAAC;AAEV","ignoreList":[]}
1
+ {"version":3,"file":"PdfViewerContent.js","names":["Error","ErrorIcon","Spin","classnames","React","useEffect","useRef","createPortal","EMPTY_ANNOTATION_ARRAY","usePdfAnnotationsByPage","usePdfFormFields","usePdfViewerCore","styles","PdfViewerAnnotationLayer","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","pageHeight","container"],"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\";\nimport \"pdfjs-dist/web/pdf_viewer.css\";\nimport React, { useEffect, useRef } from \"react\";\nimport { createPortal } from \"react-dom\";\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 styles from \"../PdfViewer.module.css\";\nimport type { PdfAnnotation, PdfFormFieldValue } from \"../types.js\";\nimport { PdfViewerAnnotationLayer } from \"./PdfViewerAnnotationLayer.js\";\n\nexport interface PdfViewerContentProps {\n /** PDF source — URL string or ArrayBuffer */\n src: string | ArrayBuffer;\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,\n initialScale = 1.0,\n onPageChange: onPageChangeProp,\n onScaleChange: onScaleChangeProp,\n formData,\n onFormChange,\n className,\n}: PdfViewerContentProps): React.ReactElement {\n const viewer = usePdfViewerCore({ src, initialPage, initialScale });\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(function notifyPageChange() {\n if (isInitialMountRef.current) {\n return;\n }\n onPageChangeRef.current?.(viewer.currentPage);\n }, [viewer.currentPage]);\n\n useEffect(function notifyScaleChange() {\n if (isInitialMountRef.current) {\n return;\n }\n onScaleChangeRef.current?.(viewer.scale);\n }, [viewer.scale]);\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 = annotationsByPage[target.pageNumber]\n ?? EMPTY_ANNOTATION_ARRAY;\n if (pageAnnotations.length === 0) {\n return null;\n }\n return createPortal(\n <PdfViewerAnnotationLayer\n key={target.pageNumber}\n annotations={pageAnnotations}\n pageHeight={target.pageHeight}\n scale={target.scale}\n onAnnotationClick={onAnnotationClick}\n />,\n target.container,\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;AACnC,OAAO,+BAA+B;AACtC,OAAOC,KAAK,IAAIC,SAAS,EAAEC,MAAM,QAAQ,OAAO;AAChD,SAASC,YAAY,QAAQ,WAAW;AACxC,SAASC,sBAAsB,QAAQ,iBAAiB;AACxD,SAASC,uBAAuB,QAAQ,qCAAqC;AAC7E,SAASC,gBAAgB,QAAQ,8BAA8B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AA;IAAKf,SAAS,EAAEd,MAAM,CAACoC;EAAuB,gBAC5C5C,KAAA,CAAAqC,aAAA;IAAKQ,GAAG,EAAEtB,MAAM,CAACuB,YAAa;IAACxB,SAAS,EAAEd,MAAM,CAACuC;EAAgB,gBAC/D/C,KAAA,CAAAqC,aAAA;IAAKQ,GAAG,EAAEtB,MAAM,CAACyB,SAAU;IAAC1B,SAAS,EAAC;EAAW,CAAE,CAAC,EACnDC,MAAM,CAAC0B,aAAa,CAACC,GAAG,CAAEC,MAAM,IAAK;IACpC,MAAMC,eAAe,GAAG5B,iBAAiB,CAAC2B,MAAM,CAACE,UAAU,CAAC,IACvDjD,sBAAsB;IAC3B,IAAIgD,eAAe,CAACE,MAAM,KAAK,CAAC,EAAE;MAChC,OAAO,IAAI;IACb;IACA,oBAAOnD,YAAY,cACjBH,KAAA,CAAAqC,aAAA,CAAC5B,wBAAwB;MACvB8C,GAAG,EAAEJ,MAAM,CAACE,UAAW;MACvBzC,WAAW,EAAEwC,eAAgB;MAC7BI,UAAU,EAAEL,MAAM,CAACK,UAAW;MAC9BvB,KAAK,EAAEkB,MAAM,CAAClB,KAAM;MACpBpB,iBAAiB,EAAEA;IAAkB,CACtC,CAAC,EACFsC,MAAM,CAACM,SACT,CAAC;EACH,CAAC,CACE,CACF,CACF,CAAC;AAEV","ignoreList":[]}
@@ -4,7 +4,7 @@
4
4
  display: flex;
5
5
  flex-direction: column;
6
6
  background-color: var(--osdk-pdf-viewer-sidebar-bg);
7
- border-right: 1px solid var(--osdk-pdf-viewer-sidebar-border);
7
+ border-right: var(--osdk-pdf-viewer-sidebar-border);
8
8
  overflow: hidden;
9
9
  }
10
10
 
@@ -4,7 +4,7 @@
4
4
  display: flex;
5
5
  flex-direction: column;
6
6
  background-color: var(--osdk-pdf-viewer-sidebar-bg);
7
- border-right: 1px solid var(--osdk-pdf-viewer-sidebar-border);
7
+ border-right: var(--osdk-pdf-viewer-sidebar-border);
8
8
  overflow: hidden;
9
9
  }
10
10
 
@@ -28,7 +28,7 @@
28
28
  align-items: center;
29
29
  gap: var(--osdk-spacing-2xs, 2px);
30
30
  padding: var(--osdk-spacing-2xs, 2px);
31
- border: 1px solid var(--osdk-surface-border-color, rgba(0, 0, 0, 0.15));
31
+ border: none;
32
32
  border-radius: var(--osdk-surface-border-radius);
33
33
  background-color: var(--osdk-surface-background-color, transparent);
34
34
  }