import type { Extension, GuestEmitter, NamedEvent, GuestApis } from "@adobe/uix-core"; import type { CapabilitySpec } from "./port.js"; import { Emitter } from "@adobe/uix-core"; import { Port, PortOptions } from "./port.js"; /** * Dictionary of {@link Port} objects by extension ID. * @public */ export type PortMap = Map; /** @public */ export type HostEvent> = NamedEvent & { host: Host; }>; /** @public */ type HostGuestEvent = HostEvent<`guest${Type}`, { guest: Port; }>; /** * All guests requested by host have been loaded and connected. * @public */ export type HostEventLoadAllGuests = HostEvent<"loadallguests", { failed: Port[]; loaded: Port[]; }>; /** * Shared context has been set or updated; all guests receive this event too. * @public */ export type HostEventContextChange = HostEvent<"contextchange", { context: SharedContextValues; }>; /** * An error has occurred during loading or unloading of guests. * @public */ export type HostEventError = HostEvent<"error", { error: Error; }>; /** @public */ export type HostEvents = HostGuestEvent<"beforeload"> | HostGuestEvent<"load"> | HostGuestEvent<"beforeunload"> | HostGuestEvent<"unload"> | HostEvent<"beforeunload"> | HostEvent<"unload"> | HostEventLoadAllGuests | HostEventContextChange | HostEventError; /** @public */ export type InstalledExtensions = Record; /** @public */ export type ExtensionsArray = Array<[string, Extension | string]>; /** @public */ export type ExtensionsProvider = () => Promise; /** * Values for shared context. Must be a plain object, serializable to JSON. * @public */ export type SharedContextValues = Record; /** @public */ export interface HostConfig { /** * Human-readable "slug" name of the extensible area--often an entire app. * This string serves as a namespace for extension points within the area. */ hostName: string; /** * A DOM element _outside_ of the React root. This is necessary to preserve * the lifetime of the iframes which are running extension objects; if they * live inside the React root, then React could unexpectedly re-render the * iframe tags themselves at any time, causing a reload of the frame. */ runtimeContainer?: HTMLElement; /** * Copiously log lifecycle events. */ debug?: boolean; /** * Default options to use for every guest Port. * * If `config.debug` is true, then the guest options will have `debug: true` * unless `debug: false` is explicitly passed in `guestOptions`. */ guestOptions?: PortOptions; /** * A read-only dictionary of values that the host will supply to all the * guests. */ sharedContext?: SharedContextValues; /** * Disables built-in metrics of UIX SDK */ disableMetrics?: boolean; } /** * Callback to use to filter the list returned from {@link Host.(getLoadedGuests:2)} * @public */ type GuestFilter = (item: GuestEmitter) => boolean; /** * Manager object for connecting to {@link @adobe/uix-guest#GuestServer | * GuestServers} and {@link @adobe/uix-guest#GuestUI | GuestUIs}, providing and * receiving their APIs, and providing them to the app for interacting with UI. * * @remarks * The Host object is the main connection manager for all UIX Guests. * Making an app extensible requires creating a Host object. * * The extensible app using the Hostis responsible for providing a list of * extension references to the Host object. Use {@link * createExtensionRegistryProvider} for that purpose. Once you have retrieved a * list of extensions available to the host app, pass it to {@link Host.load}. * * When a Host creates a Guest, it must create an `