import type { FormInput, PromptTextRequest } from "@yaakapp-internal/plugins"; import type { ReactNode } from "react"; import type { DialogProps } from "../components/core/Dialog"; import { showPromptForm } from "./prompt-form"; type PromptProps = Omit & { description?: ReactNode; onCancel: () => void; onResult: (value: string | null) => void; }; type PromptArgs = Pick & Omit & { id: string }; export async function showPrompt({ id, title, description, cancelText, confirmText, required, ...props }: PromptArgs) { const inputs: FormInput[] = [ { ...props, optional: !required, type: "text", name: "value", }, ]; const result = await showPromptForm({ id, title, description, inputs, cancelText, confirmText, }); if (result == null) return null; // Cancelled if (typeof result.value === "string") return result.value; return props.defaultValue ?? ""; }