| 1 | import type { DesktopBridge } from "@t3tools/contracts"; |
| 2 | |
| 3 | export const DESKTOP_PASTE_AS_TEXT_EVENT = "t3:paste-as-text"; |
| 4 | |
| 5 | /** Arm composer paste handling before Electron delivers the native clipboard event. */ |
| 6 | export function installDesktopPasteAsText( |
| 7 | bridge: Pick<DesktopBridge, "onMenuAction" | "pasteAsText"> | undefined, |
| 8 | target: EventTarget, |
| 9 | ): (() => void) | undefined { |
| 10 | return bridge?.onMenuAction((action) => { |
| 11 | if (action !== "paste-as-text") return; |
| 12 | target.dispatchEvent(new Event(DESKTOP_PASTE_AS_TEXT_EVENT)); |
| 13 | void bridge.pasteAsText?.(); |
| 14 | }); |
| 15 | } |