Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion viewer/src/client/components/chat/ChatInput.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import { blobToAttachment, imageFilesFromDataTransfer, MAX_ATTACHMENTS } from ".

export { buildSendValue };

const MAX_TEXTAREA_HEIGHT = 192; // tailwind max-h-48

function ChatInput({ className }, ref) {
const [value, setValue] = useState("");
const turnInProgress = useChatStore((state) => state.turnInProgress);
Expand Down Expand Up @@ -165,6 +167,15 @@ function ChatInput({ className }, ref) {
window.requestAnimationFrame?.(() => textareaRef.current?.focus());
}, []);

const adjustTextareaHeight = useCallback(() => {
const textarea = textareaRef.current;
if (!textarea) return;
textarea.style.height = "0px";
const nextHeight = Math.min(textarea.scrollHeight, MAX_TEXTAREA_HEIGHT);
textarea.style.height = `${nextHeight}px`;
textarea.style.overflowY = textarea.scrollHeight > MAX_TEXTAREA_HEIGHT ? "auto" : "hidden";
}, []);

useImperativeHandle(ref, () => ({
focus(options) {
textareaRef.current?.focus(options);
Expand All @@ -186,6 +197,10 @@ function ChatInput({ className }, ref) {

const hasStrip = pendingTokens.length > 0 || pendingAttachments.length > 0;

useEffect(() => {
adjustTextareaHeight();
}, [value, hasStrip, adjustTextareaHeight]);

return (
<div
data-slot="chat-input"
Expand Down Expand Up @@ -264,7 +279,7 @@ function ChatInput({ className }, ref) {
onPaste={handlePaste}
placeholder="Do anything"
rows={2}
className="min-h-10 flex-1 resize-none border-0 bg-transparent! px-0 py-0 text-sm shadow-none placeholder:text-muted-foreground/70 focus-visible:ring-0 dark:bg-transparent!"
className="scrollbar-thin min-h-10 resize-none border-0 bg-transparent! px-0 py-0 text-sm shadow-none placeholder:text-muted-foreground/70 focus-visible:ring-0 dark:bg-transparent!"
data-slot="chat-input-textarea"
/>

Expand Down
33 changes: 33 additions & 0 deletions viewer/src/client/components/chat/Markdown.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,39 @@ const COMPONENTS = {
{children}
</a>
),
table: ({ children }) => (
<div
data-slot="chat-markdown-table"
className="scrollbar-thin my-2 overflow-x-auto rounded-md border border-border/50"
>
<table className="w-full min-w-max border-collapse text-left text-[13px]">{children}</table>
</div>
),
thead: ({ children }) => <thead className="border-b border-border/60 bg-muted/40">{children}</thead>,
tbody: ({ children }) => <tbody className="divide-y divide-border/40">{children}</tbody>,
tr: ({ children }) => <tr>{children}</tr>,
th: ({ children, align }) => (
<th
className={cn(
"px-2.5 py-1.5 font-semibold text-foreground",
align === "center" && "text-center",
align === "right" && "text-right",
)}
>
{children}
</th>
),
td: ({ children, align }) => (
<td
className={cn(
"px-2.5 py-1.5 align-top",
align === "center" && "text-center",
align === "right" && "text-right",
)}
>
{children}
</td>
),
pre: ({ children }) => <>{children}</>,
code: ({ className, children }) => {
const lang = /language-([\w-]+)/.exec(className || "")?.[1];
Expand Down
Loading