@rzymek/react-pdf-highlighter 8.0.1 → 8.0.3

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.
@@ -29,6 +29,8 @@ class PdfHighlighter extends PureComponent {
29
29
  tipChildren: null
30
30
  });
31
31
  __publicField(this, "viewer");
32
+ __publicField(this, "eventBus");
33
+ __publicField(this, "linkService");
32
34
  __publicField(this, "resizeObserver", null);
33
35
  __publicField(this, "containerNode", null);
34
36
  __publicField(this, "containerNodeRef");
@@ -261,29 +263,36 @@ class PdfHighlighter extends PureComponent {
261
263
  }
262
264
  }
263
265
  async init() {
266
+ var _a;
264
267
  const { pdfDocument, pdfViewerOptions } = this.props;
265
- const pdfjs = await import("../../node_modules/.pnpm/pdfjs-dist@4.4.168/node_modules/pdfjs-dist/web/pdf_viewer.js");
266
- const eventBus = new pdfjs.EventBus();
267
- const linkService = new pdfjs.PDFLinkService({
268
- eventBus,
269
- externalLinkTarget: 2
270
- });
268
+ const pdfjs = await import("../../node_modules/.pnpm/pdfjs-dist@6.0.227/node_modules/pdfjs-dist/web/pdf_viewer.js");
271
269
  if (!this.containerNodeRef.current) {
272
270
  throw new Error("!");
273
271
  }
274
- this.viewer = this.viewer || new pdfjs.PDFViewer({
275
- container: this.containerNodeRef.current,
276
- eventBus,
277
- // enhanceTextSelection: true, // deprecated. https://github.com/mozilla/pdf.js/issues/9943#issuecomment-409369485
278
- textLayerMode: 2,
279
- removePageBorders: true,
280
- linkService,
281
- ...pdfViewerOptions
282
- });
283
- linkService.setDocument(pdfDocument);
284
- linkService.setViewer(this.viewer);
285
- this.viewer.setDocument(pdfDocument);
286
- this.attachRef(eventBus);
272
+ if (!this.viewer) {
273
+ const eventBus = new pdfjs.EventBus();
274
+ const linkService = new pdfjs.PDFLinkService({
275
+ eventBus,
276
+ externalLinkTarget: 2
277
+ });
278
+ this.viewer = new pdfjs.PDFViewer({
279
+ container: this.containerNodeRef.current,
280
+ eventBus,
281
+ // enhanceTextSelection: true, // deprecated. https://github.com/mozilla/pdf.js/issues/9943#issuecomment-409369485
282
+ textLayerMode: 2,
283
+ removePageBorders: true,
284
+ linkService,
285
+ ...pdfViewerOptions
286
+ });
287
+ this.eventBus = eventBus;
288
+ this.linkService = linkService;
289
+ linkService.setViewer(this.viewer);
290
+ this.attachRef(eventBus);
291
+ }
292
+ if (this.viewer.pdfDocument !== pdfDocument) {
293
+ (_a = this.linkService) == null ? void 0 : _a.setDocument(pdfDocument);
294
+ this.viewer.setDocument(pdfDocument);
295
+ }
287
296
  }
288
297
  componentWillUnmount() {
289
298
  this.unsubscribe();
@@ -19,7 +19,7 @@ class PdfLoader extends Component {
19
19
  componentWillUnmount() {
20
20
  const { pdfDocument: discardedDocument } = this.state;
21
21
  if (discardedDocument) {
22
- discardedDocument.destroy();
22
+ discardedDocument.loadingTask.destroy();
23
23
  }
24
24
  }
25
25
  componentDidUpdate({ url }) {
@@ -42,7 +42,7 @@ class PdfLoader extends Component {
42
42
  if (typeof workerSrc === "string") {
43
43
  GlobalWorkerOptions.workerSrc = workerSrc;
44
44
  }
45
- Promise.resolve().then(() => discardedDocument == null ? void 0 : discardedDocument.destroy()).then(() => {
45
+ Promise.resolve().then(() => discardedDocument == null ? void 0 : discardedDocument.loadingTask.destroy()).then(() => {
46
46
  if (!url) {
47
47
  return;
48
48
  }
@@ -74,7 +74,7 @@ class PdfLoader extends Component {
74
74
  }
75
75
  }
76
76
  __publicField(PdfLoader, "defaultProps", {
77
- workerSrc: "https://unpkg.com/pdfjs-dist@4.4.168/build/pdf.worker.min.mjs"
77
+ workerSrc: "https://unpkg.com/pdfjs-dist@6.0.227/build/pdf.worker.min.mjs"
78
78
  });
79
79
  export {
80
80
  PdfLoader