ext-apps/src/message-transport.examples.ts
Liad Yosef 4fc71656a3
docs: standardize UI terminology to use "view" consistently (#325)
* docs: standardize UI terminology to use "view" consistently

Replaces "widget" and "Guest UI" terminology with "view" across
the codebase as decided in the community survey.

This change updates:
- Specification document
- SDK source code and JSDoc comments
- Example servers and documentation
- Plugin documentation and skills

Closes #71

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-23 04:36:52 +02:00

58 lines
1.8 KiB
TypeScript

/**
* Type-checked examples for {@link PostMessageTransport `PostMessageTransport`}.
*
* These examples are included in the API documentation via `@includeCode` tags.
* Each function's region markers define the code snippet that appears in the docs.
*
* @module
*/
import { PostMessageTransport } from "./message-transport.js";
import type { App } from "./app.js";
import type { AppBridge } from "./app-bridge.js";
/**
* Example: View connecting to parent window.
*/
async function PostMessageTransport_view(app: App) {
//#region PostMessageTransport_view
const transport = new PostMessageTransport(window.parent, window.parent);
await app.connect(transport);
//#endregion PostMessageTransport_view
}
/**
* Example: Host connecting to an iframe.
*/
async function PostMessageTransport_host(bridge: AppBridge) {
//#region PostMessageTransport_host
const iframe = document.getElementById("app-iframe") as HTMLIFrameElement;
const transport = new PostMessageTransport(
iframe.contentWindow!,
iframe.contentWindow!,
);
await bridge.connect(transport);
//#endregion PostMessageTransport_host
}
/**
* Example: Creating transport for view (constructor only).
*/
function PostMessageTransport_constructor_view() {
//#region PostMessageTransport_constructor_view
const transport = new PostMessageTransport(window.parent, window.parent);
//#endregion PostMessageTransport_constructor_view
}
/**
* Example: Creating transport for host (constructor only).
*/
function PostMessageTransport_constructor_host() {
//#region PostMessageTransport_constructor_host
const iframe = document.getElementById("app-iframe") as HTMLIFrameElement;
const transport = new PostMessageTransport(
iframe.contentWindow!,
iframe.contentWindow!,
);
//#endregion PostMessageTransport_constructor_host
}