Open History to see the last commit
1export type PreviewAction =
2 | "toggle-panel"
3 | "refresh"
4 | "focus-url"
5 | "zoom-in"
6 | "zoom-out"
7 | "reset-zoom";
8
9const EVENT_NAME = "t3code:preview-action";
10
11export function dispatchPreviewAction(action: PreviewAction): void {
12 if (typeof window === "undefined") return;
13 window.dispatchEvent(new CustomEvent<PreviewAction>(EVENT_NAME, { detail: action }));
14}
15
16export function subscribePreviewAction(listener: (action: PreviewAction) => void): () => void {
17 if (typeof window === "undefined") return () => {};
18 const handler = (event: Event) => {
19 const detail = (event as CustomEvent<PreviewAction>).detail;
20 if (typeof detail === "string") listener(detail);
21 };
22 window.addEventListener(EVENT_NAME, handler);
23 return () => window.removeEventListener(EVENT_NAME, handler);
24}