fix: allow table links in chat responses
This commit is contained in:
parent
b91c40f6df
commit
95354eb78d
@ -78,6 +78,16 @@ type MarkdownTableHeaderCellProps = ComponentProps<"th"> & {
|
||||
node?: unknown;
|
||||
};
|
||||
|
||||
const TABLE_DRAG_INTERACTIVE_SELECTOR =
|
||||
"a, button, input, textarea, select, summary, [role='button'], [contenteditable='true'], [data-no-drag='true']";
|
||||
|
||||
function isTableDragInteractiveTarget(target: EventTarget | null) {
|
||||
return (
|
||||
target instanceof HTMLElement &&
|
||||
Boolean(target.closest(TABLE_DRAG_INTERACTIVE_SELECTOR))
|
||||
);
|
||||
}
|
||||
|
||||
function HorizontalDragScrollArea({
|
||||
children,
|
||||
className,
|
||||
@ -126,6 +136,7 @@ function HorizontalDragScrollArea({
|
||||
onPointerCancel={endDrag}
|
||||
onPointerDown={(event) => {
|
||||
if (event.button !== 0) return;
|
||||
if (isTableDragInteractiveTarget(event.target)) return;
|
||||
const element = scrollRef.current;
|
||||
if (!element || element.scrollWidth <= element.clientWidth) return;
|
||||
|
||||
@ -712,6 +723,30 @@ export const Response = ({
|
||||
table: DownloadableMarkdownTable,
|
||||
td: MarkdownTableCell,
|
||||
th: MarkdownTableHeaderCell,
|
||||
a: ({
|
||||
children,
|
||||
className,
|
||||
href,
|
||||
onClick,
|
||||
...linkProps
|
||||
}: ComponentProps<"a">) => (
|
||||
<a
|
||||
{...linkProps}
|
||||
className={cn(
|
||||
"font-medium text-primary underline underline-offset-2",
|
||||
className
|
||||
)}
|
||||
href={href}
|
||||
onClick={(event) => {
|
||||
event.stopPropagation();
|
||||
onClick?.(event);
|
||||
}}
|
||||
rel="noreferrer"
|
||||
target="_blank"
|
||||
>
|
||||
{children}
|
||||
</a>
|
||||
),
|
||||
};
|
||||
|
||||
const renderImagePreview = (src: string, alt: string | undefined, key: string) => (
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user