refactor(webui): use native link actions and remove website previews (#6391)
* refactor(webui): remove website previews and custom link menus * docs(webui): focus guide on product-specific usage
This commit is contained in:
1 parent
bc5c58d239
commit
08ca3b4525
42 files changed
+179
-1493
No files matched your search
@@ -7,7 +7,7 @@ import {
|
||||
useState,
|
||||
type ReactNode,
|
||||
} from "react";
|
||||
import { Activity, Check, ChevronRight, CircleAlert, Clock3, Copy, Link2, Quote, Wrench } from "lucide-react";
|
||||
import { Activity, Check, ChevronRight, CircleAlert, Clock3, Copy, Quote, Wrench } from "lucide-react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { DisclosureContent } from "@/components/ui/disclosure";
|
||||
|
||||
@@ -145,7 +145,6 @@ interface MessageBlockMenuActionsProps {
|
||||
isTurnStreaming?: boolean;
|
||||
onForkFromHere?: () => void;
|
||||
activity?: MessageBlockMenuActivity;
|
||||
onViewLinks?: () => void;
|
||||
sheet?: boolean;
|
||||
}
|
||||
|
||||
@@ -155,7 +154,6 @@ export function MessageBlockMenuActions({
|
||||
isTurnStreaming = false,
|
||||
onForkFromHere,
|
||||
activity,
|
||||
onViewLinks,
|
||||
sheet = false,
|
||||
}: MessageBlockMenuActionsProps) {
|
||||
const { t } = useTranslation();
|
||||
@@ -248,10 +246,6 @@ export function MessageBlockMenuActions({
|
||||
) : null}
|
||||
</div>
|
||||
) : null}
|
||||
{onViewLinks ? <button type="button" data-message-links-trigger onClick={onViewLinks}
|
||||
className="flex min-h-[var(--message-block-control-size)] w-full items-center gap-2 rounded-control px-2 py-1.5 text-[13px] text-muted-foreground hover:bg-muted/70 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring">
|
||||
<Link2 className="h-3.5 w-3.5" aria-hidden />{t("webPreview.viewLinks")}
|
||||
</button> : null}
|
||||
<FallbackResponseSources
|
||||
sources={message.role === "assistant" ? message.responseSources : undefined}
|
||||
className="min-h-[var(--message-block-control-size)] gap-1"
|
||||
|
||||
@@ -1,94 +0,0 @@
|
||||
import { useContext, useLayoutEffect, useRef, useState, type RefObject } from "react";
|
||||
import { ArrowLeft, ChevronRight, Link2 } from "lucide-react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
|
||||
import { WebPreviewContext } from "@/components/WebLink";
|
||||
import { floatingItemClassName, floatingItemFocusClassName } from "@/components/ui/floating-surface";
|
||||
import { copyTextToClipboard } from "@/lib/clipboard";
|
||||
import { currentWebPreviewRestriction, parseWebLink } from "@/lib/web-preview";
|
||||
|
||||
interface MessageWebLink { href: string; title: string }
|
||||
|
||||
/** Read only links actually rendered in this message, not code samples or file references. */
|
||||
export function useMessageWebLinks(root: RefObject<HTMLElement>, open: boolean) {
|
||||
const [links, setLinks] = useState<MessageWebLink[]>([]);
|
||||
useLayoutEffect(() => {
|
||||
const element = root.current;
|
||||
if (!open || !element) return;
|
||||
const collect = () => {
|
||||
const unique = new Map<string, MessageWebLink>();
|
||||
element.querySelectorAll<HTMLAnchorElement>("[data-assistant-selectable] a[data-web-link]").forEach((anchor) => {
|
||||
const href = anchor.getAttribute("href") ?? "";
|
||||
const url = parseWebLink(href);
|
||||
if (url && !unique.has(url.href)) {
|
||||
unique.set(url.href, { href, title: anchor.textContent?.trim() || href });
|
||||
}
|
||||
});
|
||||
setLinks(Array.from(unique.values()));
|
||||
};
|
||||
collect();
|
||||
// Markdown is lazy-loaded; collect again when its real links appear/change.
|
||||
const observer = new MutationObserver(collect);
|
||||
observer.observe(element, { subtree: true, childList: true, characterData: true, attributes: true, attributeFilter: ["href"] });
|
||||
return () => observer.disconnect();
|
||||
}, [root, open]);
|
||||
return links;
|
||||
}
|
||||
|
||||
const itemClassName = `${floatingItemClassName} ${floatingItemFocusClassName} w-full min-h-11 text-start hover:bg-muted/70`;
|
||||
|
||||
/** A drill-in inside the message's action surface, not another floating layer. */
|
||||
export function MessageLinksMenu({ links, onBack, onClose, expanded = false }: {
|
||||
links: MessageWebLink[];
|
||||
onBack: () => void;
|
||||
onClose: () => void;
|
||||
expanded?: boolean;
|
||||
}) {
|
||||
const { t } = useTranslation();
|
||||
const openPreview = useContext(WebPreviewContext);
|
||||
const [selected, setSelected] = useState<string | null>(links.length === 1 ? links[0].href : null);
|
||||
const active = links.find((link) => link.href === selected);
|
||||
const backRef = useRef<HTMLButtonElement>(null);
|
||||
useLayoutEffect(() => { backRef.current?.focus({ preventScroll: true }); }, [selected]);
|
||||
return <div className={expanded ? "w-full" : "w-60 max-w-full"}>
|
||||
<button ref={backRef} type="button" className={itemClassName} aria-label={t("webPreview.back")}
|
||||
onClick={() => active && links.length > 1 ? setSelected(null) : onBack()}>
|
||||
<ArrowLeft aria-hidden /><span>{t("webPreview.viewLinks")}</span>
|
||||
</button>
|
||||
{active ? <MessageLinkActions key={active.href} link={active} onClose={onClose}
|
||||
onPreview={openPreview ? () => { onClose(); openPreview(active.href); } : undefined} />
|
||||
: <div className="border-t border-border/45 pt-1">
|
||||
{links.map((link) => <button type="button" key={link.href} className={itemClassName} onClick={() => setSelected(link.href)}>
|
||||
<Link2 className="text-muted-foreground" aria-hidden />
|
||||
<span className="min-w-0 flex-1 truncate">{link.title}</span><ChevronRight className="text-muted-foreground" aria-hidden />
|
||||
</button>)}
|
||||
</div>}
|
||||
</div>;
|
||||
}
|
||||
|
||||
function MessageLinkActions({ link, onClose, onPreview }: {
|
||||
link: MessageWebLink;
|
||||
onClose: () => void;
|
||||
onPreview?: () => void;
|
||||
}) {
|
||||
const { t } = useTranslation();
|
||||
const restriction = onPreview ? currentWebPreviewRestriction(parseWebLink(link.href)) : null;
|
||||
const [feedback, setFeedback] = useState<"copied" | "copyFailed" | null>(null);
|
||||
const mounted = useRef(false);
|
||||
useLayoutEffect(() => {
|
||||
mounted.current = true;
|
||||
return () => { mounted.current = false; };
|
||||
}, []);
|
||||
const copy = async () => {
|
||||
const success = await copyTextToClipboard(link.href);
|
||||
if (mounted.current) setFeedback(success ? "copied" : "copyFailed");
|
||||
};
|
||||
return <div className="border-t border-border/45 pt-1">
|
||||
<p className="max-h-24 overflow-y-auto px-2.5 py-2 text-xs text-muted-foreground [overflow-wrap:anywhere]" dir="auto">{link.href}</p>
|
||||
{onPreview && !restriction ? <button type="button" className={itemClassName} onClick={onPreview}>{t("webPreview.open")}</button> : null}
|
||||
<a className={itemClassName} href={link.href} target="_blank" rel="noreferrer noopener" onClick={onClose}>{t("webPreview.external")}</a>
|
||||
<button type="button" className={itemClassName} onClick={() => { void copy(); }}>{t("webPreview.copy")}</button>
|
||||
{restriction ? <p className="px-2.5 py-1.5 text-xs leading-relaxed text-muted-foreground">{t(`webPreview.${restriction}`)}</p> : null}
|
||||
{feedback ? <p role="status" className="px-2.5 py-1.5 text-xs text-muted-foreground">{t(`webPreview.${feedback}`)}</p> : null}
|
||||
</div>;
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
import { useEffect, useId, useRef, useState, type CSSProperties, type PointerEvent, type ReactNode } from "react";
|
||||
import { Globe2, PanelRightClose, X } from "lucide-react";
|
||||
import { PanelRightClose, X } from "lucide-react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { FileReferenceIcon, fileKindForPath, splitFilePath } from "@/components/FileReferenceChip";
|
||||
import { FileActions } from "@/components/FileActions";
|
||||
@@ -7,10 +7,6 @@ import { SidebarSelectionHighlight, SIDEBAR_SELECTION_ITEM_CLASS } from "@/compo
|
||||
import type { PreviewTab } from "@/hooks/useFilePreviewState";
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
function tabName(tab: PreviewTab) {
|
||||
return tab.kind === "web" ? new URL(tab.value).host : splitFilePath(tab.value).name;
|
||||
}
|
||||
|
||||
/** One stable sidebar shell: switching targets never replays its opening animation. */
|
||||
export function PreviewPane({ tabs, activeId, width, isClosing, onSelect, onCloseTab, onClose, onResizeStart, children }: {
|
||||
tabs: PreviewTab[];
|
||||
@@ -72,7 +68,7 @@ export function PreviewPane({ tabs, activeId, width, isClosing, onSelect, onClos
|
||||
highlightClassName="rounded-compact">
|
||||
{tabs.map((tab, index) => {
|
||||
const selected = tab.id === activeId;
|
||||
const name = tabName(tab);
|
||||
const name = splitFilePath(tab.value).name;
|
||||
const item = <div key={tab.id} role="presentation" data-preview-tab-active={selected ? "" : undefined}
|
||||
className={cn(SIDEBAR_SELECTION_ITEM_CLASS, "group flex min-h-8 max-w-56 shrink-0 items-center rounded-compact", selected ? "text-foreground" : "text-muted-foreground hover:bg-muted/50 hover:text-foreground")}>
|
||||
<button type="button" role="tab" id={`${id}-tab-${index}`} aria-selected={selected} aria-controls={`${id}-panel`}
|
||||
@@ -93,8 +89,7 @@ export function PreviewPane({ tabs, activeId, width, isClosing, onSelect, onClos
|
||||
}}
|
||||
className="touch-target flex h-8 min-w-0 items-center gap-1.5 rounded-compact pl-2.5 pr-1.5 text-[12.5px] font-medium leading-5 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring">
|
||||
<span aria-hidden className="flex size-3.5 shrink-0 items-center justify-center text-muted-foreground">
|
||||
{tab.kind === "web" ? <Globe2 className="size-3.5" />
|
||||
: <FileReferenceIcon kind={fileKindForPath(tab.value)} className="size-3.5" />}
|
||||
<FileReferenceIcon kind={fileKindForPath(tab.value)} className="size-3.5" />
|
||||
</span>
|
||||
<span className="truncate">{name}</span>
|
||||
</button>
|
||||
@@ -104,7 +99,7 @@ export function PreviewPane({ tabs, activeId, width, isClosing, onSelect, onClos
|
||||
<X className="size-3" aria-hidden />
|
||||
</button>
|
||||
</div>;
|
||||
return tab.kind === "file" ? <FileActions key={tab.id} path={tab.value} className="shrink-0">{item}</FileActions> : item;
|
||||
return <FileActions key={tab.id} path={tab.value} className="shrink-0">{item}</FileActions>;
|
||||
})}
|
||||
</SidebarSelectionHighlight>
|
||||
</div>
|
||||
|
||||
@@ -1,108 +1,21 @@
|
||||
import { createContext, useContext, useEffect, useRef, useState, type ComponentPropsWithoutRef } from "react";
|
||||
import * as Menu from "@radix-ui/react-menu";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import type { ComponentPropsWithoutRef } from "react";
|
||||
|
||||
import { floatingItemClassName, floatingItemFocusClassName, floatingSurfaceClassName, floatingSurfaceMotionClassName } from "@/components/ui/floating-surface";
|
||||
import { useFloatingPortal } from "@/components/ui/floating-portal";
|
||||
import { copyTextToClipboard } from "@/lib/clipboard";
|
||||
import { currentWebPreviewRestriction, parseWebLink } from "@/lib/web-preview";
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
export const WebPreviewContext = createContext<((url: string) => void) | undefined>(undefined);
|
||||
|
||||
const itemClassName = `${floatingItemClassName} ${floatingItemFocusClassName} cursor-default`;
|
||||
function parseWebLink(value: string): URL | null {
|
||||
if (value.length > 8192 || value.includes("\\")
|
||||
|| Array.from(value).some((char) => char.charCodeAt(0) <= 32 || char.charCodeAt(0) === 127)) return null;
|
||||
try {
|
||||
const url = new URL(value);
|
||||
return /^https?:$/.test(url.protocol) && !url.username && !url.password ? url : null;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
export function WebLink({ href = "", children, ...props }: ComponentPropsWithoutRef<"a">) {
|
||||
const url = parseWebLink(href);
|
||||
if (url) return <WebsiteLink key={href} {...props} href={href}>{children}</WebsiteLink>;
|
||||
// Keep the renderer's relative media/document and mail links unchanged.
|
||||
const relative = !/^[a-z][a-z\d+.-]*:/i.test(href)
|
||||
&& !href.includes("\\") && !Array.from(href).some((char) => char.charCodeAt(0) < 32);
|
||||
return relative || /^(mailto:|tel:|#)/i.test(href)
|
||||
return url || relative || /^(mailto:|tel:|#)/i.test(href)
|
||||
? <a {...props} href={href} target="_blank" rel="noreferrer noopener">{children}</a> : <>{children}</>;
|
||||
}
|
||||
|
||||
/** Keep links as links; secondary actions share the compact file-reference surface. */
|
||||
function WebsiteLink({ href, children, className, ...props }: ComponentPropsWithoutRef<"a"> & { href: string }) {
|
||||
const { t } = useTranslation();
|
||||
const openPreview = useContext(WebPreviewContext);
|
||||
const portal = useFloatingPortal();
|
||||
const [open, setOpen] = useState(false);
|
||||
const restriction = open && openPreview ? currentWebPreviewRestriction(parseWebLink(href)) : null;
|
||||
const [feedback, setFeedback] = useState<"copied" | "copyFailed" | null>(null);
|
||||
const link = useRef<HTMLAnchorElement>(null);
|
||||
const point = useRef({ x: 0, y: 0 });
|
||||
const anchor = useRef({ getBoundingClientRect: () => new DOMRect(point.current.x, point.current.y, 0, 0) });
|
||||
const interactedOutside = useRef(false);
|
||||
const generation = useRef(0);
|
||||
const pointerType = useRef("");
|
||||
|
||||
useEffect(() => () => {
|
||||
generation.current += 1;
|
||||
}, []);
|
||||
|
||||
const changeOpen = (next: boolean) => {
|
||||
generation.current += 1;
|
||||
setOpen(next);
|
||||
};
|
||||
const openAt = (x: number, y: number) => {
|
||||
point.current = { x, y };
|
||||
interactedOutside.current = false;
|
||||
setFeedback(null);
|
||||
changeOpen(true);
|
||||
};
|
||||
const copy = async () => {
|
||||
const current = generation.current;
|
||||
const copied = await copyTextToClipboard(href);
|
||||
// Late clipboard results must not dismiss a new menu or report another URL.
|
||||
if (current !== generation.current) return;
|
||||
setFeedback(copied ? "copied" : "copyFailed");
|
||||
if (copied) changeOpen(false);
|
||||
};
|
||||
|
||||
return <Menu.Root open={open} onOpenChange={changeOpen}>
|
||||
<Menu.Anchor virtualRef={anchor} />
|
||||
<span className="inline max-w-full"
|
||||
onContextMenu={(event) => {
|
||||
event.stopPropagation();
|
||||
// Touch keeps the browser's native link preview/copy/share menu. Older
|
||||
// WebKit exposes contextmenu as a MouseEvent, so remember the last pointer.
|
||||
const type = (event.nativeEvent as PointerEvent).pointerType || pointerType.current;
|
||||
if (type === "touch" || (!type && window.matchMedia("(pointer: coarse)").matches)) return;
|
||||
event.preventDefault();
|
||||
openAt(event.clientX, event.clientY);
|
||||
}}
|
||||
onKeyDown={(event) => {
|
||||
if (event.key !== "ContextMenu" && !(event.shiftKey && event.key === "F10")) return;
|
||||
event.preventDefault(); event.stopPropagation();
|
||||
const bounds = link.current!.getBoundingClientRect();
|
||||
openAt(bounds.left, bounds.bottom);
|
||||
}}
|
||||
onPointerDown={(event) => {
|
||||
pointerType.current = event.pointerType;
|
||||
}}>
|
||||
<a {...props} ref={link} data-web-link href={href} target="_blank" rel="noreferrer noopener"
|
||||
className={className}>{children}</a>
|
||||
</span>
|
||||
{feedback === "copied" ? <span role="status" className="sr-only">{t("webPreview.copied")}</span> : null}
|
||||
<Menu.Portal container={portal ?? undefined}>
|
||||
<Menu.Content aria-label={t("webPreview.actions")} align="start" sideOffset={4} collisionPadding={12}
|
||||
className={cn(floatingSurfaceClassName, floatingSurfaceMotionClassName, "min-w-40 rounded-control p-1 [&_[role=menuitem]]:py-1.5 [@media(pointer:coarse)]:[&_[role=menuitem]]:min-h-11")}
|
||||
onContextMenu={(event) => { event.preventDefault(); event.stopPropagation(); }}
|
||||
onClick={(event) => event.stopPropagation()}
|
||||
onInteractOutside={() => { interactedOutside.current = true; }}
|
||||
onCloseAutoFocus={(event) => {
|
||||
event.preventDefault();
|
||||
if (!interactedOutside.current) link.current?.focus();
|
||||
}}>
|
||||
{openPreview && !restriction ? <Menu.Item className={itemClassName} onSelect={() => openPreview(href)}>{t("webPreview.open")}</Menu.Item> : null}
|
||||
<Menu.Item asChild className={itemClassName}>
|
||||
<a href={href} target="_blank" rel="noreferrer noopener">{t("webPreview.external")}</a>
|
||||
</Menu.Item>
|
||||
<Menu.Item className={itemClassName} onSelect={(event) => { event.preventDefault(); void copy(); }}>{t("webPreview.copy")}</Menu.Item>
|
||||
{restriction ? <p className="max-w-64 px-2.5 py-1.5 text-xs leading-relaxed text-muted-foreground">{t(`webPreview.${restriction}`)}</p> : null}
|
||||
{feedback === "copyFailed" ? <div role="status" className="max-w-64 px-2.5 py-1.5 text-xs text-muted-foreground">{t("webPreview.copyFailed")}</div> : null}
|
||||
</Menu.Content>
|
||||
</Menu.Portal>
|
||||
</Menu.Root>;
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
import { useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
|
||||
import { WebPreviewPanelView } from "@/components/WebPreviewPanelView";
|
||||
import { isLoopbackHost } from "@/lib/network";
|
||||
import { currentWebPreviewRestriction, parseWebLink } from "@/lib/web-preview";
|
||||
|
||||
interface WebPreviewPanelProps {
|
||||
url: string;
|
||||
}
|
||||
|
||||
export function WebPreviewPanel({ url: value }: WebPreviewPanelProps) {
|
||||
const { t } = useTranslation();
|
||||
const [revision, setRevision] = useState(0);
|
||||
const url = parseWebLink(value);
|
||||
const restriction = currentWebPreviewRestriction(url);
|
||||
return <WebPreviewPanelView url={url} restriction={restriction} loopback={!!url && isLoopbackHost(url.hostname)}
|
||||
onRefresh={() => setRevision((n) => n + 1)}>
|
||||
{!restriction ? <iframe key={`${value}:${revision}`} title={t("webPreview.frame", { host: url!.host })}
|
||||
{...{ credentialless: "" }} sandbox="allow-scripts" referrerPolicy="no-referrer"
|
||||
allow="camera 'none'; microphone 'none'; geolocation 'none'; clipboard-read 'none'; clipboard-write 'none'; payment 'none'; fullscreen 'none'; display-capture 'none'; usb 'none'; serial 'none'; hid 'none'"
|
||||
src={url!.href} className="min-h-0 w-full flex-1 border-0 bg-white" /> : null}
|
||||
</WebPreviewPanelView>;
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
import type { ReactNode } from "react";
|
||||
import { ExternalLink, Info, RotateCw } from "lucide-react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
|
||||
import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover";
|
||||
import type { currentWebPreviewRestriction } from "@/lib/web-preview";
|
||||
|
||||
export function WebPreviewPanelView({ url, restriction, loopback, onRefresh, children }: {
|
||||
url: URL | null;
|
||||
restriction: ReturnType<typeof currentWebPreviewRestriction>;
|
||||
loopback: boolean;
|
||||
onRefresh: () => void;
|
||||
children?: ReactNode;
|
||||
}) {
|
||||
const { t } = useTranslation();
|
||||
const buttonClass = "inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-md text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring";
|
||||
return (
|
||||
<section aria-label={t("webPreview.title")} data-testid="web-preview-panel" className="flex min-h-0 flex-1 flex-col">
|
||||
<div className="flex h-9 shrink-0 items-center gap-1 border-b border-border/40 px-2">
|
||||
<p className="min-w-0 flex-1 truncate px-1 text-xs text-muted-foreground" title={url?.href}>{url?.href}</p>
|
||||
<Popover>
|
||||
<PopoverTrigger asChild><button type="button" className={buttonClass} aria-label={t("previewTabs.websiteInfo")} title={t("previewTabs.websiteInfo")}><Info className="size-3.5" aria-hidden /></button></PopoverTrigger>
|
||||
<PopoverContent align="end" className="w-72 space-y-2 rounded-control p-3 text-xs leading-relaxed text-muted-foreground">
|
||||
<p>{t("webPreview.isolated")}</p>
|
||||
<p>{t("webPreview.blockedHint")}</p>
|
||||
{loopback ? <p>{t("webPreview.loopback")}</p> : null}
|
||||
</PopoverContent>
|
||||
</Popover>
|
||||
{!restriction ? <button type="button" className={buttonClass} onClick={onRefresh} title={t("webPreview.refresh")} aria-label={t("webPreview.refresh")}>
|
||||
<RotateCw className="h-4 w-4" aria-hidden />
|
||||
</button> : null}
|
||||
{url ? <a className={buttonClass} href={url.href} target="_blank" rel="noreferrer noopener" title={t("webPreview.external")} aria-label={t("webPreview.external")}>
|
||||
<ExternalLink className="h-4 w-4" aria-hidden />
|
||||
</a> : null}
|
||||
</div>
|
||||
{restriction ? <div role="status" className="flex min-h-0 flex-1 items-center justify-center overflow-auto p-6 text-center text-sm text-muted-foreground">
|
||||
{t(`webPreview.${restriction}`)}
|
||||
</div> : children}
|
||||
</section>
|
||||
);
|
||||
}
|
||||
@@ -1,8 +1,7 @@
|
||||
import { Fragment, memo, useCallback, useEffect, useId, useLayoutEffect, useMemo, useRef, useState, type ReactNode, type RefObject } from "react";
|
||||
import { Fragment, memo, useCallback, useEffect, useId, useLayoutEffect, useMemo, useRef, useState, type ReactNode } from "react";
|
||||
import { MoreHorizontal } from "lucide-react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { MessageBlockMenuActions, MessageBubble, MessageCopyButton } from "@/components/MessageBubble";
|
||||
import { MessageLinksMenu, useMessageWebLinks } from "@/components/MessageLinksMenu";
|
||||
import { FallbackResponseSources } from "@/components/ResponseSourceBadge";
|
||||
import {
|
||||
AgentActivityCluster,
|
||||
@@ -395,7 +394,6 @@ interface ThreadDisplayUnitProps {
|
||||
|
||||
interface MessageBlockMenuProps {
|
||||
mobileActions: boolean;
|
||||
messageRoot: RefObject<HTMLElement>;
|
||||
message: UIMessage;
|
||||
isTurnStreaming: boolean;
|
||||
contextBlockKey: string;
|
||||
@@ -414,7 +412,6 @@ interface MessageBlockMenuProps {
|
||||
|
||||
function MessageBlockMenu({
|
||||
mobileActions,
|
||||
messageRoot,
|
||||
message,
|
||||
isTurnStreaming,
|
||||
contextBlockKey,
|
||||
@@ -428,9 +425,6 @@ function MessageBlockMenu({
|
||||
const { t } = useTranslation();
|
||||
const contentRef = useRef<HTMLDivElement>(null);
|
||||
const triggerRef = useRef<HTMLButtonElement>(null);
|
||||
const links = useMessageWebLinks(messageRoot, open);
|
||||
const [linksShown, setLinksShown] = useState(false);
|
||||
useEffect(() => { if (!open) setLinksShown(false); }, [open]);
|
||||
const [triggerHeight, setTriggerHeight] = useState(28);
|
||||
useLayoutEffect(() => {
|
||||
const trigger = triggerRef.current;
|
||||
@@ -451,16 +445,12 @@ function MessageBlockMenu({
|
||||
// Re-evaluated when this message becomes active, including after an overnight idle.
|
||||
const shortTime = mobileActions ? "" : formatMessageHoverTime(timestamp);
|
||||
const fullTime = shortTime ? fmtDateTime(timestamp) : "";
|
||||
const actions = linksShown && links.length > 0 ? <MessageLinksMenu links={links}
|
||||
expanded={mobileActions}
|
||||
onBack={() => { setLinksShown(false); contentRef.current?.focus({ preventScroll: true }); }}
|
||||
onClose={() => onOpenChange(false)} /> : <MessageBlockMenuActions
|
||||
const actions = <MessageBlockMenuActions
|
||||
message={message}
|
||||
isTurnStreaming={isTurnStreaming}
|
||||
onForkFromHere={onForkFromHere ? () => { if (mobileActions) onOpenChange(false); onForkFromHere(); } : undefined}
|
||||
activity={activity}
|
||||
sheet={mobileActions}
|
||||
onViewLinks={links.length > 0 ? () => setLinksShown(true) : undefined}
|
||||
/>;
|
||||
if (mobileActions) {
|
||||
return <div data-message-mobile-actions className={cn("mt-1 flex items-center", message.role === "user" ? "me-2 justify-end" : "-ms-2")}>
|
||||
@@ -665,7 +655,6 @@ const ThreadDisplayUnit = memo(function ThreadDisplayUnit({
|
||||
const blockMenu = unit.type === "message" && contextBlockKey !== undefined ? (
|
||||
<MessageBlockMenu
|
||||
mobileActions={mobileActions}
|
||||
messageRoot={elementRef}
|
||||
message={unit.message}
|
||||
isTurnStreaming={isTurnStreaming}
|
||||
contextBlockKey={contextBlockKey}
|
||||
|
||||
@@ -7,9 +7,6 @@ import { FilePreviewAvailabilityProvider } from "@/components/FilePreviewAvailab
|
||||
import { FilePreviewPanel } from "@/components/FilePreviewPanel";
|
||||
import { PreviewPane } from "@/components/PreviewPane";
|
||||
import { FileActionsProvider } from "@/components/FileActions";
|
||||
import { WebPreviewContext } from "@/components/WebLink";
|
||||
import { WebPreviewPanel } from "@/components/WebPreviewPanel";
|
||||
import { parseWebLink } from "@/lib/web-preview";
|
||||
import { createFilePreviewResource } from "@/lib/file-preview-resource";
|
||||
import { SessionHandleLabel } from "@/components/SessionHandleLabel";
|
||||
import { PromptNavigator } from "@/components/thread/PromptNavigator";
|
||||
@@ -538,7 +535,7 @@ export function ThreadShell({
|
||||
} | null>(null);
|
||||
const [heroGreetingKey, setHeroGreetingKey] = useState(randomHeroGreetingKey);
|
||||
const [submittedViewportTurnId, setSubmittedViewportTurnId] = useState<string | null>(null);
|
||||
const { state: previewState, openFile, resolveFile, openWeb, selectTab, closeTab, close: closePreview, setWidth: setFilePreviewWidth } =
|
||||
const { state: previewState, openFile, resolveFile, selectTab, closeTab, close: closePreview, setWidth: setFilePreviewWidth } =
|
||||
useFilePreviewState(previewSessionKey, filePreviewStore);
|
||||
const [closingPreview, setClosingPreview] = useState<{ key: string; state: FilePreviewState } | null>(null);
|
||||
const filePreviewClosing = closingPreview?.key === previewSessionKey;
|
||||
@@ -1127,13 +1124,6 @@ export function ThreadShell({
|
||||
loadPreview: filePreviews.load,
|
||||
}), [resolveFileMetadata, filePreviews]);
|
||||
|
||||
const openWebPreview = useCallback((url: string) => {
|
||||
const parsed = parseWebLink(url);
|
||||
if (!parsed) return;
|
||||
cancelPreviewClose();
|
||||
openWeb(parsed.href);
|
||||
}, [cancelPreviewClose, openWeb]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!previewOpen || !headerActive) return;
|
||||
const onKeyDown = (event: KeyboardEvent) => {
|
||||
@@ -1452,7 +1442,6 @@ export function ThreadShell({
|
||||
resolve={previewSessionKey ? resolveFilePreviewAvailability : undefined}
|
||||
>
|
||||
<FileActionsProvider value={previewSessionKey ? fileActions : undefined}>
|
||||
<WebPreviewContext.Provider value={previewSessionKey ? openWebPreview : undefined}>
|
||||
<ThreadViewport
|
||||
ref={viewportRef}
|
||||
messages={displayMessages}
|
||||
@@ -1485,7 +1474,6 @@ export function ThreadShell({
|
||||
onForkFromMessage={onForkChat ? handleForkFromMessage : undefined}
|
||||
onQuoteSelection={session ? handleQuoteSelection : undefined}
|
||||
/>
|
||||
</WebPreviewContext.Provider>
|
||||
</FileActionsProvider>
|
||||
</FilePreviewAvailabilityProvider>
|
||||
</div>
|
||||
@@ -1515,18 +1503,16 @@ export function ThreadShell({
|
||||
onClose={handleCloseFilePreview}
|
||||
onResizeStart={handleFilePreviewResizeStart}
|
||||
>
|
||||
{activePreview.kind === "file" ? (
|
||||
<FilePreviewPanel
|
||||
key={activePreview.id}
|
||||
sessionKey={previewSessionKey}
|
||||
path={activePreview.value}
|
||||
token={token}
|
||||
loadPreview={filePreviews.load}
|
||||
initialPreview={filePreviews.peek(activePreview.value)}
|
||||
onOpenFilePreview={openFilePreview}
|
||||
onResolvePath={resolveFile}
|
||||
/>
|
||||
) : <WebPreviewPanel key={activePreview.id} url={activePreview.value} />}
|
||||
<FilePreviewPanel
|
||||
key={activePreview.id}
|
||||
sessionKey={previewSessionKey}
|
||||
path={activePreview.value}
|
||||
token={token}
|
||||
loadPreview={filePreviews.load}
|
||||
initialPreview={filePreviews.peek(activePreview.value)}
|
||||
onOpenFilePreview={openFilePreview}
|
||||
onResolvePath={resolveFile}
|
||||
/>
|
||||
</PreviewPane>
|
||||
</FileActionsProvider>
|
||||
) : null}
|
||||
|
||||
Reference in new issue
Block a user