@adobe/ccweb-add-on-sdk-types 1.0.0 → 1.1.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.
@@ -23,8 +23,8 @@
23
23
  ********************************************************************************/
24
24
 
25
25
  /**
26
- * Here are various global objects and Web APIs available for use in script code.
27
- * Please note, script runtime exposes only a subset of functionalities
26
+ * Here are various global objects and Web APIs available for use in document sandbox code.
27
+ * Please note, document sandbox runtime exposes only a subset of functionalities
28
28
  * exposed by standard Web APIs.
29
29
  */
30
30
  declare global {
@@ -40,11 +40,6 @@ declare global {
40
40
  assert(assertion?: boolean, msg?: string, ...subst: any[]): void;
41
41
  }
42
42
 
43
- function setTimeout(functionRef: Function, delay: number, ...params: any[]): number;
44
- function clearTimeout(timeoutID: number): void;
45
- function setInterval(functionRef: Function, delay: number, ...params: any[]): number;
46
- function clearInterval(intervalID: number): void;
47
-
48
43
  interface Blob {
49
44
  readonly size: number;
50
45
  readonly type: string;
@@ -53,6 +48,10 @@ declare global {
53
48
  text(): Promise<string>;
54
49
  }
55
50
 
51
+ interface BlobPropertyBag {
52
+ type?: string;
53
+ }
54
+
56
55
  var Blob: {
57
56
  prototype: Blob;
58
57
  new (blobParts?: BlobPart[], options?: BlobPropertyBag): Blob;
@@ -22,7 +22,7 @@
22
22
  * SOFTWARE.
23
23
  ********************************************************************************/
24
24
 
25
- export * from "./express.js";
25
+ export * from "./express-document-sdk.js";
26
26
  export * from "./global.js";
27
- export * from "./script-sdk.js";
28
- export { default } from "./script-sdk.js";
27
+ export * from "./add-on-sdk-document-sandbox.js";
28
+ export { default } from "./add-on-sdk-document-sandbox.js";
package/ui/ui-sdk.d.ts CHANGED
@@ -22,8 +22,6 @@
22
22
  * SOFTWARE.
23
23
  ********************************************************************************/
24
24
 
25
- import { Remote } from "comlink";
26
-
27
25
  /**
28
26
  * Base interface for all type of add-ons
29
27
  */
@@ -134,7 +132,16 @@ export declare enum AppEvent {
134
132
  /**
135
133
  * triggered when drag is complete on the currently dragged element.
136
134
  */
137
- dragend = "dragend"
135
+ dragend = "dragend",
136
+
137
+ /**
138
+ * triggered when the document id is available in the application.
139
+ */
140
+ documentIdAvailable = "documentIdAvailable",
141
+ /**
142
+ * triggered when the document title is changed in the application.
143
+ */
144
+ documentTitleChange = "documentTitleChange"
138
145
  }
139
146
 
140
147
  export declare type AppEventHandlerType<Event extends AppEventType> = (data: AppEventsTypeMap[Event]) => void;
@@ -147,6 +154,9 @@ declare interface AppEventsTypeMap {
147
154
  [AppEvent.localechange]: AppLocaleChangeEventData;
148
155
  [AppEvent.dragstart]: AppDragStartEventData;
149
156
  [AppEvent.dragend]: AppDragEndEventData;
157
+
158
+ [AppEvent.documentIdAvailable]: DocumentIdAvailableEventData;
159
+ [AppEvent.documentTitleChange]: DocumentTitleChangeEventData;
150
160
  }
151
161
 
152
162
  export declare type AppEventType = keyof AppEventsTypeMap & string;
@@ -552,9 +562,35 @@ declare interface Document_2 {
552
562
  * Create renditions
553
563
  */
554
564
  createRenditions(renditionOptions: RenditionOptions, renditionIntent?: RenditionIntent): Promise<Rendition[]>;
565
+ /**
566
+ * Get metadata of all or range of pages of the document
567
+ */
568
+ getPagesMetadata(options: PageMetadataOptions): Promise<PageMetadata[]>;
569
+ /**
570
+ * Get document id
571
+ */
572
+ id(): Promise<string | undefined>;
573
+ /**
574
+ * Get document name/title
575
+ */
576
+ title(): Promise<string>;
555
577
  }
556
578
  export { Document_2 as Document };
557
579
 
580
+ /**
581
+ * The payload data sent to the document id available event handler.
582
+ */
583
+ declare interface DocumentIdAvailableEventData {
584
+ documentId: string | undefined;
585
+ }
586
+
587
+ /**
588
+ * The payload data sent to the document title change event handler.
589
+ */
590
+ declare interface DocumentTitleChangeEventData {
591
+ documentTitle: string;
592
+ }
593
+
558
594
  /**
559
595
  * Interface to hold various callbacks which are required to be passed to enableDragToDocument.
560
596
  */
@@ -673,11 +709,64 @@ export declare interface JpgRenditionOptions extends RenditionOptions {
673
709
  };
674
710
  }
675
711
 
712
+ /**
713
+ * Takes the raw type of a remote object or function as a remote thread would see it through a proxy (e.g. when
714
+ * passed in as a function argument) and returns the type the local thread has to supply.
715
+ * Creation of new class objects is not allowed.
716
+ *
717
+ * This is the inverse of `Remote<T>`. It takes a `Remote<T>` and returns its original input `T`.
718
+ */
719
+ declare type Local<T> = LocalObject<T> &
720
+ (T extends (...args: infer TArguments) => infer TReturn
721
+ ? (
722
+ ...args: {
723
+ [I in keyof TArguments]: ProxyOrClone<TArguments[I]>;
724
+ }
725
+ ) => MaybePromise<UnproxyOrClone<Unpromisify<TReturn>>>
726
+ : unknown) &
727
+ (T extends {
728
+ new (...args: infer TArguments): infer TInstance;
729
+ }
730
+ ? {
731
+ new: never;
732
+ }
733
+ : unknown);
734
+
676
735
  /**
677
736
  * Placeholder for future localization support
678
737
  */
679
738
  export declare type LocalizedString = string;
680
739
 
740
+ /**
741
+ * Takes the type of an object as a remote thread would see it through a proxy (e.g. when passed in as a function
742
+ * argument) and returns the type that the local thread has to supply.
743
+ *
744
+ * This does not handle call signatures, which is handled by the more general `Local<T>` type.
745
+ *
746
+ * This is the inverse of `RemoteObject<T>`.
747
+ *
748
+ * @template T The type of a proxied object.
749
+ */
750
+ declare type LocalObject<T> = {
751
+ [P in keyof T]: LocalProperty<T[P]>;
752
+ };
753
+
754
+ /**
755
+ * Takes the raw type of a property as a remote thread would see it through a proxy (e.g. when passed in as a function
756
+ * argument) and returns the type that the local thread has to supply.
757
+ *
758
+ * This is the inverse of `RemoteProperty<T>`.
759
+ *
760
+ * Note: This needs to be its own type alias, otherwise it will not distribute over unions. See
761
+ * https://www.typescriptlang.org/docs/handbook/advanced-types.html#distributive-conditional-types
762
+ */
763
+ declare type LocalProperty<T> = T extends Function | ProxyMarked ? Local<T> : Unpromisify<T>;
764
+
765
+ /**
766
+ * Expresses that a type can be either a sync or async.
767
+ */
768
+ declare type MaybePromise<T> = Promise<T> | T;
769
+
681
770
  /**
682
771
  * Media Attributes for importing media
683
772
  */
@@ -707,6 +796,53 @@ export declare interface OAuth {
707
796
  authorizeWithOwnRedirect(request: AuthorizeWithOwnRedirectRequest): Promise<AuthorizationResult>;
708
797
  }
709
798
 
799
+ /**
800
+ * Represents the metadata of the Page
801
+ */
802
+ export declare interface PageMetadata {
803
+ /**
804
+ * Unique id that represent the given page
805
+ */
806
+ id: string;
807
+ /**
808
+ * Page title
809
+ */
810
+ title: string;
811
+ /**
812
+ * Page size in pixels
813
+ */
814
+ size: {
815
+ width: number;
816
+ height: number;
817
+ };
818
+ /**
819
+ * Whether page contains any premium content
820
+ */
821
+ hasPremiumContent: boolean;
822
+ /**
823
+ * Whether page contains timelines
824
+ */
825
+ hasTemporalContent: boolean;
826
+ /**
827
+ * Pixels per inch of the page
828
+ */
829
+ pixelsPerInch?: number;
830
+ }
831
+
832
+ /**
833
+ * Options for fetching page metadata
834
+ */
835
+ export declare interface PageMetadataOptions {
836
+ /**
837
+ * Page range of the document to get the metadata
838
+ */
839
+ range: Range_2;
840
+ /**
841
+ * Ids of the pages (Only required if the range is "specificPages")
842
+ */
843
+ pageIds?: string[];
844
+ }
845
+
710
846
  export declare interface PageRendition extends Rendition {
711
847
  /**
712
848
  * Page rendition type
@@ -716,6 +852,10 @@ export declare interface PageRendition extends Rendition {
716
852
  * Page title
717
853
  */
718
854
  title: string;
855
+ /**
856
+ * Page metadata
857
+ */
858
+ metadata: PageMetadata;
719
859
  }
720
860
 
721
861
  export declare interface PngRenditionOptions extends RenditionOptions {
@@ -738,6 +878,29 @@ export declare interface PngRenditionOptions extends RenditionOptions {
738
878
  };
739
879
  }
740
880
 
881
+ /**
882
+ * Takes a type and wraps it in a Promise, if it not already is one.
883
+ * This is to avoid `Promise<Promise<T>>`.
884
+ *
885
+ * This is the inverse of `Unpromisify<T>`.
886
+ */
887
+ declare type Promisify<T> = T extends Promise<unknown> ? T : Promise<T>;
888
+
889
+ /**
890
+ * Interface of values that were marked to be proxied with `Runtime.apiProxy()`.
891
+ * Can also be implemented by classes.
892
+ */
893
+ declare interface ProxyMarked {
894
+ [proxyMarker]: true;
895
+ }
896
+
897
+ declare const proxyMarker: unique symbol;
898
+
899
+ /**
900
+ * Proxies `T` if it is a `ProxyMarked`, clones it otherwise (as handled by structured cloning and transfer handlers).
901
+ */
902
+ declare type ProxyOrClone<T> = T extends ProxyMarked ? Remote<T> : T;
903
+
741
904
  /**
742
905
  * Rendition page range
743
906
  */
@@ -749,10 +912,55 @@ declare enum Range_2 {
749
912
  /**
750
913
  * Generate rendition for all the pages
751
914
  */
752
- entireDocument = "entireDocument"
915
+ entireDocument = "entireDocument",
916
+ /**
917
+ * Generate rendition for specific pages
918
+ */
919
+ specificPages = "specificPages"
753
920
  }
754
921
  export { Range_2 as Range };
755
922
 
923
+ /**
924
+ * Takes the raw type of a remote object or function in the other thread and returns the type as it is visible to
925
+ * the local thread from the proxy return value of `Runtime.apiProxy()`.
926
+ * Creation of new class objects is not allowed.
927
+ */
928
+ declare type Remote<T> = RemoteObject<T> &
929
+ (T extends (...args: infer TArguments) => infer TReturn
930
+ ? (
931
+ ...args: {
932
+ [I in keyof TArguments]: UnproxyOrClone<TArguments[I]>;
933
+ }
934
+ ) => Promisify<ProxyOrClone<Unpromisify<TReturn>>>
935
+ : unknown) &
936
+ (T extends {
937
+ new (...args: infer TArguments): infer TInstance;
938
+ }
939
+ ? {
940
+ new: never;
941
+ }
942
+ : unknown);
943
+
944
+ /**
945
+ * Takes the raw type of a remote object in the other thread and returns the type as it is visible to the local thread
946
+ * when proxied with `Runtime.apiProxy()`.
947
+ *
948
+ * This does not handle call signatures, which is handled by the more general `Remote<T>` type.
949
+ *
950
+ * @template T The raw type of a remote object as seen in the other thread.
951
+ */
952
+ declare type RemoteObject<T> = {
953
+ [P in keyof T]: RemoteProperty<T[P]>;
954
+ };
955
+
956
+ /**
957
+ * Takes the raw type of a remote property and returns the type that is visible to the local thread on the proxy.
958
+ *
959
+ * Note: This needs to be its own type alias, otherwise it will not distribute over unions.
960
+ * See https://www.typescriptlang.org/docs/handbook/advanced-types.html#distributive-conditional-types
961
+ */
962
+ declare type RemoteProperty<T> = T extends Function | ProxyMarked ? Remote<T> : Promisify<T>;
963
+
756
964
  export declare interface Rendition {
757
965
  /**
758
966
  * Type of Rendition
@@ -809,6 +1017,10 @@ export declare interface RenditionOptions {
809
1017
  * Format of the rendition
810
1018
  */
811
1019
  format: RenditionFormat;
1020
+ /**
1021
+ * Ids of the pages (Only required if the range is "specificPages")
1022
+ */
1023
+ pageIds?: string[];
812
1024
  }
813
1025
 
814
1026
  /**
@@ -831,21 +1043,20 @@ export declare interface Runtime {
831
1043
  dialog?: Dialog;
832
1044
 
833
1045
  /**
834
- * @experimental - Experimental API
835
1046
  * Exposes the concrete object/function of type T,
836
- * which can be accessed into different runtime part of this AddOn e.g., "script" runtime.
1047
+ * which can be accessed into different runtime part of this AddOn e.g., "document model sandbox" runtime.
837
1048
  * Note that only concrete objects / class instances are supported. We can't expose entire class
838
1049
  * from one runtime and create instance of that class in another runtime. Trying to do
839
1050
  * so may result in undefined behaviour.
840
1051
  * @param apiObj - the concrete object to expose to other runtimes
841
1052
  *
842
1053
  * Notes:
843
- * 1. This method is only present if this is a panel runtime and it has an associated script runtime.
1054
+ * 1. This method is only present if this UI runtime represents panel UI (not RuntimeType.dialog),
1055
+ * and the add-on has an associated document model sandbox. The sandbox runtime provides similar method to expose APIs in the other direction.
844
1056
  * 2. This method call is allowed only once. Subsequent calls are ignored.
845
1057
  */
846
1058
  exposeApi?<T>(apiObj: T): void;
847
1059
  /**
848
- * @experimental - Experimental API
849
1060
  * Requests a promise based proxy object for other runtimes, which will be used
850
1061
  * by this UI runtime to directly call the APIs exposed (using exposeApi) from the other runtimes.
851
1062
  * await or .then is necessary, since returned object is a promise.
@@ -855,7 +1066,8 @@ export declare interface Runtime {
855
1066
  * @see https://github.com/GoogleChromeLabs/comlink/blob/main/src/comlink.ts#L117
856
1067
  *
857
1068
  * Note:
858
- * 1. This method is only present if this is a panel runtime and it has an associated script runtime.
1069
+ * 1. This method is only present if this UI runtime represents panel UI (not RuntimeType.dialog),
1070
+ * and the add-on has an associated document model sandbox. The sandbox runtime provides similar method to get proxy object in the other direction.
859
1071
  * 2. Calling the method again for same runtime type will return a new proxy object without any behavior difference.
860
1072
  */
861
1073
  apiProxy?<T>(runtimeType: RuntimeType): Promise<Remote<T>>;
@@ -871,9 +1083,14 @@ export declare enum RuntimeType {
871
1083
  */
872
1084
  dialog = "dialog",
873
1085
  /**
874
- * Add-On's script runtime - js runtime that hosts the add-ons script / document authoring logic.
1086
+ * @deprecated Use `documentSandbox` instead.
1087
+ * Add-On's document model sandbox - JS runtime that hosts add-on code that has direct access to the full model.
1088
+ */
1089
+ script = "script",
1090
+ /**
1091
+ * Add-On's document model sandbox - JS runtime that hosts add-on code that has direct access to the full model.
875
1092
  */
876
- script = "script"
1093
+ documentSandbox = "documentSandbox"
877
1094
  }
878
1095
 
879
1096
  export declare type SimpleDialogOptions = AlertDialogOptions | InputDialogOptions;
@@ -898,6 +1115,19 @@ export declare interface UI {
898
1115
 
899
1116
  declare type UiTheme = "light" | "dark" | "lightest" | "darkest";
900
1117
 
1118
+ /**
1119
+ * Takes a type that may be Promise and unwraps the Promise type.
1120
+ * If `P` is not a Promise, it returns `P`.
1121
+ *
1122
+ * This is the inverse of `Promisify<T>`.
1123
+ */
1124
+ declare type Unpromisify<P> = P extends Promise<infer T> ? T : P;
1125
+
1126
+ /**
1127
+ * Inverse of `ProxyOrClone<T>`.
1128
+ */
1129
+ declare type UnproxyOrClone<T> = T extends RemoteObject<ProxyMarked> ? Local<T> : T;
1130
+
901
1131
  /**
902
1132
  * Types of dialog variants supported.
903
1133
  */
@@ -1,101 +0,0 @@
1
- /********************************************************************************
2
- * MIT License
3
-
4
- * © Copyright 2023 Adobe. All rights reserved.
5
-
6
- * Permission is hereby granted, free of charge, to any person obtaining a copy
7
- * of this software and associated documentation files (the "Software"), to deal
8
- * in the Software without restriction, including without limitation the rights
9
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
- * copies of the Software, and to permit persons to whom the Software is
11
- * furnished to do so, subject to the following conditions:
12
- *
13
- * The above copyright notice and this permission notice shall be included in all
14
- * copies or substantial portions of the Software.
15
- *
16
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
- * SOFTWARE.
23
- ********************************************************************************/
24
-
25
- import { Remote } from "comlink";
26
-
27
- /**
28
- * Represents the instance of this AddOn.
29
- * The instance contains the necessary details like the associated Runtime etc.
30
- */
31
- export declare class AddOn {
32
- /**
33
- * Get the runtime instance, which represents
34
- * the execution environment for this AddOn.
35
- */
36
- get runtime(): Runtime;
37
- }
38
-
39
- /**
40
- * The APIs provided by AddOn Script SDK.
41
- * The APIs are exposed as an ES6 module.
42
- */
43
- export declare class AddOnScriptSDK {
44
- /**
45
- * Returns the instance of this AddOn.
46
- * @see AddOn
47
- */
48
- get instance(): AddOn;
49
- }
50
-
51
- declare const addOnScriptSdk: AddOnScriptSDK;
52
- export default addOnScriptSdk;
53
-
54
- /**
55
- * The instance of Runtime this AddOn is running into.
56
- * It contains methods to expose APIs from this runtime
57
- * and getting access to APIs exposed by other runtimes.
58
- */
59
- export declare class Runtime {
60
- /**
61
- * The runtime-type of this Runtime.
62
- * Will always be "script".
63
- */
64
- get type(): RuntimeType.script;
65
- /**
66
- * Exposes the concrete object/function of type T,
67
- * which can be accessed into different runtime part of this AddOn e.g., "panel" (iframe) runtime.
68
- * Note that only concrete objects / class instances are supported. We can't expose entire class
69
- * from one runtime and create instance of that class in another runtime. Trying to do
70
- * so may result in undefined behaviour.
71
- * @param obj - the concrete object to expose to other runtimes
72
- * Note: This method call is allowed only once. Subsequent calls are ignored.
73
- */
74
- exposeApi<T>(obj: T): void;
75
- /**
76
- * Requests a promise based proxy object for other runtimes, which will be used
77
- * by this script runtime to directly call the APIs exposed (using exposeApi) from the other runtimes (e.g., UI runtime).
78
- * await or .then is necessary, since returned object is a promise.
79
- * @param runtimeType - the runtime, for which proxy object needs to be created.
80
- * @returns a promise which may resolve to a proxy or reject with rejection reason.
81
- * The promise resolves to API proxy object exposed by desired runtime, as soon as the other runtime is finished initializing.
82
- * Note: Calling the method again for same runtime type will return a new proxy object without any behavior difference.
83
- */
84
- apiProxy(runtimeType: RuntimeType): Promise<Remote<unknown>>;
85
- }
86
-
87
- /**
88
- * Supported runtime types for this AddOn.
89
- */
90
- export declare enum RuntimeType {
91
- /**
92
- * Represents iframe runtime part of this AddOn.
93
- */
94
- panel = "panel",
95
- /**
96
- * Represents Script runtime part of this AddOn.
97
- */
98
- script = "script"
99
- }
100
-
101
- export {};