Add slash command prompt support

This commit is contained in:
Shantur Rathore
2026-01-08 17:41:29 +00:00
parent e9241a1b93
commit cb2966fb08
5 changed files with 264 additions and 53 deletions

View File

@@ -3,7 +3,7 @@ import { createSignal } from "solid-js"
export type AlertVariant = "info" | "warning" | "error"
export type AlertDialogState = {
type?: "alert" | "confirm"
type?: "alert" | "confirm" | "prompt"
title?: string
message: string
detail?: string
@@ -12,7 +12,17 @@ export type AlertDialogState = {
cancelLabel?: string
onConfirm?: () => void
onCancel?: () => void
// prompt-only
inputLabel?: string
inputPlaceholder?: string
inputDefaultValue?: string
// confirm-only
resolve?: (value: boolean) => void
// prompt-only
resolvePrompt?: (value: string | null) => void
}
const [alertDialogState, setAlertDialogState] = createSignal<AlertDialogState | null>(null)
@@ -39,6 +49,23 @@ export function showConfirmDialog(message: string, options?: Omit<AlertDialogSta
})
}
export function showPromptDialog(
message: string,
options?: Omit<AlertDialogState, "message" | "type" | "resolve" | "resolvePrompt">,
): Promise<string | null> {
const activeElement = typeof document !== "undefined" ? (document.activeElement as HTMLElement | null) : null
activeElement?.blur()
return new Promise<string | null>((resolvePrompt) => {
setAlertDialogState({
type: "prompt",
message,
...options,
resolvePrompt,
})
})
}
export function dismissAlertDialog() {
setAlertDialogState(null)
}