import { codeToHtml, isSupportedLanguage } from "@pierre/highlights" import { OpenCodeTheme } from "@opencode/ui/context/highlight-theme" import { Icon } from "@opencode/ui/icon" import { Tooltip } from "@opencode/ui/tooltip" import { createMemo, createSignal, onCleanup, Show, type JSX } from "solid-js" import { useLanguage } from "@/runtime/i18n/language" import { usePlatform } from "@/runtime/platform/platform" import "./automations.css" const decoder = new TextDecoder() export function HighlightedCode(props: { code: string; lang: string; class?: string }) { const html = createMemo(() => decoder.decode( codeToHtml(props.code, { lang: isSupportedLanguage(props.lang) ? props.lang : "text", theme: OpenCodeTheme, }), ), ) return (
) } /** * 1-line text is 20px tall + 10px vertical padding = 40px. * A 24px copy button at top-2 end-2 sits 8px from top, bottom, and right (equally spaced on 1 line, top-anchored on multi-line). */ export function CodeSurface(props: { copyText: string; children: JSX.Element }) { return (
{props.children}
) } function createCopy(text: () => string) { const platform = usePlatform() const [copied, setCopied] = createSignal(false) let timer: ReturnType | undefined onCleanup(() => clearTimeout(timer)) const copy = async () => { const value = text() const write = platform.writeClipboardText ? platform.writeClipboardText(value) : navigator.clipboard?.writeText(value) if (!write) return const ok = await write.then( () => true, () => false, ) if (!ok) return setCopied(true) clearTimeout(timer) timer = setTimeout(() => setCopied(false), 1600) } return { copied, copy } } export function CopyButton(props: { text: string; class?: string }) { const language = useLanguage() const { copied, copy } = createCopy(() => props.text) return ( ) } export function CopyPathButton(props: { path: string }) { const language = useLanguage() const { copied, copy } = createCopy(() => props.path) return ( ) }