// Run a saved script from public/scripts/ or paste DSL ad-hoc. // Triggered by the Play icon in the appbar or Cmd/Ctrl+Shift+P. import { useEffect, useState } from "react" import { Play } from "lucide-react" import { Button } from "~/components/ui/button" import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, } from "~/components/ui/dialog" import { runScript, runScriptText } from "@crema/action-bus" const KNOWN_SCRIPTS = [ { name: "demo-tour", description: "Tour the rail" }, { name: "demo-search", description: "Focus and fill search" }, ] export function useScriptsHotkey(open: () => void) { useEffect(() => { const onKey = (e: KeyboardEvent) => { const mod = e.metaKey || e.ctrlKey if (mod && e.shiftKey && (e.key === "p" || e.key === "P")) { e.preventDefault() open() } } window.addEventListener("keydown", onKey) return () => window.removeEventListener("keydown", onKey) }, [open]) } export function ScriptsDialog({ open, onOpenChange, }: { open: boolean onOpenChange: (v: boolean) => void }) { const [text, setText] = useState("") const [status, setStatus] = useState(null) const [busy, setBusy] = useState(false) const runByName = async (name: string) => { setBusy(true) setStatus(`Running ${name}…`) try { onOpenChange(false) await runScript(name) setStatus(`Ran ${name}.`) } catch (e) { setStatus(`Error: ${e instanceof Error ? e.message : String(e)}`) } finally { setBusy(false) } } const runText = async () => { if (!text.trim()) return setBusy(true) setStatus("Running…") try { onOpenChange(false) await runScriptText(text) setStatus("Done.") } catch (e) { setStatus(`Error: ${e instanceof Error ? e.message : String(e)}`) } finally { setBusy(false) } } return ( Run a script Pick a saved script or paste DSL. Cmd/Ctrl + Shift + P toggles this.
Saved
{KNOWN_SCRIPTS.map((s) => ( ))}
Paste DSL