Learn how to exchange data between Universal Editor and your extension
As we develop extensions for the Universal Editor, it's essential to facilitate data exchange between the editor and the extension. There are two main categories of data involved:
- User-specific information, like IMS organization.
- Editor-specific information, such as the current editor location.
Below you can find the details on how to access these data categories.
Shared Context
The shared context is a dataset that Universal Editor shares with UI Extensions. It's used to understand the context of the user who is running Universal Editor. You can access the shared context through the sharedContext property of the connection object.
import { attach } from "@adobe/uix-guest";
useEffect(() => {
(async () => {
const guestConnection = await attach({ id: extensionId });
setGuestConnection(guestConnection);
})();
}, []);
...
const context = guestConnection.sharedContext;
const hostAppLocale = context.get("locale");
Available data in the shared context:
stringstringstringstringEditor State
The editor state is a dataset that Universal Editor shares with UI Extensions. It's used to understand the current state of the editor. You can access the editor state through the editorState property of the host object.
Below is an example of how you can access editor state properties, e.g., connections.
import { attach } from "@adobe/uix-guest";
...
useEffect(() => {
(async () => {
const guestConnection = await attach({ id: extensionId });
setGuestConnection(guestConnection);
})();
}, []);
...
const editorState = await guestConnection.host.editorState.get();
const {connections} = editorState;
...
Available data in the editor state:
obj{ "aemconnection": "aem:%auth_instance_url%" }obj<string, boolean>{ "fcb38012-c4c7-51a8-896c-79e76kjk": true }[objects]Array[{id: '33661..", type: 'reference', resource: "urn:..., ..}, {}]string"%locationString%"obj<string, string>{"aemconnection":"<custom header token>"}