The best way to control Claude Code, Codex and more from any computer or phone
| 1 | export type PreviewAction = |
| 2 | | "toggle-panel" |
| 3 | | "refresh" |
| 4 | | "back" |
| 5 | | "forward" |
| 6 | | "focus-url" |
| 7 | | "zoom-in" |
| 8 | | "zoom-out" |
| 9 | | "reset-zoom" |
| 10 | | "find"; |
| 11 | |
| 12 | const EVENT_NAME = "t3code:preview-action"; |
| 13 | |
| 14 | export function dispatchPreviewAction(action: PreviewAction): void { |
| 15 | if (typeof window === "undefined") return; |
| 16 | window.dispatchEvent(new CustomEvent<PreviewAction>(EVENT_NAME, { detail: action })); |
| 17 | } |
| 18 | |
| 19 | export function subscribePreviewAction(listener: (action: PreviewAction) => void): () => void { |
| 20 | if (typeof window === "undefined") return () => {}; |
| 21 | const handler = (event: Event) => { |
| 22 | const detail = (event as CustomEvent<PreviewAction>).detail; |
| 23 | if (typeof detail === "string") listener(detail); |
| 24 | }; |
| 25 | window.addEventListener(EVENT_NAME, handler); |
| 26 | return () => window.removeEventListener(EVENT_NAME, handler); |
| 27 | } |