import type { CompletionContext, CompletionResult, } from "@codemirror/autocomplete"; import { useEffect, useRef, useState } from "preact/hooks"; import { MiniEditor } from "./mini_editor.tsx"; import type { ComponentChildren, Ref } from "preact"; export function Prompt({ message, defaultValue, vimMode, darkMode, completer, callback, }: { message: string; defaultValue?: string; vimMode: boolean; darkMode: boolean; completer: (context: CompletionContext) => Promise; callback: (value?: string) => void; }) { const [text, setText] = useState(defaultValue || ""); const returnEl = ( { callback(); }} >
{ callback(text); return true; }} onEscape={() => { callback(); }} onChange={(text) => { setText(text); }} />
); return returnEl; } export function Confirm({ message, callback, }: { message: string; callback: (value: boolean) => void; }) { const okButtonRef = useRef(null); setTimeout(() => { okButtonRef.current?.focus(); }); const returnEl = ( { callback(false); }} >
); return returnEl; } export function Button({ children, primary, onActivate, buttonRef, }: { children: ComponentChildren; primary?: boolean; onActivate: () => void; buttonRef?: Ref; }) { return ( ); } export function AlwaysShownModal({ children, onCancel, }: { children: ComponentChildren; onCancel?: () => void; }) { const dialogRef = useRef(null); useEffect(() => { dialogRef.current?.showModal(); }, []); return ( { e.preventDefault(); onCancel?.(); }} onKeyDown={(e) => { e.stopPropagation(); }} ref={dialogRef} > {children} ); }