@rhc-office/sdk 6.6.266 → 6.6.351

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 (92) hide show
  1. package/README.md +1 -5
  2. package/dist/api/annotation-tool.d.ts +162 -102
  3. package/dist/api/annotation-tool.d.ts.map +1 -1
  4. package/dist/api/callbacks.d.ts +32 -6
  5. package/dist/api/callbacks.d.ts.map +1 -1
  6. package/dist/api/document-sdk.d.ts +6 -5
  7. package/dist/api/document-sdk.d.ts.map +1 -1
  8. package/dist/api/document-tool.d.ts +16 -11
  9. package/dist/api/document-tool.d.ts.map +1 -1
  10. package/dist/api/menu-visibility.d.ts +6 -1
  11. package/dist/api/menu-visibility.d.ts.map +1 -1
  12. package/dist/api/page-arrange-tool.d.ts +28 -0
  13. package/dist/api/page-arrange-tool.d.ts.map +1 -0
  14. package/dist/api/security-tool.d.ts +21 -0
  15. package/dist/api/security-tool.d.ts.map +1 -0
  16. package/dist/api/ui-tool.d.ts +19 -0
  17. package/dist/api/ui-tool.d.ts.map +1 -1
  18. package/dist/browser/document-viewer.js +1 -1
  19. package/dist/browser/document-viewer.js.map +1 -1
  20. package/dist/index.d.ts +3 -0
  21. package/dist/index.d.ts.map +1 -1
  22. package/dist/index.js +730 -501
  23. package/dist/index.js.map +1 -1
  24. package/dist/index.umd.cjs +1 -1
  25. package/dist/index.umd.cjs.map +1 -1
  26. package/dist/tools/AnnotationToolImpl.d.ts +25 -0
  27. package/dist/tools/AnnotationToolImpl.d.ts.map +1 -0
  28. package/dist/tools/CryptoToolImpl.d.ts +9 -0
  29. package/dist/tools/CryptoToolImpl.d.ts.map +1 -0
  30. package/dist/tools/DigitalSignToolImpl.d.ts +27 -0
  31. package/dist/tools/DigitalSignToolImpl.d.ts.map +1 -0
  32. package/dist/tools/DocumentToolImpl.d.ts +1 -0
  33. package/dist/tools/DocumentToolImpl.d.ts.map +1 -1
  34. package/dist/tools/PageArrangeToolImpl.d.ts +21 -0
  35. package/dist/tools/PageArrangeToolImpl.d.ts.map +1 -0
  36. package/dist/tools/SecurityToolImpl.d.ts +12 -0
  37. package/dist/tools/SecurityToolImpl.d.ts.map +1 -0
  38. package/dist/tools/SignServerToolImpl.d.ts +19 -0
  39. package/dist/tools/SignServerToolImpl.d.ts.map +1 -0
  40. package/dist/tools/SymbologyToolImpl.d.ts +8 -0
  41. package/dist/tools/SymbologyToolImpl.d.ts.map +1 -0
  42. package/dist/tools/TemplateSignToolImpl.d.ts +13 -0
  43. package/dist/tools/TemplateSignToolImpl.d.ts.map +1 -0
  44. package/dist/tools/UIToolImpl.d.ts +13 -0
  45. package/dist/tools/UIToolImpl.d.ts.map +1 -1
  46. package/dist/tools/index.d.ts +8 -1
  47. package/dist/tools/index.d.ts.map +1 -1
  48. package/dist/viewer/AdapterProtocol.d.ts +3 -1
  49. package/dist/viewer/AdapterProtocol.d.ts.map +1 -1
  50. package/dist/viewer/BridgeToolAdapter.d.ts +1 -0
  51. package/dist/viewer/BridgeToolAdapter.d.ts.map +1 -1
  52. package/dist/viewer/DocumentSDK.d.ts +7 -5
  53. package/dist/viewer/DocumentSDK.d.ts.map +1 -1
  54. package/dist/viewer/ReaderBridgeClient.d.ts +3 -0
  55. package/dist/viewer/ReaderBridgeClient.d.ts.map +1 -1
  56. package/dist/viewer/ReaderConfiguration.d.ts +0 -1
  57. package/dist/viewer/ReaderConfiguration.d.ts.map +1 -1
  58. package/dist/viewer/ReaderStateStore.d.ts +2 -0
  59. package/dist/viewer/ReaderStateStore.d.ts.map +1 -1
  60. package/dist/viewer/SdkCallbackRegistry.d.ts +5 -2
  61. package/dist/viewer/SdkCallbackRegistry.d.ts.map +1 -1
  62. package/package.json +2 -2
  63. package/src/api/annotation-tool.ts +232 -146
  64. package/src/api/callbacks.ts +48 -7
  65. package/src/api/document-sdk.ts +9 -5
  66. package/src/api/document-tool.ts +25 -13
  67. package/src/api/menu-visibility.ts +10 -1
  68. package/src/api/page-arrange-tool.ts +67 -0
  69. package/src/api/security-tool.ts +32 -0
  70. package/src/api/ui-tool.ts +33 -0
  71. package/src/index.ts +3 -0
  72. package/src/tools/AnnotationToolImpl.ts +169 -0
  73. package/src/tools/CryptoToolImpl.ts +27 -0
  74. package/src/tools/DigitalSignToolImpl.ts +166 -0
  75. package/src/tools/DocumentToolImpl.ts +32 -6
  76. package/src/tools/PageArrangeToolImpl.ts +99 -0
  77. package/src/tools/SecurityToolImpl.ts +48 -0
  78. package/src/tools/SignServerToolImpl.ts +92 -0
  79. package/src/tools/SymbologyToolImpl.ts +34 -0
  80. package/src/tools/TemplateSignToolImpl.ts +51 -0
  81. package/src/tools/UIToolImpl.ts +98 -12
  82. package/src/tools/index.ts +8 -1
  83. package/src/viewer/AdapterProtocol.ts +4 -0
  84. package/src/viewer/BridgeToolAdapter.ts +11 -2
  85. package/src/viewer/DocumentSDK.ts +71 -144
  86. package/src/viewer/ReaderBridgeClient.ts +9 -0
  87. package/src/viewer/ReaderConfiguration.ts +0 -2
  88. package/src/viewer/ReaderStateStore.ts +13 -1
  89. package/src/viewer/SdkCallbackRegistry.ts +84 -6
  90. package/dist/tools/Phase1ToolPlaceholder.d.ts +0 -5
  91. package/dist/tools/Phase1ToolPlaceholder.d.ts.map +0 -1
  92. package/src/tools/Phase1ToolPlaceholder.ts +0 -35
@@ -1,28 +1,33 @@
1
1
  import type { AnnotationTool } from '../api/annotation-tool';
2
- import type { IDigitalAnnotationInfo } from '../api/annotation-tool';
3
2
  import type { CryptoTool } from '../api/crypto-tool';
4
- import type {
5
- AnnotationEventCallback,
6
- ReaderReadyCallback,
7
- ReaderUnloadCallback,
8
- } from '../api/callbacks';
9
- import type { IDocumentSDK, IReaderEmbedOptions } from '../api/document-sdk';
3
+ import type { ReaderReadyCallback, ReaderUnloadCallback } from '../api/callbacks';
4
+ import type { IDocumentSDK, ReaderThemeMode } from '../api/document-sdk';
10
5
  import type { DocumentTool } from '../api/document-tool';
11
6
  import type { FindTool } from '../api/find-tool';
12
7
  import type { NetworkingTool } from '../api/networking-tool';
8
+ import type { PageArrangeTool } from '../api/page-arrange-tool';
13
9
  import type { PageTool } from '../api/page-tool';
14
10
  import type { PdfFormFiller } from '../api/pdf-formfiller';
11
+ import type { SecurityTool } from '../api/security-tool';
15
12
  import type { SignServerTool } from '../api/sign-server';
16
13
  import type { DigitalSignTool } from '../api/sign-tool';
17
14
  import type { SymbologyTool } from '../api/symbology-tool';
18
15
  import type { TemplateSignTool } from '../api/template-sign';
19
16
  import type { UITool } from '../api/ui-tool';
17
+ import { AnnotationToolImpl } from '../tools/AnnotationToolImpl';
18
+ import { CryptoToolImpl } from '../tools/CryptoToolImpl';
19
+ import { DigitalSignToolImpl } from '../tools/DigitalSignToolImpl';
20
20
  import { DocumentToolImpl } from '../tools/DocumentToolImpl';
21
21
  import { FindToolImpl } from '../tools/FindToolImpl';
22
22
  import { NetworkingToolImpl } from '../tools/NetworkingToolImpl';
23
+ import { PageArrangeToolImpl } from '../tools/PageArrangeToolImpl';
23
24
  import { PageToolImpl } from '../tools/PageToolImpl';
24
25
  import { PdfFormFillerImpl } from '../tools/PdfFormFillerImpl';
25
26
  import { DigitalSignOptions, KVField } from '../tools/SDKValueObjects';
27
+ import { SecurityToolImpl } from '../tools/SecurityToolImpl';
28
+ import { SignServerToolImpl } from '../tools/SignServerToolImpl';
29
+ import { SymbologyToolImpl } from '../tools/SymbologyToolImpl';
30
+ import { TemplateSignToolImpl } from '../tools/TemplateSignToolImpl';
26
31
  import { UIToolImpl } from '../tools/UIToolImpl';
27
32
  import type { NormalizedReaderEmbedOptions } from './ReaderConfiguration';
28
33
  import { normalizeAppUrl, normalizeReaderEmbedOptions } from './ReaderConfiguration';
@@ -36,7 +41,6 @@ import {
36
41
  RHC_OFFICE_READER_ID_ATTRIBUTE,
37
42
  type AdapterEvent,
38
43
  } from './AdapterProtocol';
39
- import { createBridgeToolAdapter, createNotImplementedBridgeTool } from './BridgeToolAdapter';
40
44
  import { ReaderBridgeClient } from './ReaderBridgeClient';
41
45
  import { ReaderStateStore } from './ReaderStateStore';
42
46
  import { SdkCallbackRegistry } from './SdkCallbackRegistry';
@@ -45,8 +49,8 @@ type ReaderEventListener = Parameters<IDocumentSDK['setReaderEventListener']>[0]
45
49
  type ReaderEventPayload = Parameters<NonNullable<ReaderEventListener>>[1];
46
50
 
47
51
  interface DocumentSDKRuntimeOptions {
48
- adapterReadyTimeoutMs?: number;
49
- adapterRequestTimeoutMs?: number;
52
+ readyTimeoutMs?: number;
53
+ requestTimeoutMs?: number;
50
54
  }
51
55
 
52
56
  type NativeReaderEventName = 'documentLoaded' | 'documentStateChange' | 'documentError';
@@ -151,36 +155,25 @@ const removeMediaQueryListener = (
151
155
  }
152
156
  };
153
157
 
154
- const applyReaderElementLayout = (
155
- readerElement: HTMLElement,
156
- configuration: NormalizedReaderEmbedOptions,
157
- ): void => {
158
- if (configuration.style) {
159
- readerElement.style.cssText = configuration.style;
160
- }
161
-
158
+ const applyReaderElementLayout = (readerElement: HTMLElement): void => {
162
159
  if (!readerElement.style.display) {
163
160
  readerElement.style.display = 'block';
164
161
  }
165
162
 
166
163
  if (!readerElement.style.width) {
167
- readerElement.style.width = configuration.width ?? '100%';
168
- } else if (configuration.width) {
169
- readerElement.style.width = configuration.width;
164
+ readerElement.style.width = '100%';
170
165
  }
171
166
 
172
167
  if (!readerElement.style.height) {
173
- readerElement.style.height = configuration.height ?? '100%';
174
- } else if (configuration.height) {
175
- readerElement.style.height = configuration.height;
168
+ readerElement.style.height = '100%';
176
169
  }
177
170
  };
178
171
 
179
172
  const bindReaderElementTheme = (
180
173
  readerElement: HTMLElement,
181
- configuration: NormalizedReaderEmbedOptions,
174
+ theme: ReaderThemeMode | undefined,
182
175
  ): ReaderThemeCleanup | null => {
183
- const configuredTheme = configuration.theme;
176
+ const configuredTheme = theme;
184
177
  if (!configuredTheme) {
185
178
  readerElement.removeAttribute('theme');
186
179
  return null;
@@ -230,30 +223,17 @@ export class DocumentSDK implements IDocumentSDK {
230
223
  private readonly documentTool = new DocumentToolImpl(this.bridgeToolContext);
231
224
  private readonly uiTool = new UIToolImpl(this.bridgeToolContext);
232
225
  private readonly pageTool = new PageToolImpl(this.bridgeToolContext);
226
+ private readonly pageArrangeTool = new PageArrangeToolImpl(this.bridgeToolContext);
233
227
  private readonly findTool = new FindToolImpl(this.bridgeToolContext);
234
- private readonly signServerTool = createNotImplementedBridgeTool<SignServerTool>(
235
- 'signServer',
236
- this.bridgeToolContext,
237
- );
238
- private readonly digitalSignTool = createNotImplementedBridgeTool<DigitalSignTool>(
239
- 'digitalSign',
240
- this.bridgeToolContext,
241
- );
242
- private readonly symbologyTool = createNotImplementedBridgeTool<SymbologyTool>(
243
- 'symbology',
244
- this.bridgeToolContext,
245
- );
246
- private readonly annotationTool = this.createAnnotationTool();
247
- private readonly templateSignTool = createNotImplementedBridgeTool<TemplateSignTool>(
248
- 'templateSign',
249
- this.bridgeToolContext,
250
- );
228
+ private readonly signServerTool = new SignServerToolImpl(this.bridgeToolContext);
229
+ private readonly digitalSignTool = new DigitalSignToolImpl(this.bridgeToolContext);
230
+ private readonly symbologyTool = new SymbologyToolImpl(this.bridgeToolContext);
231
+ private readonly annotationTool = new AnnotationToolImpl(this.bridgeToolContext);
232
+ private readonly templateSignTool = new TemplateSignToolImpl(this.bridgeToolContext);
251
233
  private readonly pdfFormFiller = new PdfFormFillerImpl(this.bridgeToolContext);
252
234
  private readonly networkingTool = new NetworkingToolImpl(this.bridgeToolContext);
253
- private readonly cryptoTool = createNotImplementedBridgeTool<CryptoTool>(
254
- 'crypto',
255
- this.bridgeToolContext,
256
- );
235
+ private readonly cryptoTool = new CryptoToolImpl(this.bridgeToolContext);
236
+ private readonly securityTool = new SecurityToolImpl(this.bridgeToolContext);
257
237
 
258
238
  private readonly readyCallbacks: ReaderReadyCallback[] = [];
259
239
  private readonly unloadCallbacks: ReaderUnloadCallback[] = [];
@@ -270,14 +250,13 @@ export class DocumentSDK implements IDocumentSDK {
270
250
  private normalizedConfiguration: NormalizedReaderEmbedOptions | null = null;
271
251
  private sessionUser?: Parameters<IDocumentSDK['setSessionUser']>[0];
272
252
  private sessionData?: string;
273
- private license?: { license: string; feature: string };
274
253
  private readonly nativeEventCleanupCallbacks: Array<() => void> = [];
275
254
  private themeCleanup: ReaderThemeCleanup | null = null;
276
255
 
277
256
  constructor(options?: DocumentSDKRuntimeOptions) {
278
257
  this.bridge.configureTimeouts({
279
- readyTimeoutMs: options?.adapterReadyTimeoutMs,
280
- requestTimeoutMs: options?.adapterRequestTimeoutMs,
258
+ readyTimeoutMs: options?.readyTimeoutMs,
259
+ requestTimeoutMs: options?.requestTimeoutMs,
281
260
  });
282
261
  }
283
262
 
@@ -285,12 +264,29 @@ export class DocumentSDK implements IDocumentSDK {
285
264
  this.debugEnabled = debug;
286
265
  };
287
266
 
288
- readonly changeLanguage: IDocumentSDK['changeLanguage'] = (): void => {
289
- // Phase 1: reserved for future reader language bridging.
267
+ readonly changeLanguage: IDocumentSDK['changeLanguage'] = (lang): void => {
268
+ if (!this.readerElement) {
269
+ return;
270
+ }
271
+
272
+ this.readerElement.setAttribute('language', lang);
290
273
  };
291
274
 
292
- readonly setLicense: IDocumentSDK['setLicense'] = (license, feature): void => {
293
- this.license = { license, feature };
275
+ readonly setThemeMode: IDocumentSDK['setThemeMode'] = (theme): void => {
276
+ this.themeCleanup?.();
277
+ this.themeCleanup = null;
278
+ this.normalizedConfiguration = this.normalizedConfiguration
279
+ ? {
280
+ ...this.normalizedConfiguration,
281
+ theme,
282
+ }
283
+ : null;
284
+
285
+ if (!this.readerElement) {
286
+ return;
287
+ }
288
+
289
+ this.themeCleanup = bindReaderElementTheme(this.readerElement, theme);
294
290
  };
295
291
 
296
292
  readonly setSessionUser: IDocumentSDK['setSessionUser'] = (userNameOrInfo): void => {
@@ -395,6 +391,10 @@ export class DocumentSDK implements IDocumentSDK {
395
391
  return this.pageTool;
396
392
  };
397
393
 
394
+ readonly getPageArrangeTool: IDocumentSDK['getPageArrangeTool'] = (): PageArrangeTool => {
395
+ return this.pageArrangeTool;
396
+ };
397
+
398
398
  readonly getFindTool: IDocumentSDK['getFindTool'] = (): FindTool => {
399
399
  return this.findTool;
400
400
  };
@@ -431,6 +431,10 @@ export class DocumentSDK implements IDocumentSDK {
431
431
  return this.cryptoTool;
432
432
  };
433
433
 
434
+ readonly getSecurityTool: IDocumentSDK['getSecurityTool'] = (): SecurityTool => {
435
+ return this.securityTool;
436
+ };
437
+
434
438
  readonly createDigitalSignOptions: IDocumentSDK['createDigitalSignOptions'] = () => {
435
439
  return new DigitalSignOptions();
436
440
  };
@@ -439,92 +443,6 @@ export class DocumentSDK implements IDocumentSDK {
439
443
  return new KVField(key, value, description);
440
444
  };
441
445
 
442
- private createAnnotationTool(): AnnotationTool {
443
- return createBridgeToolAdapter<AnnotationTool>(
444
- 'annotation',
445
- {
446
- addAnnotationEventCallback: {
447
- kind: 'callbackRegister',
448
- callback: (callbacks, args) => {
449
- const callback = args[0];
450
- if (typeof callback === 'function') {
451
- callbacks.annotationEvents.push(callback as AnnotationEventCallback);
452
- }
453
- },
454
- },
455
- addAnnotationPersistCallback: {
456
- kind: 'callbackRegister',
457
- callback: (callbacks, args) => {
458
- const callback = args[0];
459
- if (typeof callback === 'function') {
460
- callbacks.annotationPersist.push(callback as (event: unknown) => void);
461
- }
462
- },
463
- },
464
- addAnnotationRetrieveCallback: {
465
- kind: 'callbackRegister',
466
- callback: (callbacks, args) => {
467
- const callback = args[0];
468
- if (typeof callback === 'function') {
469
- callbacks.annotationRetrieve.push(callback as (event: unknown) => void);
470
- }
471
- },
472
- },
473
- addDigitalAnnotationRetrieveCallback: {
474
- kind: 'callbackRegister',
475
- callback: (callbacks, args) => {
476
- const callback = args[0];
477
- if (typeof callback === 'function') {
478
- callbacks.digitalAnnotationRetrieve.push(
479
- callback as (annotations: IDigitalAnnotationInfo[]) => void,
480
- );
481
- }
482
- },
483
- },
484
- isInAnnotationMode: {
485
- kind: 'stateGetter',
486
- state: (state) => state.annotationEnabled,
487
- },
488
- getAnnotations: { kind: 'stateGetter', state: () => [] },
489
- getAnnotationsCount: { kind: 'stateGetter', state: () => 0 },
490
- queryAnnotationsBy: { kind: 'stateGetter', state: () => [] },
491
- setToolSource: { kind: 'command' },
492
- openAnnotationView: { kind: 'command' },
493
- closeAnnotationView: { kind: 'command' },
494
- openTextAnnotationView: { kind: 'command' },
495
- setTextAnnotationFontColor: { kind: 'command' },
496
- setTextAnnotationFontSize: { kind: 'command' },
497
- closeTextAnnotationView: { kind: 'command' },
498
- createTextAnnotation: { kind: 'command' },
499
- setPersistToDocument: { kind: 'command' },
500
- saveAnnotations: { kind: 'callbackQuery' },
501
- saveTextAnnotations: { kind: 'command' },
502
- clearAnnotations: { kind: 'command' },
503
- clearTextAnnotations: { kind: 'command' },
504
- undoAnnotation: { kind: 'command' },
505
- redoAnnotation: { kind: 'command' },
506
- selectAnnotationTool: { kind: 'command' },
507
- showAnnotationColorPicker: { kind: 'command' },
508
- setAnnotationPenType: { kind: 'command' },
509
- appendAnnotations: { kind: 'callbackQuery' },
510
- batchAppendAnnotations: { kind: 'callbackQuery' },
511
- setAnnotationPenColor: { kind: 'command' },
512
- setAnnotationPenWidth: { kind: 'command' },
513
- setAnnotationPenThickness: { kind: 'command' },
514
- enableAnnotationsInfoView: { kind: 'command' },
515
- enableAnnotationsDeletion: { kind: 'command' },
516
- enableAnnotationsDeletionOnlyByAuthor: { kind: 'command' },
517
- listDigitalStamps: { kind: 'command' },
518
- listAnnotations: { kind: 'command' },
519
- deleteAnnotationsBy: { kind: 'command' },
520
- deleteAnnotationsById: { kind: 'command' },
521
- addDigitalAnnotation: { kind: 'command' },
522
- addInkAnnotationCallback: { kind: 'callbackRegister' },
523
- },
524
- this.bridgeToolContext,
525
- );
526
- }
527
-
528
446
  private readonly mountReader = async (
529
447
  hostContainer: HTMLDivElement,
530
448
  configuration: NormalizedReaderEmbedOptions,
@@ -541,8 +459,12 @@ export class DocumentSDK implements IDocumentSDK {
541
459
  readerElement.setAttribute(RHC_OFFICE_READER_ID_ATTRIBUTE, readerId);
542
460
  this.readerId = readerId;
543
461
  this.bridge.setReaderId(readerId);
544
- applyReaderElementLayout(readerElement, configuration);
545
- this.themeCleanup = bindReaderElementTheme(readerElement, configuration);
462
+ applyReaderElementLayout(readerElement);
463
+ const shouldUseCompactMode =
464
+ configuration.compactViewer === true && configuration.keepPCMenu !== true;
465
+ readerElement.toggleAttribute('data-sdk-compact-mode', shouldUseCompactMode);
466
+ readerElement.setAttribute('language', configuration.language ?? 'zh_CN');
467
+ this.themeCleanup = bindReaderElementTheme(readerElement, configuration.theme);
546
468
  this.bindNativeReaderEvents(readerElement);
547
469
 
548
470
  hostContainer.replaceChildren(readerElement);
@@ -552,8 +474,13 @@ export class DocumentSDK implements IDocumentSDK {
552
474
  return;
553
475
  }
554
476
 
555
- if (configuration.scrollIntoView && typeof hostContainer.scrollIntoView === 'function') {
556
- hostContainer.scrollIntoView({ behavior: 'smooth', block: 'nearest' });
477
+ const adapterReady = await this.bridge.waitForReady();
478
+ if (this.mountToken !== mountToken) {
479
+ return;
480
+ }
481
+
482
+ if (!adapterReady) {
483
+ throw new Error('Editor adapter is not available.');
557
484
  }
558
485
 
559
486
  this.isReady = true;
@@ -141,6 +141,15 @@ export class ReaderBridgeClient {
141
141
  return getAdapterGlobal()?.getCapabilities(this.readerId) ?? null;
142
142
  }
143
143
 
144
+ async waitForReady(options?: { timeoutMs?: number }): Promise<boolean> {
145
+ if (!this.readerId) {
146
+ return false;
147
+ }
148
+
149
+ const adapter = await this.waitForAdapter(this.readerId, options?.timeoutMs);
150
+ return Boolean(adapter);
151
+ }
152
+
144
153
  private async waitForAdapter(
145
154
  readerId: string,
146
155
  timeoutMs = this.readyTimeoutMs,
@@ -4,7 +4,6 @@ export type SupportedReaderTheme = 'light' | 'dark' | 'high-contrast' | 'auto';
4
4
 
5
5
  export interface NormalizedReaderEmbedOptions extends IReaderEmbedOptions {
6
6
  appUrl: string;
7
- scrollIntoView: boolean;
8
7
  theme?: SupportedReaderTheme;
9
8
  }
10
9
 
@@ -53,7 +52,6 @@ export const normalizeReaderEmbedOptions = (
53
52
  return {
54
53
  ...configuration,
55
54
  appUrl: normalizedAppUrl,
56
- scrollIntoView: configuration.scrollIntoView ?? true,
57
55
  theme: normalizeTheme(configuration.theme),
58
56
  };
59
57
  };
@@ -3,6 +3,8 @@ import type { AdapterStatePatch } from './AdapterProtocol';
3
3
  export interface ReaderStateSnapshot {
4
4
  annotationEnabled: boolean;
5
5
  annotationMode?: string;
6
+ annotations?: unknown[];
7
+ digitalSignatures?: unknown[];
6
8
  documentModified: boolean;
7
9
  documentOpened: boolean;
8
10
  documentType?: string;
@@ -37,6 +39,10 @@ export class ReaderStateStore {
37
39
  this.state = {
38
40
  ...this.state,
39
41
  ...patch,
42
+ annotations: patch.annotations ? [...patch.annotations] : this.state.annotations,
43
+ digitalSignatures: patch.digitalSignatures
44
+ ? [...patch.digitalSignatures]
45
+ : this.state.digitalSignatures,
40
46
  };
41
47
  }
42
48
 
@@ -48,6 +54,12 @@ export class ReaderStateStore {
48
54
  }
49
55
 
50
56
  snapshot(): ReaderStateSnapshot {
51
- return { ...this.state };
57
+ return {
58
+ ...this.state,
59
+ annotations: this.state.annotations ? [...this.state.annotations] : undefined,
60
+ digitalSignatures: this.state.digitalSignatures
61
+ ? [...this.state.digitalSignatures]
62
+ : undefined,
63
+ };
52
64
  }
53
65
  }
@@ -1,37 +1,106 @@
1
1
  import type {
2
2
  AnnotationEventCallback,
3
+ AnnotationEventPayload,
3
4
  DigitalSignatureRetrieveCallback,
4
5
  DocumentClosedCallback,
6
+ DocumentCloseResult,
7
+ DocumentOpenedCallback,
8
+ DocumentOpenResult,
9
+ DocumentReaderStatus,
10
+ DocumentSaveResult,
5
11
  DocumentSavedCallback,
6
12
  PageChangeCallback,
7
13
  PageModeChangeCallback,
8
14
  } from '../api/callbacks';
9
15
  import type { IDigitalAnnotationInfo } from '../api/annotation-tool';
16
+ import type { ISignServerAuthorization, SignServerAuthCallback } from '../api/sign-server';
17
+
18
+ const normalizeAnnotationEventPayload = (payload: unknown): AnnotationEventPayload | undefined => {
19
+ return typeof payload === 'object' && payload !== null && !Array.isArray(payload)
20
+ ? (payload as AnnotationEventPayload)
21
+ : undefined;
22
+ };
23
+
24
+ const isRecord = (value: unknown): value is Record<string, unknown> => {
25
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
26
+ };
27
+
28
+ const normalizeDocumentReaderStatus = (value: unknown): DocumentReaderStatus | undefined => {
29
+ if (!isRecord(value)) {
30
+ return undefined;
31
+ }
32
+
33
+ const state: DocumentReaderStatus = {};
34
+ if (typeof value.currentPage === 'number') {
35
+ state.currentPage = value.currentPage;
36
+ }
37
+ if (typeof value.documentType === 'string') {
38
+ state.documentType = value.documentType;
39
+ }
40
+ if (typeof value.totalPages === 'number') {
41
+ state.totalPages = value.totalPages;
42
+ } else if (typeof value.pageCount === 'number') {
43
+ state.totalPages = value.pageCount;
44
+ }
45
+ if (typeof value.zoomLevel === 'number') {
46
+ state.zoomLevel = value.zoomLevel;
47
+ }
48
+
49
+ return Object.keys(state).length > 0 ? state : undefined;
50
+ };
51
+
52
+ const normalizeDocumentOpenResult = (payload: unknown): DocumentOpenResult => {
53
+ if (!isRecord(payload)) {
54
+ return {
55
+ success: true,
56
+ status: 'ok',
57
+ };
58
+ }
59
+
60
+ const nestedState = normalizeDocumentReaderStatus(payload.state);
61
+ const payloadState = normalizeDocumentReaderStatus(payload);
62
+ const error = typeof payload.error === 'string' ? payload.error : undefined;
63
+ const success = typeof payload.success === 'boolean' ? payload.success : !error;
64
+ const status = typeof payload.status === 'string' ? payload.status : success ? 'ok' : 'error';
65
+
66
+ return {
67
+ success,
68
+ status,
69
+ error,
70
+ state: nestedState ?? payloadState,
71
+ };
72
+ };
10
73
 
11
74
  export class SdkCallbackRegistry {
12
75
  readonly annotationEvents: AnnotationEventCallback[] = [];
13
76
  readonly annotationPersist: Array<(event: unknown) => void> = [];
14
77
  readonly annotationRetrieve: Array<(event: unknown) => void> = [];
15
78
  readonly digitalAnnotationRetrieve: Array<(annotations: IDigitalAnnotationInfo[]) => void> = [];
79
+ readonly digitalSign: Array<(response: unknown) => void> = [];
16
80
  readonly digitalSignatureParse: DigitalSignatureRetrieveCallback[] = [];
17
81
  readonly digitalSignatureRetrieve: DigitalSignatureRetrieveCallback[] = [];
18
82
  readonly documentClosed: DocumentClosedCallback[] = [];
19
- readonly documentOpened: Array<(status: string, error: string) => void> = [];
83
+ readonly documentOpened: DocumentOpenedCallback[] = [];
20
84
  readonly documentSaved: DocumentSavedCallback[] = [];
21
85
  readonly pageChange: PageChangeCallback[] = [];
22
86
  readonly pageModeChange: PageModeChangeCallback[] = [];
87
+ readonly signServerAuth: SignServerAuthCallback[] = [];
23
88
 
24
89
  emit(event: string, payload: unknown): void {
25
90
  switch (event) {
26
91
  case 'documentOpened':
27
- case 'documentLoaded':
28
- this.documentOpened.forEach((callback) => callback('ok', ''));
92
+ case 'documentLoaded': {
93
+ const result = normalizeDocumentOpenResult(payload);
94
+ this.documentOpened.forEach((callback) =>
95
+ callback(result.status ?? 'ok', result.error ?? '', result),
96
+ );
29
97
  return;
98
+ }
30
99
  case 'documentSaved':
31
- this.documentSaved.forEach((callback) => callback(payload));
100
+ this.documentSaved.forEach((callback) => callback(payload as DocumentSaveResult));
32
101
  return;
33
102
  case 'documentClosed':
34
- this.documentClosed.forEach((callback) => callback(payload));
103
+ this.documentClosed.forEach((callback) => callback(payload as DocumentCloseResult));
35
104
  return;
36
105
  case 'pageChange': {
37
106
  const pagePayload = payload as { pageIndex?: number; pageCount?: number };
@@ -48,7 +117,10 @@ export class SdkCallbackRegistry {
48
117
  case 'annotationEvent': {
49
118
  const annotationPayload = payload as { event?: string; payload?: unknown };
50
119
  this.annotationEvents.forEach((callback) =>
51
- callback(annotationPayload.event ?? 'annotationEvent', annotationPayload.payload),
120
+ callback(
121
+ annotationPayload.event ?? 'annotationEvent',
122
+ normalizeAnnotationEventPayload(annotationPayload.payload),
123
+ ),
52
124
  );
53
125
  return;
54
126
  }
@@ -63,6 +135,9 @@ export class SdkCallbackRegistry {
63
135
  callback(Array.isArray(payload) ? (payload as IDigitalAnnotationInfo[]) : []),
64
136
  );
65
137
  return;
138
+ case 'digitalSign':
139
+ this.digitalSign.forEach((callback) => callback(payload));
140
+ return;
66
141
  case 'digitalSignatureRetrieve':
67
142
  this.digitalSignatureRetrieve.forEach((callback) =>
68
143
  callback(Array.isArray(payload) ? payload : []),
@@ -73,6 +148,9 @@ export class SdkCallbackRegistry {
73
148
  callback(Array.isArray(payload) ? payload : []),
74
149
  );
75
150
  return;
151
+ case 'signServerAuth':
152
+ this.signServerAuth.forEach((callback) => callback(payload as ISignServerAuthorization));
153
+ return;
76
154
  default:
77
155
  return;
78
156
  }
@@ -1,5 +0,0 @@
1
- export declare class SDKPhase1NotImplementedError extends Error {
2
- constructor(toolName: string, methodName: string);
3
- }
4
- export declare const createPhase1ToolPlaceholder: <T extends object>(toolName: string) => T;
5
- //# sourceMappingURL=Phase1ToolPlaceholder.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Phase1ToolPlaceholder.d.ts","sourceRoot":"","sources":["../../src/tools/Phase1ToolPlaceholder.ts"],"names":[],"mappings":"AAAA,qBAAa,4BAA6B,SAAQ,KAAK;gBACzC,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM;CAIjD;AAQD,eAAO,MAAM,2BAA2B,GAAI,CAAC,SAAS,MAAM,EAAE,UAAU,MAAM,KAAG,CAqBhF,CAAC"}
@@ -1,35 +0,0 @@
1
- export class SDKPhase1NotImplementedError extends Error {
2
- constructor(toolName: string, methodName: string) {
3
- super(`[Phase 1] ${toolName}.${methodName} is not implemented yet.`);
4
- this.name = 'SDKPhase1NotImplementedError';
5
- }
6
- }
7
-
8
- const createThrowingMethod = (toolName: string, methodName: string) => {
9
- return (): never => {
10
- throw new SDKPhase1NotImplementedError(toolName, methodName);
11
- };
12
- };
13
-
14
- export const createPhase1ToolPlaceholder = <T extends object>(toolName: string): T => {
15
- return new Proxy(
16
- {},
17
- {
18
- get: (_target, property): unknown => {
19
- if (property === 'then') {
20
- return undefined;
21
- }
22
-
23
- if (typeof property === 'symbol') {
24
- if (property === Symbol.toStringTag) {
25
- return toolName;
26
- }
27
-
28
- return undefined;
29
- }
30
-
31
- return createThrowingMethod(toolName, property);
32
- },
33
- },
34
- ) as T;
35
- };