@vaadin-component-factory/vcf-pdf-viewer 1.0.0 → 1.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.
@@ -1,8 +1,6 @@
1
1
  import { PolymerElement, html } from '@polymer/polymer/polymer-element';
2
2
  import { ThemableMixin } from '@vaadin/vaadin-themable-mixin';
3
3
  import { ElementMixin } from '@vaadin/component-base/src/element-mixin.js';
4
- import { IronResizableBehavior } from '@polymer/iron-resizable-behavior';
5
- import { mixinBehaviors } from '@polymer/polymer/lib/legacy/class.js';
6
4
  import '@vaadin/polymer-legacy-adapter/template-renderer.js';
7
5
  import '@vaadin/text-field';
8
6
  import '@vaadin/select';
@@ -34,8 +32,7 @@ pdfjsLib.GlobalWorkerOptions.workerSrc = pdfjsWorker;
34
32
  */
35
33
  class PdfViewerElement extends
36
34
  ElementMixin(
37
- ThemableMixin(
38
- mixinBehaviors([IronResizableBehavior], PolymerElement))) {
35
+ ThemableMixin(PolymerElement)) {
39
36
 
40
37
  static get template() {
41
38
  return html`
@@ -382,6 +379,14 @@ class PdfViewerElement extends
382
379
  type: Boolean,
383
380
  value: false
384
381
  },
382
+
383
+ /**
384
+ * Flag to indicate if toolbar should only show filename as title
385
+ */
386
+ toolbarOnlyFilename: {
387
+ type: Boolean,
388
+ value: false
389
+ },
385
390
  };
386
391
  }
387
392
 
@@ -392,7 +397,9 @@ class PdfViewerElement extends
392
397
  }
393
398
 
394
399
  __setTitle(pdfTitle, filename) {
395
- if (pdfTitle && filename) {
400
+ if(this.__viewer && this.toolbarOnlyFilename && filename) {
401
+ this.__title = filename;
402
+ } else if (pdfTitle && filename) {
396
403
  this.__title = pdfTitle + ' - ' + filename;
397
404
  } else if (pdfTitle) {
398
405
  this.__title = pdfTitle;
@@ -401,7 +408,7 @@ class PdfViewerElement extends
401
408
  } else {
402
409
  this.__title = 'PDF';
403
410
  }
404
- }
411
+ }
405
412
 
406
413
  ready() {
407
414
  super.ready();
@@ -469,8 +476,15 @@ class PdfViewerElement extends
469
476
  }
470
477
  });
471
478
 
472
- this.addEventListener('iron-resize', this.__recalculateSizes);
473
- this.__recalculateSizes();
479
+ this.__resizeObserver = new ResizeObserver(() => {
480
+ requestAnimationFrame(() => this.__recalculateSizes());
481
+ });
482
+ this.__resizeObserver.observe(this);
483
+ }
484
+
485
+ connectedCallback() {
486
+ super.connectedCallback();
487
+ this.__recalculateSizes();
474
488
  }
475
489
 
476
490
  __updateCurrentPageValue(pageNumber){
@@ -513,7 +527,7 @@ class PdfViewerElement extends
513
527
  return;
514
528
  }
515
529
  this.__setFilename(src);
516
- this.__document = pdfjsLib.getDocument(src);
530
+ this.__document = pdfjsLib.getDocument(new URL(src, document.baseURI).href);
517
531
  return this.__document.promise.then((pdfDocument) => {
518
532
  // Document loaded, specifying document for the viewer.
519
533
  this.__thumbnailViewer.setDocument(pdfDocument);
@@ -628,11 +642,10 @@ class PdfViewerElement extends
628
642
  }
629
643
 
630
644
  setCurrentPage(value) {
631
- if (!this.__viewer || this.__loading) {
645
+ if (value != undefined) {
632
646
  this.$.currentPage.value = value;
633
- } else {
634
- this.__pageChange();
635
647
  }
648
+ this.__pageChange();
636
649
  }
637
650
 
638
651
  _getPage() {