@adobe/uix-guest 0.6.3
Sign up to get free protection for your applications and to get access to all the features.
- package/LICENSE +201 -0
- package/README.md +1 -0
- package/dist/debug-guest.d.ts +8 -0
- package/dist/debug-guest.d.ts.map +1 -0
- package/dist/esm/index.js +155 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/guest-server.d.ts +53 -0
- package/dist/guest-server.d.ts.map +1 -0
- package/dist/guest-ui.d.ts +102 -0
- package/dist/guest-ui.d.ts.map +1 -0
- package/dist/guest.d.ts +160 -0
- package/dist/guest.d.ts.map +1 -0
- package/dist/iife/index.js +761 -0
- package/dist/iife/index.js.map +1 -0
- package/dist/index.d.ts +105 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +172 -0
- package/dist/index.js.map +1 -0
- package/package.json +39 -0
- package/src/debug-guest.ts +42 -0
- package/src/guest-server.ts +56 -0
- package/src/guest-ui.ts +123 -0
- package/src/guest.ts +255 -0
- package/src/index.ts +142 -0
- package/tsconfig.json +20 -0
package/dist/guest.d.ts
ADDED
@@ -0,0 +1,160 @@
|
|
1
|
+
import { Connection } from "penpal";
|
2
|
+
import type { RemoteHostApis, NamedEvent, VirtualApi } from "@adobe/uix-core";
|
3
|
+
import { Emitter } from "@adobe/uix-core";
|
4
|
+
/**
|
5
|
+
* @public
|
6
|
+
*/
|
7
|
+
export declare type GuestEvent<Type extends string = string, Detail = Record<string, unknown>> = NamedEvent<Type, Detail & Record<string, unknown> & {
|
8
|
+
guest: Guest;
|
9
|
+
}>;
|
10
|
+
/**
|
11
|
+
* @public
|
12
|
+
*/
|
13
|
+
export declare type GuestEventContextChange = GuestEvent<"contextchange", {
|
14
|
+
context: Record<string, unknown>;
|
15
|
+
}>;
|
16
|
+
/** @public */
|
17
|
+
export declare type GuestEventBeforeConnect = GuestEvent<"beforeconnect">;
|
18
|
+
/** @public */
|
19
|
+
export declare type GuestEventConnected = GuestEvent<"connected", {
|
20
|
+
connection: Connection;
|
21
|
+
}>;
|
22
|
+
/** @public */
|
23
|
+
export declare type GuestEventError = GuestEvent<"error", {
|
24
|
+
error: Error;
|
25
|
+
}>;
|
26
|
+
/**
|
27
|
+
* @public
|
28
|
+
*/
|
29
|
+
export declare type GuestEvents = GuestEventContextChange | GuestEventBeforeConnect | GuestEventConnected | GuestEventError;
|
30
|
+
/**
|
31
|
+
* @public
|
32
|
+
*/
|
33
|
+
export interface GuestConfig {
|
34
|
+
/**
|
35
|
+
* String slug identifying extension. This may need to use IDs from an
|
36
|
+
* external system in the future.
|
37
|
+
*/
|
38
|
+
id: string;
|
39
|
+
/**
|
40
|
+
* Set debug flags on all libraries that have them, and add loggers to SDK
|
41
|
+
* objects. Log a lot to the console.
|
42
|
+
*/
|
43
|
+
debug?: boolean;
|
44
|
+
/**
|
45
|
+
* Time out and stop trying to reach the host after this many milliseconds
|
46
|
+
*/
|
47
|
+
timeout?: number;
|
48
|
+
}
|
49
|
+
/**
|
50
|
+
* A `Map` representing the {@link @adobe/uix-host#HostConfig.sharedContext}
|
51
|
+
* object.
|
52
|
+
*
|
53
|
+
* @remarks While the Host object is a plain JavaScript object. the `sharedContext` in the Guest object implements the {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map | Map} interface.
|
54
|
+
*
|
55
|
+
* @example
|
56
|
+
* In the host app window, the Host object shares context:
|
57
|
+
* ```javascript
|
58
|
+
*host.shareContext({
|
59
|
+
* someAuthToken: 'abc'
|
60
|
+
*});
|
61
|
+
* ```
|
62
|
+
*
|
63
|
+
* After the `contentchange` event has fired in the guest window:
|
64
|
+
* ```javascript
|
65
|
+
* guest.sharedContext.get('someAuthToken') === 'abc'
|
66
|
+
* ```
|
67
|
+
* @public
|
68
|
+
*/
|
69
|
+
export declare class SharedContext {
|
70
|
+
private _map;
|
71
|
+
constructor(values: Record<string, unknown>);
|
72
|
+
private reset;
|
73
|
+
/**
|
74
|
+
* @public
|
75
|
+
* Retrieve a copy of a value from the {@link @adobe/uix-host#HostConfig.sharedContext} object. *Note that this is not a reference to any actual objects from the parent. If the parent updates an "inner object" inside the SharedContext, that change will not be reflected in the Guest!*
|
76
|
+
*/
|
77
|
+
get(key: string): unknown;
|
78
|
+
}
|
79
|
+
/**
|
80
|
+
* Generic Guest object, with methods shared by all types of Guest.
|
81
|
+
* @internal
|
82
|
+
*/
|
83
|
+
export declare class Guest<Incoming extends object = VirtualApi> extends Emitter<GuestEvents> {
|
84
|
+
/**
|
85
|
+
* Shared context has been set or updated.
|
86
|
+
* @eventProperty
|
87
|
+
*/
|
88
|
+
contextchange: GuestEventContextChange;
|
89
|
+
/**
|
90
|
+
* About to attempt connection to the host.
|
91
|
+
* @eventProperty
|
92
|
+
*/
|
93
|
+
beforeconnect: GuestEventBeforeConnect;
|
94
|
+
/**
|
95
|
+
* Host connection has been established.
|
96
|
+
* @eventProperty
|
97
|
+
*/
|
98
|
+
connected: GuestEventConnected;
|
99
|
+
/**
|
100
|
+
* Host connection has failed.
|
101
|
+
* @eventProperty
|
102
|
+
*/
|
103
|
+
error: GuestEventError;
|
104
|
+
/**
|
105
|
+
* {@inheritdoc SharedContext}
|
106
|
+
*/
|
107
|
+
sharedContext: SharedContext;
|
108
|
+
private debugLogger;
|
109
|
+
/**
|
110
|
+
* @param config - Initializer for guest object, including ID.
|
111
|
+
*/
|
112
|
+
constructor(config: GuestConfig);
|
113
|
+
/**
|
114
|
+
* Proxy object for calling methods on the host.
|
115
|
+
*
|
116
|
+
* @remarks Any APIs exposed to the extension via {@link @adobe/uix-host#Port.provide}
|
117
|
+
* can be called on this object. Because these methods are called with RPC,
|
118
|
+
* they are all asynchronous, The return types of all Host methods will be
|
119
|
+
* Promises which resolve to the value the Host method returns.
|
120
|
+
* @public
|
121
|
+
*/
|
122
|
+
host: RemoteHostApis<Incoming>;
|
123
|
+
private timeout;
|
124
|
+
private hostConnectionPromise;
|
125
|
+
private hostConnection;
|
126
|
+
/** @internal */
|
127
|
+
protected getLocalMethods(): {
|
128
|
+
emit: (type: "contextchange" | "beforeconnect" | "connected" | "error", detail: ({
|
129
|
+
context: Record<string, unknown>;
|
130
|
+
} & Record<string, unknown> & {
|
131
|
+
guest: Guest<VirtualApi>;
|
132
|
+
}) | (Record<string, unknown> & {
|
133
|
+
guest: Guest<VirtualApi>;
|
134
|
+
}) | ({
|
135
|
+
connection: Connection<import("penpal").CallSender>;
|
136
|
+
} & Record<string, unknown> & {
|
137
|
+
guest: Guest<VirtualApi>;
|
138
|
+
}) | ({
|
139
|
+
error: Error;
|
140
|
+
} & Record<string, unknown> & {
|
141
|
+
guest: Guest<VirtualApi>;
|
142
|
+
})) => void;
|
143
|
+
};
|
144
|
+
/**
|
145
|
+
* Accept a connection from the Host.
|
146
|
+
* @returns A Promise that resolves when the Host has established a connection.
|
147
|
+
* @deprecated It is preferable to use {@link register} for primary frames,
|
148
|
+
* and {@link attach} for UI frames and other secondary frames, than to
|
149
|
+
* instantiate a Guest and then call `.connect()` on it. The latter style
|
150
|
+
* returns an object that cannot be used until it is connected, and therefore
|
151
|
+
* risks errors.
|
152
|
+
* @public
|
153
|
+
*/
|
154
|
+
connect(): Promise<void>;
|
155
|
+
/**
|
156
|
+
* @internal
|
157
|
+
*/
|
158
|
+
_connect(): Promise<void>;
|
159
|
+
}
|
160
|
+
//# sourceMappingURL=guest.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"guest.d.ts","sourceRoot":"","sources":["../src/guest.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,UAAU,EAAmB,MAAM,QAAQ,CAAC;AACrD,OAAO,KAAK,EACV,cAAc,EAEd,UAAU,EACV,UAAU,EACX,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,OAAO,EAIR,MAAM,iBAAiB,CAAC;AAGzB;;GAEG;AACH,oBAAY,UAAU,CACpB,IAAI,SAAS,MAAM,GAAG,MAAM,EAC5B,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IAC9B,UAAU,CACZ,IAAI,EACJ,MAAM,GACJ,MAAM,CAAC,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