feat: add expand state signal and height calculation helpers

This commit is contained in:
bizzkoot
2026-01-11 20:04:25 +08:00
parent 72f420b6f6
commit f06359a1fc

View File

@@ -46,10 +46,28 @@ export default function PromptInput(props: PromptInputProps) {
const [pasteCount, setPasteCount] = createSignal(0) const [pasteCount, setPasteCount] = createSignal(0)
const [imageCount, setImageCount] = createSignal(0) const [imageCount, setImageCount] = createSignal(0)
const [mode, setMode] = createSignal<"normal" | "shell">("normal") const [mode, setMode] = createSignal<"normal" | "shell">("normal")
const [expandState, setExpandState] = createSignal<"normal" | "fifty" | "eighty">("normal")
const SELECTION_INSERT_MAX_LENGTH = 2000 const SELECTION_INSERT_MAX_LENGTH = 2000
let textareaRef: HTMLTextAreaElement | undefined let textareaRef: HTMLTextAreaElement | undefined
let containerRef: HTMLDivElement | undefined let containerRef: HTMLDivElement | undefined
const calculateContainerHeight = () => {
if (!containerRef) return 0
const rect = containerRef.getBoundingClientRect()
const root = containerRef.closest(".session-view")
if (!root) return 0
const rootRect = root.getBoundingClientRect()
return rootRect.height - rect.top
}
const getExpandedHeight = (): string => {
const state = expandState()
if (state === "normal") return "auto"
const containerHeight = calculateContainerHeight()
if (state === "fifty") return `${containerHeight * 0.5}px`
return `${containerHeight * 0.8}px`
}