Extract shared rendering (chat-render.ts) and streaming hook (use-chat-stream.ts) from ChatWidget so both the floating panel and the new page share identical markdown/KaTeX/SSE logic. New page features: - Responsive sidebar (inline desktop, Sheet drawer mobile) - Conversation search/filter - Notebook picker via cmdk command palette - Auto-growing multi-line textarea input - Pop-out button on widget header to open /chat ChatLayout.astro omits the floating widget to avoid duplicate UI. Chat store gains selectedNotebookId for page-level notebook context. shadcn-ui primitives (ScrollArea, Sheet, Command, Popover, etc.) wired to existing SpiceBook dark theme tokens.
112 lines
3.8 KiB
TypeScript
112 lines
3.8 KiB
TypeScript
import * as React from 'react';
|
|
import { Command as CommandPrimitive } from 'cmdk';
|
|
import { Search } from 'lucide-react';
|
|
import { cn } from '../../lib/cn';
|
|
|
|
const Command = React.forwardRef<
|
|
React.ComponentRef<typeof CommandPrimitive>,
|
|
React.ComponentPropsWithoutRef<typeof CommandPrimitive>
|
|
>(({ className, ...props }, ref) => (
|
|
<CommandPrimitive
|
|
ref={ref}
|
|
className={cn(
|
|
'flex h-full w-full flex-col overflow-hidden rounded-lg bg-[var(--color-sb-surface)] text-[var(--color-sb-text)]',
|
|
className,
|
|
)}
|
|
{...props}
|
|
/>
|
|
));
|
|
Command.displayName = CommandPrimitive.displayName;
|
|
|
|
const CommandInput = React.forwardRef<
|
|
React.ComponentRef<typeof CommandPrimitive.Input>,
|
|
React.ComponentPropsWithoutRef<typeof CommandPrimitive.Input>
|
|
>(({ className, ...props }, ref) => (
|
|
<div className="flex items-center border-b border-[var(--color-sb-border)] px-3" cmdk-input-wrapper="">
|
|
<Search size={14} className="mr-2 shrink-0 text-[var(--color-sb-muted)]" />
|
|
<CommandPrimitive.Input
|
|
ref={ref}
|
|
className={cn(
|
|
'flex h-9 w-full rounded-md bg-transparent py-2 text-sm outline-none placeholder:text-[var(--color-sb-muted)] disabled:cursor-not-allowed disabled:opacity-50',
|
|
className,
|
|
)}
|
|
{...props}
|
|
/>
|
|
</div>
|
|
));
|
|
CommandInput.displayName = CommandPrimitive.Input.displayName;
|
|
|
|
const CommandList = React.forwardRef<
|
|
React.ComponentRef<typeof CommandPrimitive.List>,
|
|
React.ComponentPropsWithoutRef<typeof CommandPrimitive.List>
|
|
>(({ className, ...props }, ref) => (
|
|
<CommandPrimitive.List
|
|
ref={ref}
|
|
className={cn('max-h-[300px] overflow-y-auto overflow-x-hidden', className)}
|
|
{...props}
|
|
/>
|
|
));
|
|
CommandList.displayName = CommandPrimitive.List.displayName;
|
|
|
|
const CommandEmpty = React.forwardRef<
|
|
React.ComponentRef<typeof CommandPrimitive.Empty>,
|
|
React.ComponentPropsWithoutRef<typeof CommandPrimitive.Empty>
|
|
>((props, ref) => (
|
|
<CommandPrimitive.Empty ref={ref} className="py-6 text-center text-sm text-[var(--color-sb-muted)]" {...props} />
|
|
));
|
|
CommandEmpty.displayName = CommandPrimitive.Empty.displayName;
|
|
|
|
const CommandGroup = React.forwardRef<
|
|
React.ComponentRef<typeof CommandPrimitive.Group>,
|
|
React.ComponentPropsWithoutRef<typeof CommandPrimitive.Group>
|
|
>(({ className, ...props }, ref) => (
|
|
<CommandPrimitive.Group
|
|
ref={ref}
|
|
className={cn(
|
|
'overflow-hidden p-1 text-[var(--color-sb-text)] [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:py-1.5 [&_[cmdk-group-heading]]:text-xs [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:text-[var(--color-sb-muted)]',
|
|
className,
|
|
)}
|
|
{...props}
|
|
/>
|
|
));
|
|
CommandGroup.displayName = CommandPrimitive.Group.displayName;
|
|
|
|
const CommandItem = React.forwardRef<
|
|
React.ComponentRef<typeof CommandPrimitive.Item>,
|
|
React.ComponentPropsWithoutRef<typeof CommandPrimitive.Item>
|
|
>(({ className, ...props }, ref) => (
|
|
<CommandPrimitive.Item
|
|
ref={ref}
|
|
className={cn(
|
|
'relative flex cursor-pointer select-none items-center gap-2 rounded-md px-2 py-1.5 text-sm outline-none',
|
|
'data-[selected=true]:bg-[var(--color-sb-cell)] data-[selected=true]:text-[var(--color-sb-text-bright)]',
|
|
'data-[disabled=true]:pointer-events-none data-[disabled=true]:opacity-50',
|
|
className,
|
|
)}
|
|
{...props}
|
|
/>
|
|
));
|
|
CommandItem.displayName = CommandPrimitive.Item.displayName;
|
|
|
|
const CommandSeparator = React.forwardRef<
|
|
React.ComponentRef<typeof CommandPrimitive.Separator>,
|
|
React.ComponentPropsWithoutRef<typeof CommandPrimitive.Separator>
|
|
>(({ className, ...props }, ref) => (
|
|
<CommandPrimitive.Separator
|
|
ref={ref}
|
|
className={cn('-mx-1 h-px bg-[var(--color-sb-border)]', className)}
|
|
{...props}
|
|
/>
|
|
));
|
|
CommandSeparator.displayName = CommandPrimitive.Separator.displayName;
|
|
|
|
export {
|
|
Command,
|
|
CommandInput,
|
|
CommandList,
|
|
CommandEmpty,
|
|
CommandGroup,
|
|
CommandItem,
|
|
CommandSeparator,
|
|
};
|