feat(web): quote chips show what you said about the quote (#15703)
This commit is contained in:
1 parent
33afd5a5aa
commit
12865b4a73
2 files changed
+60
-26
No files matched your search
@@ -19,11 +19,6 @@ vi.mock("@tanstack/react-router", () => ({
|
||||
Link: ({ children }: { children: ReactNode }) => <a>{children}</a>,
|
||||
}));
|
||||
// Keep the real chip/editor lifecycle while replacing DOM positioning and floating layers.
|
||||
vi.mock("../ui/tooltip", () => ({
|
||||
Tooltip: ({ children }: { children: ReactNode }) => <>{children}</>,
|
||||
TooltipTrigger: ({ render }: { render: ReactNode }) => render,
|
||||
TooltipPopup: ({ children }: { children: ReactNode }) => <>{children}</>,
|
||||
}));
|
||||
vi.mock("../ui/popover", () => ({
|
||||
Popover: ({ children }: { children: ReactNode }) => <>{children}</>,
|
||||
PopoverTrigger: ({ children }: { children: ReactNode }) => <button>{children}</button>,
|
||||
@@ -62,6 +57,7 @@ function mount(onSave = vi.fn(() => true)) {
|
||||
return (
|
||||
<AssistantCitationChip
|
||||
citation={citation}
|
||||
composer
|
||||
commentEditor={{ open, sourceAnchor, onOpenChange: setOpen, onSave }}
|
||||
/>
|
||||
);
|
||||
|
||||
@@ -4,7 +4,7 @@ import {
|
||||
serializeAssistantCitation,
|
||||
} from "@t3tools/shared/assistantCitations";
|
||||
import { Link, useNavigate } from "@tanstack/react-router";
|
||||
import { PencilIcon, QuoteIcon } from "lucide-react";
|
||||
import { ArrowUpRightIcon, PencilIcon, QuoteIcon } from "lucide-react";
|
||||
import {
|
||||
useEffect,
|
||||
useEffectEvent,
|
||||
@@ -20,9 +20,12 @@ import {
|
||||
assistantCitationHash,
|
||||
assistantCitationNavigation,
|
||||
} from "../../lib/assistantCitationNavigation";
|
||||
import { cn } from "~/lib/utils";
|
||||
import { ContextChip, ContextChipAction, ContextChipLabel } from "../ContextChip";
|
||||
import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip";
|
||||
import { Popover, PopoverPopup, PopoverTrigger } from "../ui/popover";
|
||||
import { ContextChipPopover } from "../contextChipParts";
|
||||
import { Button } from "../ui/button";
|
||||
import { Popover, PopoverClose, PopoverPopup, PopoverTrigger } from "../ui/popover";
|
||||
import { getVirtualizedScrollFadeClassName } from "../ui/scroll-area";
|
||||
import { AssistantCitationCommentEditor } from "./AssistantCitationCommentEditor";
|
||||
import { resolveAssistantCitationCommentDismissal } from "./assistantCitationCommentDismissal";
|
||||
import { observeAssistantCitationCommentSource } from "./AssistantCitationSource";
|
||||
@@ -122,16 +125,27 @@ export function AssistantCitationChip({
|
||||
<ContextChipLabel className="max-w-[16em]">{label}</ContextChipLabel>
|
||||
</Link>
|
||||
);
|
||||
const chatSourceLink = (
|
||||
<Link
|
||||
{...sourceLinkProps}
|
||||
className="inline-flex h-full min-w-0 items-center gap-[0.33em] rounded-sm text-inherit no-underline hover:bg-(--context-chip-accent)/17 focus-visible:outline-2 focus-visible:outline-foreground"
|
||||
aria-label={`View cited assistant text: ${label}`}
|
||||
>
|
||||
<QuoteIcon aria-hidden="true" />
|
||||
<ContextChipLabel className="max-w-[16em]">{label}</ContextChipLabel>
|
||||
</Link>
|
||||
);
|
||||
if (!composer) {
|
||||
return (
|
||||
<ContextChipPopover
|
||||
kind="citation"
|
||||
icon={<QuoteIcon />}
|
||||
label={label}
|
||||
accessibleLabel={`Quoted assistant text: ${label}`}
|
||||
copyMarkdown={serializeAssistantCitation(citation)}
|
||||
>
|
||||
<div className="flex max-h-[calc(var(--available-height)_-_1rem_-_2px)] flex-col items-start gap-3 p-1 text-sm">
|
||||
<AssistantCitationQuote citation={citation} />
|
||||
<PopoverClose
|
||||
render={<Button variant="outline" size="sm" render={<Link {...sourceLinkProps} />} />}
|
||||
>
|
||||
<ArrowUpRightIcon aria-hidden="true" />
|
||||
Go to source
|
||||
</PopoverClose>
|
||||
</div>
|
||||
</ContextChipPopover>
|
||||
);
|
||||
}
|
||||
return (
|
||||
<ContextChip
|
||||
kind="citation"
|
||||
@@ -139,14 +153,7 @@ export function AssistantCitationChip({
|
||||
data-assistant-citation-chip="true"
|
||||
data-markdown-copy={serializeAssistantCitation(citation)}
|
||||
>
|
||||
{composer ? (
|
||||
composerSourceLink
|
||||
) : (
|
||||
<Tooltip>
|
||||
<TooltipTrigger render={chatSourceLink} />
|
||||
<TooltipPopup side="top">View source</TooltipPopup>
|
||||
</Tooltip>
|
||||
)}
|
||||
{composerSourceLink}
|
||||
{commentEditor ? (
|
||||
<Popover
|
||||
open={commentEditor.open}
|
||||
@@ -232,3 +239,34 @@ export function AssistantCitationChip({
|
||||
</ContextChip>
|
||||
);
|
||||
}
|
||||
|
||||
function AssistantCitationQuote({ citation }: { citation: AssistantCitation }) {
|
||||
const [fade, setFade] = useState({ top: false, bottom: false });
|
||||
const updateFade = (element: HTMLElement) => {
|
||||
const top = element.scrollTop > 1;
|
||||
const bottom = element.scrollHeight - element.clientHeight - element.scrollTop > 1;
|
||||
setFade((current) =>
|
||||
current.top === top && current.bottom === bottom ? current : { top, bottom },
|
||||
);
|
||||
};
|
||||
return (
|
||||
<div
|
||||
ref={(element) => {
|
||||
if (!element) return;
|
||||
const observer = new ResizeObserver(() => updateFade(element));
|
||||
observer.observe(element);
|
||||
return () => observer.disconnect();
|
||||
}}
|
||||
onScroll={(event) => updateFade(event.currentTarget)}
|
||||
className={cn(
|
||||
"max-h-64 min-h-0 space-y-3 self-stretch overflow-y-auto whitespace-pre-wrap wrap-break-word",
|
||||
getVirtualizedScrollFadeClassName(fade),
|
||||
)}
|
||||
>
|
||||
<blockquote className="border-l-2 border-border pl-3 text-muted-foreground">
|
||||
{citation.text}
|
||||
</blockquote>
|
||||
{citation.comment ? <p>{citation.comment}</p> : null}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user