import { Box, Text, Textarea } from "../ui"; import { useEffect, useRef, useState } from "react"; import { type InputRenderable, type TextareaRenderable } from "../ui"; import { type AlertContext, type PromptContext, useDialogKeyboard } from "../ui/dialog"; import type { WizardStep } from "../types/plugin"; import { colors } from "../theme/colors"; import { Button, DialogFrame, ListView, TextField } from "./ui"; import { listCursorMove } from "./ui/list-view"; import { t } from "../i18n"; export function PaneTemplateInfoStep({ dismiss, dialogId, step, }: AlertContext & { step: WizardStep }) { useDialogKeyboard((event) => { event.stopPropagation(); if (event.name === "return" || event.name === "enter" || event.name === "escape") { dismiss(); } }, dialogId); return ( {step.body?.map((line, index) => ( {line ? t(line) : " "} ))} ); } export function PaneTemplateInputStep({ resolve, step, }: PromptContext & { step: WizardStep }) { const inputRef = useRef(null); const [value, setValue] = useState(step.defaultValue ?? ""); useEffect(() => { inputRef.current?.focus?.(); }, []); return ( {step.body?.map((line, index) => ( {line ? t(line) : " "} ))} { const submitted = submittedValue.trim() || step.defaultValue || ""; if (submitted || step.required === false) resolve(submitted); }} /> ); } export function PaneTemplateTextareaStep({ resolve, step, dialogId, }: PromptContext & { step: WizardStep }) { const textareaRef = useRef(null); useEffect(() => { textareaRef.current?.focus?.(); }, []); useDialogKeyboard((event) => { event.stopPropagation(); if (event.name === "escape") { resolve(""); return; } if (event.ctrl && event.name === "s") { const submitted = textareaRef.current?.editBuffer.getText().trim() || step.defaultValue || ""; if (submitted) resolve(submitted); } }, { scope: dialogId, allowEditable: true }); const commit = () => { const submitted = textareaRef.current?.editBuffer.getText().trim() || step.defaultValue || ""; if (submitted) resolve(submitted); }; return ( {step.body?.map((line, index) => ( {line ? t(line) : " "} ))}