@hyperfrontend/features/hostHost
Host-side SDK for embedding hyperfrontend features — shell factory, display modes, iframe utilities, and lifecycle.
import { createShell, DisplayMode } from '@hyperfrontend/features/host'
const shell = createShell({
url: 'https://features.example.com/clock',
container: '#clock-slot',
displayMode: DisplayMode.Embedded,
})
shell.on('open', () => console.log('feature connected'))
shell.on('tick', (time) => console.log('feature said', time))
shell.open()
shell.send('set-timezone', { tz: 'UTC' })
API
| Export | Purpose |
|---|---|
createShell | Build a shell handle for a feature; returns open/close/send/on/isOpen. |
DisplayMode | The four built-in modes: Embedded, Dialog, Popup, Standalone. |
ShellHandle | Type of the handle returned by createShell. |
ShellOptions | Options accepted by createShell and per-open overrides. |
ExperiencePlugin | Opt-in extension point for layering transitions/animations onto display modes. |
The shell wraps a @hyperfrontend/nexus broker: send emits a contract action to the feature, and on subscribes to feature messages and the open/close/error lifecycle events. close disconnects the channel; destroy also releases the DOM.
API Reference
ƒ Functions
Creates a host-side shell for embedding a feature.
Provisions a nexus broker and returns a handle whose
Provisions a nexus broker and returns a handle whose
open mounts the feature in the requested display mode.Parameters
| Name | Type | Description |
|---|---|---|
§options | ShellOptions | Create-time shell options, overridable per open call. |
Returns
ShellHandleA handle exposing
open, close, destroy, send, on, and isOpen.Example
Embedding a clock feature
const clock = createShell({ container: '#clock', url: 'https://clock.example.com' })
clock.open({ displayMode: DisplayMode.Dialog, dialogWidth: 530 })
clock.on('timeUpdated', (data) => console.log(data))◈ Interfaces
Opt-in extension that decorates a feature's mount lifecycle (e.g. transitions, animations).
Implement this interface to layer experiences onto the built-in display modes, then pass the plugin to the host shell. The SDK ships no built-in plugins.
Implement this interface to layer experiences onto the built-in display modes, then pass the plugin to the host shell. The SDK ships no built-in plugins.
Properties
Context handed to an ExperiencePlugin around a feature's mount lifecycle.
Public handle returned by createShell.
Properties
Options accepted by the host-side FeatureContract consumer when creating or opening a shell.
Properties
§
contract?:FeatureContract— Contract describing the feature's actions; replaces the generic default when provided.
§
embedSizing?:EmbedSizing— How an embedded feature is sized; defaults to
fill (the iframe fills its container).§
onUnresponsive?:UnresponsivePolicy— How the host reacts when the feature stops responding; defaults to
emit.Context passed to an UnresponsivePolicy callback when a feature stops beating.
◆ Types
How the feature is laid out when the host surfaces it.
type EmbedSizing = "fill" | "content"What the host does when a feature misses too many heartbeats.
emit (the default) emits an error; unmount also tears the feature down; a callback takes over handling entirely with the UnresponsiveInfo.type UnresponsivePolicy = "emit" | "unmount" | (info: UnresponsiveInfo) => void● Variables
Supported ways a host can surface an embedded feature.
All four modes are built into the SDK.
All four modes are built into the SDK.