Pluggable host behavior. All are optional — the client has sensible defaults.

interface EditorBridgeHandlers {
    fs?: FsResponder;
    getInitialDoc?: () => undefined | null | DocOpenPayload;
    getThemeState?: () => ThemePushState;
    onCompiled?: (status: number, log: string, pdf: null | string) => void;
    onDirty?: (dirty: boolean) => void;
    onPickFolder?: () => Promise<null | string>;
    onReady?: (protocol?: number) => void;
}

Properties

FS-adapter RPC handler. Defaults to NoopFsResponder.

getInitialDoc?: () => undefined | null | DocOpenPayload

The document/project to mount immediately after the handshake. Return null/undefined to skip the auto doc:open (the host can call sendDocOpen() later instead).

getThemeState?: () => ThemePushState

Resolve the current theme to push on the 'texbrain:ready' handshake (and any later manual pushTheme() call). Required to theme the editor before first paint.

onCompiled?: (status: number, log: string, pdf: null | string) => void

Compile finished (or failed) on the guest. pdf is base64-encoded.

onDirty?: (dirty: boolean) => void

Editor buffer dirty-state changed.

onPickFolder?: () => Promise<null | string>

The guest asked for the host's NATIVE directory picker (its embedded "Open Folder" — the iframe can't pick itself). Show the dialog, re-root the fs responder at the chosen folder, and resolve with the folder's basename (null = user cancelled). Unset ⇒ the client replies ok:false so the guest surfaces an error instead of hanging.

onReady?: (protocol?: number) => void

Guest completed its boot handshake. protocol is the bridge protocol the live Editor build reports in texbrain:ready — a belt-and-suspenders runtime signal only (the REAL compat gate is the release-manifest check at install/update time, ADR 0017); compare against SUPPORTED_BRIDGE_PROTOCOLS (src/api/editorPlugin.ts, exported from the plugin's guest-js) to show a non-fatal warning on mismatch.