import { atUriToUrl, classifyAtUri } from "src/utils/mentionUtils";
/**
* Component for rendering at-uri mentions (publications and documents) as clickable links.
* NOTE: This component's styling and behavior should match the ProseMirror schema rendering
* in components/Blocks/TextBlock/schema.ts (atMention mark). If you update one, update the other.
*/
export function AtMentionLink({
atURI,
href,
icon: iconUrl,
children,
className = "",
}: {
atURI: string;
href?: string;
icon?: string;
children: React.ReactNode;
className?: string;
}) {
const { isPublication, isDocument } = classifyAtUri(atURI);
// Show publication icon, or service-provided icon
const iconSrc =
isPublication || isDocument
? `/api/pub_icon?at_uri=${encodeURIComponent(atURI)}`
: iconUrl ?? null;
const icon = iconSrc ? (
) : null;
const linkHref = href || atUriToUrl(atURI);
return (
{icon}
{children}
);
}