From: characharm Date: Tue, 8 Apr 2025 09:14:59 +0000 (+0500) Subject: server : webui : Improve Chat Input with Auto-Sizing Textarea (#12785) X-Git-Tag: gguf-v0.16.1~77 X-Git-Url: https://git.djapps.eu/?a=commitdiff_plain;h=8ca6e1c3a4deb6bb27ee294bfd5706098d94ae88;p=pkg%2Fggml%2Fsources%2Fllama.cpp server : webui : Improve Chat Input with Auto-Sizing Textarea (#12785) * Update ChatScreen.tsx * useAutosizeTextarea.ts useAutosizeTextarea to encapsulate the logic. * Implement responsive auto-sizing chat textarea Replaces the manual textarea resizing with an automatic height adjustment based on content. - `useChatTextarea` hook to manage textarea state and auto-sizing logic via refs, preserving the optimization - Textarea now grows vertically up to a maximum height (`lg:max-h-48`) on large screens (lg breakpoint and up). - Disables auto-sizing and enables manual vertical resizing (`resize-vertical`) on smaller screens for better mobile usability. - Aligns the "Send" button to the bottom of the textarea (`items-end`) for consistent positioning during resize. * -update compressed index.html.gz after npm run build -refactor: replace OptimizedTextareaValue with AutosizeTextareaApi in VSCode context hook * chore: normalize line endings to LF refactor: AutosizeTextareaApi -> chatTextareaApi * refactor: Rename interface to PascalCase --------- Co-authored-by: Xuan Son Nguyen --- diff --git a/examples/server/public/index.html.gz b/examples/server/public/index.html.gz index 941815c2..674e2275 100644 Binary files a/examples/server/public/index.html.gz and b/examples/server/public/index.html.gz differ diff --git a/examples/server/webui/src/components/ChatScreen.tsx b/examples/server/webui/src/components/ChatScreen.tsx index d12b06e1..29ab5ea6 100644 --- a/examples/server/webui/src/components/ChatScreen.tsx +++ b/examples/server/webui/src/components/ChatScreen.tsx @@ -1,4 +1,4 @@ -import { useEffect, useMemo, useRef, useState } from 'react'; +import { useEffect, useMemo, useState } from 'react'; import { CallbackGeneratedChunk, useAppContext } from '../utils/app.context'; import ChatMessage from './ChatMessage'; import { CanvasType, Message, PendingMessage } from '../utils/types'; @@ -6,6 +6,7 @@ import { classNames, cleanCurrentUrl, throttle } from '../utils/misc'; import CanvasPyInterpreter from './CanvasPyInterpreter'; import StorageUtils from '../utils/storage'; import { useVSCodeContext } from '../utils/llama-vscode'; +import { useChatTextarea, ChatTextareaApi } from './useChatTextarea.ts'; /** * A message display is a message node with additional information for rendering. @@ -99,7 +100,8 @@ export default function ChatScreen() { canvasData, replaceMessageAndGenerate, } = useAppContext(); - const textarea = useOptimizedTextarea(prefilledMsg.content()); + + const textarea: ChatTextareaApi = useChatTextarea(prefilledMsg.content()); const { extraContext, clearExtraContext } = useVSCodeContext(textarea); // TODO: improve this when we have "upload file" feature @@ -248,14 +250,16 @@ export default function ChatScreen() { {/* chat input */} -
+
+ {isGenerating(currConvId ?? '') ? (