@progress/kendo-pdfviewer-common 0.4.2-develop.1 → 0.5.0-develop.1

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 (29) hide show
  1. package/dist/es/annotations/annotation-editor-ui-manager.js +25 -0
  2. package/dist/es/annotations/annotation-layer-builder.js +2 -2
  3. package/dist/es/annotations/annotation-layer.js +352 -337
  4. package/dist/es/annotations/helpers/annotation-storage.js +14 -0
  5. package/dist/es/annotations/shared/event_utils.js +6 -0
  6. package/dist/es/utils.js +2 -2
  7. package/dist/es/widget/page.js +1 -0
  8. package/dist/es/widget/pdfviewer.js +20 -6
  9. package/dist/es2015/annotations/annotation-editor-ui-manager.js +25 -0
  10. package/dist/es2015/annotations/annotation-layer-builder.js +2 -2
  11. package/dist/es2015/annotations/annotation-layer.js +352 -337
  12. package/dist/es2015/annotations/helpers/annotation-storage.js +14 -0
  13. package/dist/es2015/annotations/shared/event_utils.js +6 -0
  14. package/dist/es2015/utils.js +2 -2
  15. package/dist/es2015/widget/page.js +1 -0
  16. package/dist/es2015/widget/pdfviewer.js +20 -6
  17. package/dist/npm/annotations/annotation-editor-ui-manager.d.ts +3 -0
  18. package/dist/npm/annotations/annotation-editor-ui-manager.js +25 -0
  19. package/dist/npm/annotations/annotation-layer-builder.js +2 -2
  20. package/dist/npm/annotations/annotation-layer.js +352 -337
  21. package/dist/npm/annotations/helpers/annotation-storage.d.ts +10 -0
  22. package/dist/npm/annotations/helpers/annotation-storage.js +14 -0
  23. package/dist/npm/annotations/shared/event_utils.d.ts +4 -0
  24. package/dist/npm/annotations/shared/event_utils.js +6 -0
  25. package/dist/npm/utils.js +2 -2
  26. package/dist/npm/widget/page.js +1 -0
  27. package/dist/npm/widget/pdfviewer.d.ts +1 -0
  28. package/dist/npm/widget/pdfviewer.js +20 -6
  29. package/package.json +1 -1
@@ -45,6 +45,20 @@ class AnnotationStorage {
45
45
  this.onResetModified = null;
46
46
  this.onAnnotationEditor = null;
47
47
  }
48
+ /**
49
+ * Get the value for the storage - used purely for debugging purposes.
50
+ * @returns {Object}
51
+ */
52
+ getStorage() {
53
+ return __classPrivateFieldGet(this, _AnnotationStorage_storage, "f");
54
+ }
55
+ /**
56
+ * Get the modified flag for the storage - used purely for debugging purposes.
57
+ * @returns {Object}
58
+ */
59
+ getModified() {
60
+ return __classPrivateFieldGet(this, _AnnotationStorage_modified, "f");
61
+ }
48
62
  /**
49
63
  * Get the value for a given key if it exists, or return the default value.
50
64
  * @param {string} key
@@ -64,6 +64,12 @@ class EventBus {
64
64
  constructor() {
65
65
  _EventBus_listeners.set(this, Object.create(null));
66
66
  }
67
+ /**
68
+ * Returs the current event listeners - used purely for debugging purposes.
69
+ */
70
+ getListeners() {
71
+ return __classPrivateFieldGet(this, _EventBus_listeners, "f");
72
+ }
67
73
  /**
68
74
  * @param {string} eventName
69
75
  * @param {function} listener
@@ -399,10 +399,10 @@ export const scrollToPage = (rootElement, pageNumber) => {
399
399
  */
400
400
  export const currentPage = (rootElement) => {
401
401
  const scrollElement = rootElement.querySelector('.k-pdf-viewer-canvas');
402
- const page = rootElement.querySelector('.k-page');
402
+ const page = rootElement.querySelector('.k-page:not(.k-blank-page)');
403
403
  return scrollElement && page
404
404
  ? Math.floor(Math.round(scrollElement.scrollTop) /
405
- (page.offsetHeight + page.offsetTop) +
405
+ Math.max(1, page.offsetHeight + page.offsetTop) +
406
406
  0.01)
407
407
  : 0;
408
408
  };
@@ -92,6 +92,7 @@ export class Page extends Component {
92
92
  // todo: ported from pdf.js
93
93
  this.pdfViewer = options.pdfViewer;
94
94
  this.pdfPage = options.pdfPage;
95
+ __classPrivateFieldSet(this, _Page_annotationMode, this.pdfViewer.getAnnotationMode(), "f");
95
96
  this.resetState();
96
97
  }
97
98
  destroy() {
@@ -1,4 +1,4 @@
1
- var _PdfViewer_instances, _PdfViewer_annotationEditorMode, _PdfViewer_switchAnnotationEditorModeTimeoutId, _PdfViewer_eventAbortController, _PdfViewer_onPageRenderedCallback, _PdfViewer_switchToEditAnnotationMode, _PdfViewer_scrollIntoView;
1
+ var _PdfViewer_instances, _PdfViewer_annotationEditorMode, _PdfViewer_switchAnnotationEditorModeTimeoutId, _PdfViewer_annotationMode, _PdfViewer_eventAbortController, _PdfViewer_onPageRenderedCallback, _PdfViewer_switchToEditAnnotationMode, _PdfViewer_scrollIntoView;
2
2
  import { __awaiter, __classPrivateFieldGet, __classPrivateFieldSet } from "tslib";
3
3
  import { deepExtend, Component, isString, toArray, noop, hasValue, toClassSelector, addClass, removeClass, mousewheelDelta, convertToHtml, clamp, createPromise } from "../common/main";
4
4
  import { currentPage, parsePdfFromBase64String, scale as getRenderScale, adjustCanvasSize, createElement } from "../utils";
@@ -49,6 +49,7 @@ export class PdfViewer extends Component {
49
49
  zoomLevel: DEFAULT_ZOOM_LEVEL,
50
50
  zoomBeforePrint: false,
51
51
  zoomLevelForPrint: 3,
52
+ renderForms: false,
52
53
  searchMatchScrollLeftOffset: 0,
53
54
  // add some default offset, so that the found match
54
55
  // does not appear on the top edge of the page when navigated to
@@ -121,7 +122,7 @@ export class PdfViewer extends Component {
121
122
  // #annotationEditorHighlightColors = null;
122
123
  // #annotationEditorMode = AnnotationEditorType.NONE;
123
124
  // #annotationEditorUIManager = null;
124
- // #annotationMode = AnnotationMode.ENABLE_FORMS;
125
+ _PdfViewer_annotationMode.set(this, AnnotationMode.ENABLE);
125
126
  // #containerTopLeft = null;
126
127
  // #enableHWA = false;
127
128
  // #enableHighlightFloatingButton = false;
@@ -181,7 +182,7 @@ export class PdfViewer extends Component {
181
182
  // as this can only be obtained by JS
182
183
  this.tryTriggerScroll = (e) => {
183
184
  let isPageChanged = false;
184
- const pageNumber = currentPage(this.element) + 1;
185
+ const pageNumber = this.getCurrentPageIndex() + 1;
185
186
  if (pageNumber !== this.state.activePageNumber && (pageNumber >= 1 && pageNumber <= this.state.pdfDocument.numPages)) {
186
187
  isPageChanged = true;
187
188
  this.state.activePageNumber = pageNumber;
@@ -236,6 +237,8 @@ export class PdfViewer extends Component {
236
237
  this.wrapper = this.element;
237
238
  this.initEventBus();
238
239
  __classPrivateFieldSet(this, _PdfViewer_eventAbortController, new AbortController(), "f");
240
+ if (this.options.renderForms)
241
+ __classPrivateFieldSet(this, _PdfViewer_annotationMode, AnnotationMode.ENABLE_FORMS, "f");
239
242
  this.resetState();
240
243
  this.bindEvents();
241
244
  this.initLinkService();
@@ -326,6 +329,9 @@ export class PdfViewer extends Component {
326
329
  }
327
330
  updater();
328
331
  }
332
+ getAnnotationMode() {
333
+ return __classPrivateFieldGet(this, _PdfViewer_annotationMode, "f");
334
+ }
329
335
  getPrintUnits() {
330
336
  return this.options.printResolution / PixelsPerInch.PDF;
331
337
  }
@@ -851,7 +857,7 @@ export class PdfViewer extends Component {
851
857
  // optionalContentConfigPromise,
852
858
  // renderingQueue: this.renderingQueue,
853
859
  textLayerMode: TextLayerMode.ENABLE,
854
- annotationMode: AnnotationMode.ENABLE,
860
+ annotationMode: this.getAnnotationMode(),
855
861
  // imageResourcesPath: this.imageResourcesPath,
856
862
  // maxCanvasPixels: this.maxCanvasPixels,
857
863
  // pageColors,
@@ -940,8 +946,16 @@ export class PdfViewer extends Component {
940
946
  // and then revert
941
947
  serializedAnnotationStorage = {};
942
948
  originalAnnotationStorage = options.pdf.annotationStorage.getAll();
949
+ // With the form filling functionality enabled, values could be coming as pure JSON objects,
950
+ // thus the additional assertion.
943
951
  Object.keys(originalAnnotationStorage).forEach((key) => {
944
- serializedAnnotationStorage[key] = originalAnnotationStorage[key].toJSON();
952
+ var _a;
953
+ if (typeof ((_a = originalAnnotationStorage[key]) === null || _a === void 0 ? void 0 : _a.toJSON) === "function") {
954
+ serializedAnnotationStorage[key] = originalAnnotationStorage[key].toJSON();
955
+ }
956
+ else {
957
+ serializedAnnotationStorage[key] = originalAnnotationStorage[key];
958
+ }
945
959
  });
946
960
  Object.keys(originalAnnotationStorage).forEach((key) => {
947
961
  options.pdf.annotationStorage.remove(key);
@@ -1628,7 +1642,7 @@ export class PdfViewer extends Component {
1628
1642
  return true;
1629
1643
  }
1630
1644
  }
1631
- _PdfViewer_annotationEditorMode = new WeakMap(), _PdfViewer_switchAnnotationEditorModeTimeoutId = new WeakMap(), _PdfViewer_eventAbortController = new WeakMap(), _PdfViewer_onPageRenderedCallback = new WeakMap(), _PdfViewer_instances = new WeakSet(), _PdfViewer_switchToEditAnnotationMode = function _PdfViewer_switchToEditAnnotationMode() {
1645
+ _PdfViewer_annotationEditorMode = new WeakMap(), _PdfViewer_switchAnnotationEditorModeTimeoutId = new WeakMap(), _PdfViewer_annotationMode = new WeakMap(), _PdfViewer_eventAbortController = new WeakMap(), _PdfViewer_onPageRenderedCallback = new WeakMap(), _PdfViewer_instances = new WeakSet(), _PdfViewer_switchToEditAnnotationMode = function _PdfViewer_switchToEditAnnotationMode() {
1632
1646
  // const visible = this._getVisiblePages();
1633
1647
  // const visible = this._getVisiblePages();
1634
1648
  const pagesToRefresh = [];
@@ -28,11 +28,14 @@ export declare class AnnotationEditorUIManager {
28
28
  onSetPreference({ name }: {
29
29
  name: any;
30
30
  }): void;
31
+ onNamedAction(event: any): void;
31
32
  onPageChanging({ pageNumber }: {
32
33
  pageNumber: any;
33
34
  }): void;
34
35
  focusMainContainer(): void;
35
36
  findParent(x: any, y: any): any;
37
+ triggerPrinting(): void;
38
+ downloadOrSave(): void;
36
39
  disableUserSelect(value?: boolean): void;
37
40
  addShouldRescale(editor: any): void;
38
41
  removeShouldRescale(editor: any): void;
@@ -245,6 +245,9 @@ class AnnotationEditorUIManager {
245
245
  this._eventBus._on("setpreference", this.onSetPreference.bind(this), {
246
246
  signal
247
247
  });
248
+ this._eventBus._on("namedaction", this.onNamedAction.bind(this), {
249
+ signal
250
+ });
248
251
  tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_instances, "m", _AnnotationEditorUIManager_addSelectionListener).call(this);
249
252
  tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_instances, "m", _AnnotationEditorUIManager_addDragAndDropListeners).call(this);
250
253
  tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_instances, "m", _AnnotationEditorUIManager_addKeyboardManager).call(this);
@@ -391,6 +394,18 @@ class AnnotationEditorUIManager {
391
394
  default: break;
392
395
  }
393
396
  }
397
+ onNamedAction(event) {
398
+ // Processing a couple of named actions that might be useful, see also
399
+ // `PDFLinkService.executeNamedAction`.
400
+ switch (event.action) {
401
+ case "Print":
402
+ this.triggerPrinting();
403
+ break;
404
+ case "SaveAs":
405
+ this.downloadOrSave();
406
+ break;
407
+ }
408
+ }
394
409
  onPageChanging({ pageNumber }) {
395
410
  tslib_1.__classPrivateFieldSet(this, _AnnotationEditorUIManager_currentPageIndex, pageNumber - 1, "f");
396
411
  }
@@ -410,6 +425,16 @@ class AnnotationEditorUIManager {
410
425
  }
411
426
  return null;
412
427
  }
428
+ triggerPrinting() {
429
+ var _a;
430
+ (_a = this.pdfViewer) === null || _a === void 0 ? void 0 : _a.printFile();
431
+ }
432
+ downloadOrSave() {
433
+ var _a, _b;
434
+ (_a = this.pdfViewer) === null || _a === void 0 ? void 0 : _a.downloadFile({
435
+ fileName: (_b = this.pdfViewer) === null || _b === void 0 ? void 0 : _b.options.downloadFileName
436
+ });
437
+ }
413
438
  disableUserSelect(value = false) {
414
439
  var _a;
415
440
  (_a = tslib_1.__classPrivateFieldGet(this, _AnnotationEditorUIManager_viewer, "f")) === null || _a === void 0 ? void 0 : _a.classList.toggle("noUserSelect", value);
@@ -157,9 +157,9 @@ class AnnotationLayerBuilder {
157
157
  annotations,
158
158
  // imageResourcesPath: this.imageResourcesPath,
159
159
  renderForms: this.renderForms,
160
- linkService: this.linkService
160
+ linkService: this.linkService,
161
161
  // downloadManager: this.downloadManager,
162
- // annotationStorage: this.annotationStorage,
162
+ annotationStorage: this.annotationStorage
163
163
  // enableScripting: this.enableScripting,
164
164
  // hasJSActions,
165
165
  // fieldObjects,