Skip to content

Commit a357da2

Browse files
authored
fix: return normalized text divs/content values (#581)
1 parent 000e66b commit a357da2

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

packages/discovery-react-components/src/components/DocumentPreview/components/PdfHighlight/utils/Highlighter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ export class Highlighter {
9797
* Update text content HTML elements
9898
* @param textContentDivs HTML elements where text content items are rendered
9999
*/
100-
setTextContentDivs(textContentDivs?: HTMLCollection) {
100+
setTextContentDivs(textContentDivs?: HTMLCollection | Element[]) {
101101
this.pdfTextContentLayout?.setDivs(textContentDivs);
102102
}
103103

packages/discovery-react-components/src/components/DocumentPreview/components/PdfHighlight/utils/textLayout/PdfTextContentTextLayout.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { HtmlBboxInfo, PdfTextContentInfo, TextLayout } from './types';
1212
export class PdfTextContentTextLayout implements TextLayout<PdfTextContentTextLayoutCell> {
1313
private readonly textContentInfo: PdfTextContentInfo;
1414
readonly cells: PdfTextContentTextLayoutCell[];
15-
private divs: HTMLCollection | undefined;
15+
private divs: HTMLCollection | Element[] | undefined;
1616

1717
constructor(textContentInfo: PdfTextContentInfo, pageNum: number, htmlBboxInfo?: HtmlBboxInfo) {
1818
this.textContentInfo = textContentInfo;
@@ -48,7 +48,7 @@ export class PdfTextContentTextLayout implements TextLayout<PdfTextContentTextLa
4848
/**
4949
* set PDF text content item divs
5050
*/
51-
setDivs(divs: HTMLCollection | undefined) {
51+
setDivs(divs: HTMLCollection | Element[] | undefined) {
5252
this.divs = divs;
5353
}
5454

packages/discovery-react-components/src/components/DocumentPreview/components/PdfViewer/PdfViewerTextLayer.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export type PdfRenderedText = {
2929
/**
3030
* Text span DOM elements rendered on the text layer
3131
*/
32-
textDivs: HTMLCollection;
32+
textDivs: HTMLCollection | Element[];
3333

3434
/**
3535
* Pdf page viewport used to render text items
@@ -69,7 +69,7 @@ const PdfViewerTextLayer: FC<PdfViewerTextLayerProps> = ({
6969
async (signal: AbortSignal) => {
7070
if (textLayerWrapper && loadedText) {
7171
const { textContent, viewport, page } = loadedText;
72-
let textDivs!: HTMLCollection;
72+
let textDivs!: HTMLCollection | Element[];
7373

7474
const builder = new TextLayerBuilder({
7575
pdfPage: loadedPage,
@@ -86,6 +86,10 @@ const PdfViewerTextLayer: FC<PdfViewerTextLayerProps> = ({
8686
textContentItems
8787
);
8888
adjustTextDivs(normalizedTextDivs, normalizedTextContentItems, scale);
89+
90+
// update values that will be returned, to use normalized values
91+
textDivs = normalizedTextDivs;
92+
textContent.items = normalizedTextContentItems;
8993
}
9094
}
9195
});

0 commit comments

Comments
 (0)