@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/LICENSE
ADDED
@@ -0,0 +1,201 @@
|
|
1
|
+
Apache License
|
2
|
+
Version 2.0, January 2004
|
3
|
+
http://www.apache.org/licenses/
|
4
|
+
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
6
|
+
|
7
|
+
1. Definitions.
|
8
|
+
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
11
|
+
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
13
|
+
the copyright owner that is granting the License.
|
14
|
+
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
16
|
+
other entities that control, are controlled by, or are under common
|
17
|
+
control with that entity. For the purposes of this definition,
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
19
|
+
direction or management of such entity, whether by contract or
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
22
|
+
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
24
|
+
exercising permissions granted by this License.
|
25
|
+
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
27
|
+
including but not limited to software source code, documentation
|
28
|
+
source, and configuration files.
|
29
|
+
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
31
|
+
transformation or translation of a Source form, including but
|
32
|
+
not limited to compiled object code, generated documentation,
|
33
|
+
and conversions to other media types.
|
34
|
+
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
36
|
+
Object form, made available under the License, as indicated by a
|
37
|
+
copyright notice that is included in or attached to the work
|
38
|
+
(an example is provided in the Appendix below).
|
39
|
+
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
46
|
+
the Work and Derivative Works thereof.
|
47
|
+
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
49
|
+
the original version of the Work and any modifications or additions
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
61
|
+
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
64
|
+
subsequently incorporated within the Work.
|
65
|
+
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
72
|
+
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
78
|
+
where such license applies only to those patent claims licensable
|
79
|
+
by such Contributor that are necessarily infringed by their
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
82
|
+
institute patent litigation against any entity (including a
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
85
|
+
or contributory patent infringement, then any patent licenses
|
86
|
+
granted to You under this License for that Work shall terminate
|
87
|
+
as of the date such litigation is filed.
|
88
|
+
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
91
|
+
modifications, and in Source or Object form, provided that You
|
92
|
+
meet the following conditions:
|
93
|
+
|
94
|
+
(a) You must give any other recipients of the Work or
|
95
|
+
Derivative Works a copy of this License; and
|
96
|
+
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
98
|
+
stating that You changed the files; and
|
99
|
+
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
102
|
+
attribution notices from the Source form of the Work,
|
103
|
+
excluding those notices that do not pertain to any part of
|
104
|
+
the Derivative Works; and
|
105
|
+
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
108
|
+
include a readable copy of the attribution notices contained
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
111
|
+
of the following places: within a NOTICE text file distributed
|
112
|
+
as part of the Derivative Works; within the Source form or
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
114
|
+
within a display generated by the Derivative Works, if and
|
115
|
+
wherever such third-party notices normally appear. The contents
|
116
|
+
of the NOTICE file are for informational purposes only and
|
117
|
+
do not modify the License. You may add Your own attribution
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
120
|
+
that such additional attribution notices cannot be construed
|
121
|
+
as modifying the License.
|
122
|
+
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
124
|
+
may provide additional or different license terms and conditions
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
128
|
+
the conditions stated in this License.
|
129
|
+
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
133
|
+
this License, without any additional terms or conditions.
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
135
|
+
the terms of any separate license agreement you may have executed
|
136
|
+
with Licensor regarding such Contributions.
|
137
|
+
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
140
|
+
except as required for reasonable and customary use in describing the
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
142
|
+
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
152
|
+
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
158
|
+
incidental, or consequential damages of any character arising as a
|
159
|
+
result of this License or out of the use or inability to use the
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
162
|
+
other commercial damages or losses), even if such Contributor
|
163
|
+
has been advised of the possibility of such damages.
|
164
|
+
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
168
|
+
or other liability obligations and/or rights consistent with this
|
169
|
+
License. However, in accepting such obligations, You may act only
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
174
|
+
of your accepting any such warranty or additional liability.
|
175
|
+
|
176
|
+
END OF TERMS AND CONDITIONS
|
177
|
+
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
179
|
+
|
180
|
+
To apply the Apache License to your work, attach the following
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
182
|
+
replaced with your own identifying information. (Don't include
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
184
|
+
comment syntax for the file format. We also recommend that a
|
185
|
+
file or class name and description of purpose be included on the
|
186
|
+
same "printed page" as the copyright notice for easier
|
187
|
+
identification within third-party archives.
|
188
|
+
|
189
|
+
Copyright 2022 Adobe
|
190
|
+
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
192
|
+
you may not use this file except in compliance with the License.
|
193
|
+
You may obtain a copy of the License at
|
194
|
+
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
196
|
+
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
200
|
+
See the License for the specific language governing permissions and
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
This is the `@adobe/uix-guest` package alone. See [/README.md](../../README.md) for details.
|
@@ -0,0 +1,8 @@
|
|
1
|
+
/**
|
2
|
+
* Adapter to attach console logging listeners to a Guest running in a frame/
|
3
|
+
* @internal @preapproved
|
4
|
+
*/
|
5
|
+
import { Emits, EmitterDebugLogger } from "@adobe/uix-core";
|
6
|
+
import { GuestEvents } from "./guest";
|
7
|
+
export declare function debugGuest(guest: Emits<GuestEvents>): EmitterDebugLogger;
|
8
|
+
//# sourceMappingURL=debug-guest.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"debug-guest.d.ts","sourceRoot":"","sources":["../src/debug-guest.ts"],"names":[],"mappings":"AAYA;;;GAGG;AACH,OAAO,EAAgB,KAAK,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAC1E,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAEtC,wBAAgB,UAAU,CAAC,KAAK,EAAE,KAAK,CAAC,WAAW,CAAC,GAAG,kBAAkB,CAsBxE"}
|
@@ -0,0 +1,155 @@
|
|
1
|
+
// src/guest.ts
|
2
|
+
import { connectToParent } from "penpal";
|
3
|
+
import {
|
4
|
+
Emitter,
|
5
|
+
makeNamespaceProxy,
|
6
|
+
timeoutPromise,
|
7
|
+
quietConsole
|
8
|
+
} from "@adobe/uix-core";
|
9
|
+
|
10
|
+
// src/debug-guest.ts
|
11
|
+
import { debugEmitter } from "@adobe/uix-core";
|
12
|
+
function debugGuest(guest) {
|
13
|
+
return debugEmitter(guest, {
|
14
|
+
theme: "yellow medium",
|
15
|
+
type: "Guest"
|
16
|
+
}).listen("beforeconnect", (log, { detail: { guest: guest2 } }) => {
|
17
|
+
log.info(guest2);
|
18
|
+
}).listen("connecting", (log, { detail: { connection } }) => {
|
19
|
+
log.info(connection);
|
20
|
+
}).listen("connected", (log, { detail: { guest: guest2 } }) => {
|
21
|
+
log.info(guest2);
|
22
|
+
}).listen("error", (log, { detail: { error, guest: guest2 } }) => {
|
23
|
+
log.error(
|
24
|
+
"\u274C Failed to connect! %s",
|
25
|
+
error.message,
|
26
|
+
guest2,
|
27
|
+
error
|
28
|
+
);
|
29
|
+
});
|
30
|
+
}
|
31
|
+
|
32
|
+
// src/guest.ts
|
33
|
+
var SharedContext = class {
|
34
|
+
constructor(values) {
|
35
|
+
this.reset(values);
|
36
|
+
}
|
37
|
+
reset(values) {
|
38
|
+
this._map = new Map(Object.entries(values));
|
39
|
+
}
|
40
|
+
get(key) {
|
41
|
+
return this._map.get(key);
|
42
|
+
}
|
43
|
+
};
|
44
|
+
var Guest2 = class extends Emitter {
|
45
|
+
constructor(config) {
|
46
|
+
super(config.id);
|
47
|
+
this.debugLogger = quietConsole;
|
48
|
+
this.host = makeNamespaceProxy(
|
49
|
+
async (address) => {
|
50
|
+
await this.hostConnectionPromise;
|
51
|
+
try {
|
52
|
+
const result = await timeoutPromise(
|
53
|
+
1e4,
|
54
|
+
this.hostConnection.invokeHostMethod(address)
|
55
|
+
);
|
56
|
+
return result;
|
57
|
+
} catch (e) {
|
58
|
+
const error = e instanceof Error ? e : new Error(e);
|
59
|
+
const methodError = new Error(
|
60
|
+
`Host method call host.${address.path.join(".")}() failed: ${error.message}`
|
61
|
+
);
|
62
|
+
this.debugLogger.error(methodError);
|
63
|
+
throw methodError;
|
64
|
+
}
|
65
|
+
}
|
66
|
+
);
|
67
|
+
this.timeout = 1e4;
|
68
|
+
if (typeof config.timeout === "number") {
|
69
|
+
this.timeout = config.timeout;
|
70
|
+
}
|
71
|
+
if (config.debug) {
|
72
|
+
this.debugLogger = debugGuest(this);
|
73
|
+
}
|
74
|
+
this.addEventListener("contextchange", (event) => {
|
75
|
+
this.sharedContext = new SharedContext(event.detail.context);
|
76
|
+
});
|
77
|
+
}
|
78
|
+
getLocalMethods() {
|
79
|
+
return {
|
80
|
+
emit: (...args) => {
|
81
|
+
this.debugLogger.log(`Event "${args[0]}" emitted from host`);
|
82
|
+
this.emit(...args);
|
83
|
+
}
|
84
|
+
};
|
85
|
+
}
|
86
|
+
async connect() {
|
87
|
+
return this._connect();
|
88
|
+
}
|
89
|
+
async _connect() {
|
90
|
+
this.emit("beforeconnect", { guest: this });
|
91
|
+
try {
|
92
|
+
const connection = connectToParent({
|
93
|
+
timeout: this.timeout,
|
94
|
+
methods: this.getLocalMethods()
|
95
|
+
});
|
96
|
+
this.hostConnectionPromise = connection.promise;
|
97
|
+
this.hostConnection = await this.hostConnectionPromise;
|
98
|
+
this.sharedContext = new SharedContext(
|
99
|
+
await this.hostConnection.getSharedContext()
|
100
|
+
);
|
101
|
+
this.debugLogger.log("retrieved sharedContext", this.sharedContext);
|
102
|
+
this.emit("connected", { guest: this, connection });
|
103
|
+
} catch (e) {
|
104
|
+
this.emit("error", { guest: this, error: e });
|
105
|
+
this.debugLogger.error("Connection failed!", e);
|
106
|
+
}
|
107
|
+
}
|
108
|
+
};
|
109
|
+
|
110
|
+
// src/guest-ui.ts
|
111
|
+
var GuestUI = class extends Guest2 {
|
112
|
+
constructor(config) {
|
113
|
+
super(config);
|
114
|
+
}
|
115
|
+
};
|
116
|
+
|
117
|
+
// src/guest-server.ts
|
118
|
+
var GuestServer = class extends Guest2 {
|
119
|
+
getLocalMethods() {
|
120
|
+
return {
|
121
|
+
...super.getLocalMethods(),
|
122
|
+
apis: this.localMethods
|
123
|
+
};
|
124
|
+
}
|
125
|
+
async register(implementedMethods) {
|
126
|
+
this.localMethods = implementedMethods;
|
127
|
+
return this._connect();
|
128
|
+
}
|
129
|
+
};
|
130
|
+
|
131
|
+
// src/index.ts
|
132
|
+
function createGuest(config) {
|
133
|
+
const guest = new GuestServer(config);
|
134
|
+
return guest;
|
135
|
+
}
|
136
|
+
async function attach(config) {
|
137
|
+
const guest = new GuestUI(config);
|
138
|
+
await guest._connect();
|
139
|
+
return guest;
|
140
|
+
}
|
141
|
+
async function register(config) {
|
142
|
+
const guest = new GuestServer(config);
|
143
|
+
await guest.register(config.methods);
|
144
|
+
return guest;
|
145
|
+
}
|
146
|
+
export {
|
147
|
+
GuestServer,
|
148
|
+
GuestUI,
|
149
|
+
GuestServer as PrimaryGuest,
|
150
|
+
GuestUI as UIGuest,
|
151
|
+
attach,
|
152
|
+
createGuest,
|
153
|
+
register
|
154
|
+
};
|
155
|
+
//# sourceMappingURL=index.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../../src/guest.ts","../../src/debug-guest.ts","../../src/guest-ui.ts","../../src/guest-server.ts","../../src/index.ts"],"sourcesContent":["/*\nCopyright 2022 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\n/* eslint @typescript-eslint/no-explicit-any: \"off\" */\nimport { Connection, connectToParent } from \"penpal\";\nimport type {\n RemoteHostApis,\n HostConnection,\n NamedEvent,\n VirtualApi,\n} from \"@adobe/uix-core\";\nimport {\n Emitter,\n makeNamespaceProxy,\n timeoutPromise,\n quietConsole,\n} from \"@adobe/uix-core\";\nimport { debugGuest } from \"./debug-guest.js\";\n\n/**\n * @public\n */\nexport type GuestEvent<\n Type extends string = string,\n Detail = Record<string, unknown>\n> = NamedEvent<\n Type,\n Detail &\n Record<string, unknown> & {\n guest: Guest;\n }\n>;\n\n/**\n * @public\n */\nexport type GuestEventContextChange = GuestEvent<\n \"contextchange\",\n { context: Record<string, unknown> }\n>;\n\n/** @public */\nexport type GuestEventBeforeConnect = GuestEvent<\"beforeconnect\">;\n/** @public */\nexport type GuestEventConnected = GuestEvent<\n \"connected\",\n { connection: Connection }\n>;\n/** @public */\nexport type GuestEventError = GuestEvent<\"error\", { error: Error }>;\n\n/**\n * @public\n */\nexport type GuestEvents =\n | GuestEventContextChange\n | GuestEventBeforeConnect\n | GuestEventConnected\n | GuestEventError;\n\n/**\n * @public\n */\nexport interface GuestConfig {\n /**\n * String slug identifying extension. This may need to use IDs from an\n * external system in the future.\n */\n id: string;\n /**\n * Set debug flags on all libraries that have them, and add loggers to SDK\n * objects. Log a lot to the console.\n */\n debug?: boolean;\n /**\n * Time out and stop trying to reach the host after this many milliseconds\n */\n timeout?: number;\n}\n\n/**\n * A `Map` representing the {@link @adobe/uix-host#HostConfig.sharedContext}\n * object.\n *\n * @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.\n *\n * @example\n * In the host app window, the Host object shares context:\n * ```javascript\n *host.shareContext({\n * someAuthToken: 'abc'\n *});\n * ```\n *\n * After the `contentchange` event has fired in the guest window:\n * ```javascript\n * guest.sharedContext.get('someAuthToken') === 'abc'\n * ```\n * @public\n */\nexport class SharedContext {\n private _map: Map<string, unknown>;\n constructor(values: Record<string, unknown>) {\n this.reset(values);\n }\n private reset(values: Record<string, unknown>) {\n this._map = new Map(Object.entries(values));\n }\n /**\n * @public\n * 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!*\n */\n get(key: string) {\n return this._map.get(key);\n }\n}\n\n/**\n * Generic Guest object, with methods shared by all types of Guest.\n * @internal\n */\nexport class Guest<\n Incoming extends object = VirtualApi\n> extends Emitter<GuestEvents> {\n /**\n * Shared context has been set or updated.\n * @eventProperty\n */\n public contextchange: GuestEventContextChange;\n /**\n * About to attempt connection to the host.\n * @eventProperty\n */\n public beforeconnect: GuestEventBeforeConnect;\n /**\n * Host connection has been established.\n * @eventProperty\n */\n public connected: GuestEventConnected;\n /**\n * Host connection has failed.\n * @eventProperty\n */\n public error: GuestEventError;\n /**\n * {@inheritdoc SharedContext}\n */\n sharedContext: SharedContext;\n private debugLogger: Console = quietConsole;\n\n /**\n * @param config - Initializer for guest object, including ID.\n */\n constructor(config: GuestConfig) {\n super(config.id);\n if (typeof config.timeout === \"number\") {\n this.timeout = config.timeout;\n }\n if (config.debug) {\n this.debugLogger = debugGuest(this);\n }\n this.addEventListener(\"contextchange\", (event) => {\n this.sharedContext = new SharedContext(event.detail.context);\n });\n }\n /**\n * Proxy object for calling methods on the host.\n *\n * @remarks Any APIs exposed to the extension via {@link @adobe/uix-host#Port.provide}\n * can be called on this object. Because these methods are called with RPC,\n * they are all asynchronous, The return types of all Host methods will be\n * Promises which resolve to the value the Host method returns.\n * @public\n */\n host: RemoteHostApis<Incoming> = makeNamespaceProxy<Incoming>(\n async (address) => {\n await this.hostConnectionPromise;\n try {\n const result = await timeoutPromise(\n 10000,\n this.hostConnection.invokeHostMethod(address)\n );\n return result;\n } catch (e) {\n const error =\n e instanceof Error ? e : new Error(e as unknown as string);\n const methodError = new Error(\n `Host method call host.${address.path.join(\".\")}() failed: ${\n error.message\n }`\n );\n this.debugLogger.error(methodError);\n throw methodError;\n }\n }\n );\n private timeout = 10000;\n private hostConnectionPromise: Promise<RemoteHostApis<HostConnection>>;\n private hostConnection!: RemoteHostApis<HostConnection>;\n /** @internal */\n protected getLocalMethods() {\n return {\n emit: (...args: Parameters<typeof this.emit>) => {\n this.debugLogger.log(`Event \"${args[0]}\" emitted from host`);\n this.emit(...args);\n },\n };\n }\n /**\n * Accept a connection from the Host.\n * @returns A Promise that resolves when the Host has established a connection.\n * @deprecated It is preferable to use {@link register} for primary frames,\n * and {@link attach} for UI frames and other secondary frames, than to\n * instantiate a Guest and then call `.connect()` on it. The latter style\n * returns an object that cannot be used until it is connected, and therefore\n * risks errors.\n * @public\n */\n async connect() {\n return this._connect();\n }\n\n /**\n * @internal\n */\n async _connect() {\n this.emit(\"beforeconnect\", { guest: this });\n try {\n const connection = connectToParent<HostConnection<Incoming>>({\n timeout: this.timeout,\n methods: this.getLocalMethods(),\n });\n\n this.hostConnectionPromise = connection.promise;\n this.hostConnection = await this.hostConnectionPromise;\n this.sharedContext = new SharedContext(\n await this.hostConnection.getSharedContext()\n );\n this.debugLogger.log(\"retrieved sharedContext\", this.sharedContext);\n this.emit(\"connected\", { guest: this, connection });\n } catch (e) {\n this.emit(\"error\", { guest: this, error: e });\n this.debugLogger.error(\"Connection failed!\", e);\n }\n }\n}\n","/*\nCopyright 2022 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\n/**\n * Adapter to attach console logging listeners to a Guest running in a frame/\n * @internal @preapproved\n */\nimport { debugEmitter, Emits, EmitterDebugLogger } from \"@adobe/uix-core\";\nimport { GuestEvents } from \"./guest\";\n\nexport function debugGuest(guest: Emits<GuestEvents>): EmitterDebugLogger {\n return debugEmitter(guest, {\n theme: \"yellow medium\",\n type: \"Guest\",\n })\n .listen(\"beforeconnect\", (log, { detail: { guest } }) => {\n log.info(guest);\n })\n .listen(\"connecting\", (log, { detail: { connection } }) => {\n log.info(connection);\n })\n .listen(\"connected\", (log, { detail: { guest } }) => {\n log.info(guest);\n })\n .listen(\"error\", (log, { detail: { error, guest } }) => {\n log.error(\n \"❌ Failed to connect! %s\",\n (error as Error).message,\n guest,\n error\n );\n });\n}\n","/*\nCopyright 2022 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport type { RemoteHostApis, VirtualApi } from \"@adobe/uix-core\";\nimport {\n Guest,\n GuestConfig,\n GuestEventBeforeConnect,\n GuestEventConnected,\n GuestEventContextChange,\n GuestEventError,\n} from \"./guest\";\n\n/**\n * A Guest to be used in an extension-controlled frame, usually to display UI.\n *\n * @typeParam Incoming - Optional interface of host methods. If using\n * TypeScript, supply this type parameter and a promisified version of the\n * interface will be available at {@link Guest.host}\n *\n * @remarks\n * This is the object returned when calling {@link @adobe/uix-guest#attach}. It\n * represents an additional frame or runtime created by the host application, on\n * behalf of the extension's control frame which is running the {@link\n * GuestServer}. It is a \"secondary\" guest object, which a host won't use before\n * the control frame has connected. It exposes a subset of the functionality of\n * the {@link GuestServer}.\n *\n * Unlike the {@link GuestServer}, it cannot register methods or update the\n * {@link Guest.sharedContext}, but it remains in sync with the GuestServer and\n * can access the {@link Guest.sharedContext} of the control frame, as well as\n * any of the published methods on the host.\n *\n * Extensible host apps using the React bindings will likely render GuestUI\n * frames using the {@link @adobe/uix-host-react#GuestUIFrame} component.\n *\n * @example\n * When an extensible app renders this page, {@link @adobe/uix-guest#attach}\n * creates a GuestUI. Once it attaches to the host, it\n * ```javascript\n * import React, { useEffect, useState } from \"react\";\n * import { attach } from \"@adobe/uix-guest\";\n * import { Tooltip } from \"./tooltip\";\n *\n * export default function PopupOverlay(props) {\n * // how large am I?\n * const [dimensions, setDimensions] = useState(\n * document.body.getBoundingClientRect()\n * );\n * // if possible, use language preloaded in query parameters\n * const [language, setLanguage] = useState(props.params.lang)\n *\n * // attach only once, in a useEffect\n * useEffect(() => {\n * attach({\n * id: \"my-extension-id\",\n * debug: true,\n * })\n * .then(guestUI => {\n * // this event fires whenever the host, or the control frame, changes\n * // any sharedContext value\n * guestUI.addEventListener(\"contextchange\", ({ detail: { context }}) => {\n * setLanguage(context.lang)\n * });\n * // how large does the host want me to be?\n * return guestUI.host.tooltips.getDimensions()\n * .then(setDimensions)\n * })\n * .catch((e) => {\n * console.error(\"ui attach failed\", e);\n * });\n * }, []);\n * // render UI! Due to the setup and useState, this component will re-render\n * // once attach() is complete.\n * return (\n * <Tooltip {...props.params} lang={language} dimensions={dimensions} />\n * );\n * }\n * ```\n *\n * @public\n */\nexport class GuestUI<IHost extends VirtualApi> extends Guest<IHost> {\n /**\n * {@inheritDoc Guest.\"constructor\"}\n */\n constructor(config: GuestConfig) {\n super(config);\n }\n /**\n * {@inheritDoc Guest.contextchange}\n * @eventProperty\n */\n public contextchange: GuestEventContextChange;\n /**\n * {@inheritDoc Guest.beforeconnect}\n * @eventProperty\n */\n public beforeconnect: GuestEventBeforeConnect;\n /**\n * {@inheritDoc Guest.connected}\n * @eventProperty\n */\n public connected: GuestEventConnected;\n /**\n * {@inheritDoc Guest.error}\n * @eventProperty\n */\n public error: GuestEventError;\n /**\n * {@inheritDoc Guest.host}\n */\n host: RemoteHostApis<IHost>;\n}\n","/*\nCopyright 2022 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport type { GuestApis } from \"@adobe/uix-core\";\nimport type { SharedContext } from \"./guest\";\nimport { Guest } from \"./guest\";\n\n/**\n * A Guest to be used in the \"main\" or primary frame of an extension, the frame\n * the Host loads first.\n *\n * @remarks This is the Guest object returned from {@link register}. It can\n * expose internal methods to the Host via the {@link GuestServer.register}\n * method.\n *\n *\n * @public\n */\nexport class GuestServer<Outgoing extends GuestApis> extends Guest<Outgoing> {\n private localMethods: Outgoing;\n protected getLocalMethods() {\n return {\n ...super.getLocalMethods(),\n apis: this.localMethods,\n };\n }\n /**\n * {@inheritDoc BaseGuest.sharedContext}\n */\n sharedContext: SharedContext;\n /**\n * {@inheritdoc BaseGuest.host}\n */\n host: Guest<Outgoing>[\"host\"];\n /**\n * Pass an interface of methods which Host may call as callbacks.\n *\n * @remarks It is preferable to use {@link register} to obtain a guest object\n * and register local methods in one step. The returned guest object will be\n * pre-registered and connected.\n * @public\n */\n async register(implementedMethods: Outgoing) {\n this.localMethods = implementedMethods;\n return this._connect();\n }\n}\n","/*\nCopyright 2022 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\n/**\n * @packageDocumentation\n * Tools for UI Extensions meant to run inside extensible apps. Connects\n * Extensions running in their own window contexts with the host app, allowing\n * the host and guest to exchange method, events, and signals.\n *\n * @remarks The core object of this library, which extensions use for\n * communication, is the Guest object. There are two variants of the Guest\n * object {@link GuestServer} for the bootstrap frame which your extension keeps\n * running in the background, and {@link GuestUI} for frames meant to be\n * displayed in the host application. An extension must have one GuestServer\n * frame, and the host app may choose to use one or more GuestUI frames.\n *\n * @example Creating and connecting a GuestServer with {@link register}\n * ```typescript\n * import { register } from \"@adobe/uix-guest\";\n *\n * const server = await register({\n * // Must match extension ID from registry\n * id: \"My Custom View Extension\",\n * // enable logging in dev build\n * debug: process.env.NODE_ENV !== \"production\",\n * // Host can access these methods from its Port to this guest\n * methods: {\n * // Methods must be namespaced by one or more levels\n * myCustomView: {\n * async documentIsViewable(docId) {\n * const doc = await callMyRuntimeAction(docId);\n * return someValidation(doc);\n * },\n * renderView(docId, depth) {\n * // Use a host method\n * const tooltip = await server.host.editor.requestTooltip({\n * type: 'frame',\n * url: new URL(`/show/${docId}`, location).href\n * })\n * }\n * },\n * },\n * })\n * ```\n *\n * @example Connecting to an existing GuestServer with a GuestUI\n * ```typescript\n * import { attach } from \"@adobe/uix-guest\";\n *\n * const ui = await attach({\n * id: \"My Custom View Extension\",\n * })\n *\n * // when editing is done:\n * const saved = await ui.host.editor.saveChanges();\n * if (!saved) {\n * const editorState = ui.sharedContext.get('editorState');\n * if (editorState.tooltips[ui.id].invalid === true) {\n * putGuestUIInInvalidState();\n * }\n * } else {\n * ui.host.editor.dismissTooltip();\n * }\n * ```\n *\n */\nimport type { Guest, GuestConfig } from \"./guest.js\";\nimport { GuestUI } from \"./guest-ui.js\";\nimport { GuestServer } from \"./guest-server.js\";\nimport { GuestApis } from \"@adobe/uix-core\";\n\n/**\n * {@inheritdoc GuestConfig}\n * @public\n */\ntype GuestConfigWithMethods<Outgoing extends GuestApis> = GuestConfig & {\n methods: Outgoing;\n};\n\n/**\n * Create and immediately return a {@link GuestServer}.\n *\n * @deprecated Use {@link attach} or {@link register}, which return Promises\n * that resolve once the guest is connected.\n * @public\n */\nexport function createGuest(config: GuestConfig) {\n const guest = new GuestServer(config);\n return guest;\n}\n\n/**\n * Connect to a running {@link GuestServer} to share its context and render UI.\n *\n * @remarks Creates a guest object that shares most of the GuestServer API,\n * except it cannot register its own methods. Use `attach()` in an app or\n * document that is meant to render a UI in the host application; it will have\n * access to the sharedContext object shared by the host and GuestServer.\n *\n * @public\n */\nexport async function attach(config: GuestConfig) {\n const guest = new GuestUI(config);\n await guest._connect();\n return guest;\n}\n\n/**\n * Initiate a connection to the host app and its extension points.\n *\n * @remarks Creates the \"main\" {@link GuestServer}, which runs in the background\n * without UI. Registers methods passed in the `methods` parameter, then\n * resolves the returned Promise with the connected GuestServer object.\n *\n * @public\n */\nexport async function register<Outgoing extends GuestApis>(\n config: GuestConfigWithMethods<Outgoing>\n) {\n const guest = new GuestServer(config);\n await guest.register(config.methods);\n return guest;\n}\n\n// backwards compatibility\nexport {\n Guest,\n Guest as BaseGuest,\n GuestUI,\n GuestUI as UIGuest,\n GuestServer,\n GuestServer as PrimaryGuest,\n};\n"],"mappings":"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","names":["guest","Guest","Guest","Guest"]}
|
@@ -0,0 +1,53 @@
|
|
1
|
+
import type { GuestApis } from "@adobe/uix-core";
|
2
|
+
import type { SharedContext } from "./guest";
|
3
|
+
import { Guest } from "./guest";
|
4
|
+
/**
|
5
|
+
* A Guest to be used in the "main" or primary frame of an extension, the frame
|
6
|
+
* the Host loads first.
|
7
|
+
*
|
8
|
+
* @remarks This is the Guest object returned from {@link register}. It can
|
9
|
+
* expose internal methods to the Host via the {@link GuestServer.register}
|
10
|
+
* method.
|
11
|
+
*
|
12
|
+
*
|
13
|
+
* @public
|
14
|
+
*/
|
15
|
+
export declare class GuestServer<Outgoing extends GuestApis> extends Guest<Outgoing> {
|
16
|
+
private localMethods;
|
17
|
+
protected getLocalMethods(): {
|
18
|
+
apis: Outgoing;
|
19
|
+
emit: (type: "contextchange" | "beforeconnect" | "connected" | "error", detail: ({
|
20
|
+
context: Record<string, unknown>;
|
21
|
+
} & Record<string, unknown> & {
|
22
|
+
guest: Guest<import("@adobe/uix-core").VirtualApi>;
|
23
|
+
}) | (Record<string, unknown> & {
|
24
|
+
guest: Guest<import("@adobe/uix-core").VirtualApi>;
|
25
|
+
}) | ({
|
26
|
+
connection: import("penpal").Connection<import("penpal").CallSender>;
|
27
|
+
} & Record<string, unknown> & {
|
28
|
+
guest: Guest<import("@adobe/uix-core").VirtualApi>;
|
29
|
+
}) | ({
|
30
|
+
error: Error;
|
31
|
+
} & Record<string, unknown> & {
|
32
|
+
guest: Guest<import("@adobe/uix-core").VirtualApi>;
|
33
|
+
})) => void;
|
34
|
+
};
|
35
|
+
/**
|
36
|
+
* {@inheritDoc BaseGuest.sharedContext}
|
37
|
+
*/
|
38
|
+
sharedContext: SharedContext;
|
39
|
+
/**
|
40
|
+
* {@inheritdoc BaseGuest.host}
|
41
|
+
*/
|
42
|
+
host: Guest<Outgoing>["host"];
|
43
|
+
/**
|
44
|
+
* Pass an interface of methods which Host may call as callbacks.
|
45
|
+
*
|
46
|
+
* @remarks It is preferable to use {@link register} to obtain a guest object
|
47
|
+
* and register local methods in one step. The returned guest object will be
|
48
|
+
* pre-registered and connected.
|
49
|
+
* @public
|
50
|
+
*/
|
51
|
+
register(implementedMethods: Outgoing): Promise<void>;
|
52
|
+
}
|
53
|
+
//# sourceMappingURL=guest-server.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"guest-server.d.ts","sourceRoot":"","sources":["../src/guest-server.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAC7C,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAEhC;;;;;;;;;;GAUG;AACH,qBAAa,WAAW,CAAC,QAAQ,SAAS,SAAS,CAAE,SAAQ,KAAK,CAAC,QAAQ,CAAC;IAC1E,OAAO,CAAC,YAAY,CAAW;IAC/B,SAAS,CAAC,eAAe;;;;;;;;;;;;;;;;;;IAMzB;;OAEG;IACH,aAAa,EAAE,aAAa,CAAC;IAC7B;;OAEG;IACH,IAAI,EAAE,KAAK,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,CAAC;IAC9B;;;;;;;OAOG;IACG,QAAQ,CAAC,kBAAkB,EAAE,QAAQ;CAI5C"}
|
@@ -0,0 +1,102 @@
|
|
1
|
+
import type { RemoteHostApis, VirtualApi } from "@adobe/uix-core";
|
2
|
+
import { Guest, GuestConfig, GuestEventBeforeConnect, GuestEventConnected, GuestEventContextChange, GuestEventError } from "./guest";
|
3
|
+
/**
|
4
|
+
* A Guest to be used in an extension-controlled frame, usually to display UI.
|
5
|
+
*
|
6
|
+
* @typeParam Incoming - Optional interface of host methods. If using
|
7
|
+
* TypeScript, supply this type parameter and a promisified version of the
|
8
|
+
* interface will be available at {@link Guest.host}
|
9
|
+
*
|
10
|
+
* @remarks
|
11
|
+
* This is the object returned when calling {@link @adobe/uix-guest#attach}. It
|
12
|
+
* represents an additional frame or runtime created by the host application, on
|
13
|
+
* behalf of the extension's control frame which is running the {@link
|
14
|
+
* GuestServer}. It is a "secondary" guest object, which a host won't use before
|
15
|
+
* the control frame has connected. It exposes a subset of the functionality of
|
16
|
+
* the {@link GuestServer}.
|
17
|
+
*
|
18
|
+
* Unlike the {@link GuestServer}, it cannot register methods or update the
|
19
|
+
* {@link Guest.sharedContext}, but it remains in sync with the GuestServer and
|
20
|
+
* can access the {@link Guest.sharedContext} of the control frame, as well as
|
21
|
+
* any of the published methods on the host.
|
22
|
+
*
|
23
|
+
* Extensible host apps using the React bindings will likely render GuestUI
|
24
|
+
* frames using the {@link @adobe/uix-host-react#GuestUIFrame} component.
|
25
|
+
*
|
26
|
+
* @example
|
27
|
+
* When an extensible app renders this page, {@link @adobe/uix-guest#attach}
|
28
|
+
* creates a GuestUI. Once it attaches to the host, it
|
29
|
+
* ```javascript
|
30
|
+
* import React, { useEffect, useState } from "react";
|
31
|
+
* import { attach } from "@adobe/uix-guest";
|
32
|
+
* import { Tooltip } from "./tooltip";
|
33
|
+
*
|
34
|
+
* export default function PopupOverlay(props) {
|
35
|
+
* // how large am I?
|
36
|
+
* const [dimensions, setDimensions] = useState(
|
37
|
+
* document.body.getBoundingClientRect()
|
38
|
+
* );
|
39
|
+
* // if possible, use language preloaded in query parameters
|
40
|
+
* const [language, setLanguage] = useState(props.params.lang)
|
41
|
+
*
|
42
|
+
* // attach only once, in a useEffect
|
43
|
+
* useEffect(() => {
|
44
|
+
* attach({
|
45
|
+
* id: "my-extension-id",
|
46
|
+
* debug: true,
|
47
|
+
* })
|
48
|
+
* .then(guestUI => {
|
49
|
+
* // this event fires whenever the host, or the control frame, changes
|
50
|
+
* // any sharedContext value
|
51
|
+
* guestUI.addEventListener("contextchange", ({ detail: { context }}) => {
|
52
|
+
* setLanguage(context.lang)
|
53
|
+
* });
|
54
|
+
* // how large does the host want me to be?
|
55
|
+
* return guestUI.host.tooltips.getDimensions()
|
56
|
+
* .then(setDimensions)
|
57
|
+
* })
|
58
|
+
* .catch((e) => {
|
59
|
+
* console.error("ui attach failed", e);
|
60
|
+
* });
|
61
|
+
* }, []);
|
62
|
+
* // render UI! Due to the setup and useState, this component will re-render
|
63
|
+
* // once attach() is complete.
|
64
|
+
* return (
|
65
|
+
* <Tooltip {...props.params} lang={language} dimensions={dimensions} />
|
66
|
+
* );
|
67
|
+
* }
|
68
|
+
* ```
|
69
|
+
*
|
70
|
+
* @public
|
71
|
+
*/
|
72
|
+
export declare class GuestUI<IHost extends VirtualApi> extends Guest<IHost> {
|
73
|
+
/**
|
74
|
+
* {@inheritDoc Guest."constructor"}
|
75
|
+
*/
|
76
|
+
constructor(config: GuestConfig);
|
77
|
+
/**
|
78
|
+
* {@inheritDoc Guest.contextchange}
|
79
|
+
* @eventProperty
|
80
|
+
*/
|
81
|
+
contextchange: GuestEventContextChange;
|
82
|
+
/**
|
83
|
+
* {@inheritDoc Guest.beforeconnect}
|
84
|
+
* @eventProperty
|
85
|
+
*/
|
86
|
+
beforeconnect: GuestEventBeforeConnect;
|
87
|
+
/**
|
88
|
+
* {@inheritDoc Guest.connected}
|
89
|
+
* @eventProperty
|
90
|
+
*/
|
91
|
+
connected: GuestEventConnected;
|
92
|
+
/**
|
93
|
+
* {@inheritDoc Guest.error}
|
94
|
+
* @eventProperty
|
95
|
+
*/
|
96
|
+
error: GuestEventError;
|
97
|
+
/**
|
98
|
+
* {@inheritDoc Guest.host}
|
99
|
+
*/
|
100
|
+
host: RemoteHostApis<IHost>;
|
101
|
+
}
|
102
|
+
//# sourceMappingURL=guest-ui.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"guest-ui.d.ts","sourceRoot":"","sources":["../src/guest-ui.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAClE,OAAO,EACL,KAAK,EACL,WAAW,EACX,uBAAuB,EACvB,mBAAmB,EACnB,uBAAuB,EACvB,eAAe,EAChB,MAAM,SAAS,CAAC;AAEjB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoEG;AACH,qBAAa,OAAO,CAAC,KAAK,SAAS,UAAU,CAAE,SAAQ,KAAK,CAAC,KAAK,CAAC;IACjE;;OAEG;gBACS,MAAM,EAAE,WAAW;IAG/B;;;OAGG;IACI,aAAa,EAAE,uBAAuB,CAAC;IAC9C;;;OAGG;IACI,aAAa,EAAE,uBAAuB,CAAC;IAC9C;;;OAGG;IACI,SAAS,EAAE,mBAAmB,CAAC;IACtC;;;OAGG;IACI,KAAK,EAAE,eAAe,CAAC;IAC9B;;OAEG;IACH,IAAI,EAAE,cAAc,CAAC,KAAK,CAAC,CAAC;CAC7B"}
|