import type { ComponentProps, RefObject } from 'react' import { IconArrowUp } from '@tabler/icons-react' import { Button } from '@/client/components/ui/button' import { Tooltip, TooltipContent, TooltipTrigger } from '@/client/components/ui/tooltip' import { cn } from '@/client/lib/cn' import { Spinner } from '../ui/spinner' type ComposerProps = Omit, 'ref'> & { composerRef: RefObject } type ComposerFocusTarget = Pick export function focusComposer(composer: ComposerFocusTarget | null) { if (!composer) return composer.focus() const end = composer.value.length composer.setSelectionRange(end, end) } export function Composer({ composerRef, className, onMouseDown, children, ...props }: ComposerProps) { return (
{ onMouseDown?.(event) if (event.defaultPrevented) return if ( event.target instanceof Element && event.target.closest('button, input, textarea, select, a, [contenteditable="true"]') ) return focusComposer(composerRef.current) }} className={cn( 'group/composer flex w-full cursor-text flex-col gap-1 rounded-xl bg-card p-2 text-card-foreground shadow-xs transition-[color,box-shadow] outline-none focus-within:shadow-sm', className )} > {children}
) } type ComposerTextareaProps = Omit, 'ref'> & { textareaRef: RefObject } export function ComposerTextarea({ textareaRef, className, ...props }: ComposerTextareaProps) { return (