2025-09-21 12:03:29 +01:00
|
|
|
'use client';
|
2025-08-28 14:15:36 +01:00
|
|
|
|
2025-09-21 12:03:29 +01:00
|
|
|
import { Badge } from '@/components/ui/badge';
|
2025-08-28 14:15:36 +01:00
|
|
|
import {
|
|
|
|
|
Carousel,
|
|
|
|
|
CarouselContent,
|
|
|
|
|
CarouselItem,
|
2025-09-21 12:03:29 +01:00
|
|
|
type CarouselApi,
|
|
|
|
|
} from '@/components/ui/carousel';
|
2025-08-28 14:15:36 +01:00
|
|
|
import {
|
|
|
|
|
HoverCard,
|
|
|
|
|
HoverCardContent,
|
|
|
|
|
HoverCardTrigger,
|
2025-09-21 12:03:29 +01:00
|
|
|
} from '@/components/ui/hover-card';
|
|
|
|
|
import { cn } from '@/lib/utils';
|
|
|
|
|
import { ArrowLeftIcon, ArrowRightIcon } from 'lucide-react';
|
|
|
|
|
import {
|
|
|
|
|
type ComponentProps,
|
|
|
|
|
createContext,
|
|
|
|
|
useCallback,
|
|
|
|
|
useContext,
|
|
|
|
|
useEffect,
|
|
|
|
|
useState,
|
|
|
|
|
} from 'react';
|
2025-08-28 14:15:36 +01:00
|
|
|
|
2025-09-21 12:03:29 +01:00
|
|
|
export type InlineCitationProps = ComponentProps<'span'>;
|
2025-08-28 14:15:36 +01:00
|
|
|
|
|
|
|
|
export const InlineCitation = ({
|
|
|
|
|
className,
|
|
|
|
|
...props
|
|
|
|
|
}: InlineCitationProps) => (
|
|
|
|
|
<span
|
2025-09-21 12:03:29 +01:00
|
|
|
className={cn('group inline items-center gap-1', className)}
|
2025-08-28 14:15:36 +01:00
|
|
|
{...props}
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
|
2025-09-21 12:03:29 +01:00
|
|
|
export type InlineCitationTextProps = ComponentProps<'span'>;
|
2025-08-28 14:15:36 +01:00
|
|
|
|
|
|
|
|
export const InlineCitationText = ({
|
|
|
|
|
className,
|
|
|
|
|
...props
|
|
|
|
|
}: InlineCitationTextProps) => (
|
|
|
|
|
<span
|
2025-09-21 12:03:29 +01:00
|
|
|
className={cn('transition-colors group-hover:bg-accent', className)}
|
2025-08-28 14:15:36 +01:00
|
|
|
{...props}
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
export type InlineCitationCardProps = ComponentProps<typeof HoverCard>;
|
|
|
|
|
|
|
|
|
|
export const InlineCitationCard = (props: InlineCitationCardProps) => (
|
|
|
|
|
<HoverCard closeDelay={0} openDelay={0} {...props} />
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
export type InlineCitationCardTriggerProps = ComponentProps<typeof Badge> & {
|
|
|
|
|
sources: string[];
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const InlineCitationCardTrigger = ({
|
|
|
|
|
sources,
|
|
|
|
|
className,
|
|
|
|
|
...props
|
|
|
|
|
}: InlineCitationCardTriggerProps) => (
|
|
|
|
|
<HoverCardTrigger asChild>
|
|
|
|
|
<Badge
|
2025-09-21 12:03:29 +01:00
|
|
|
className={cn('ml-1 rounded-full', className)}
|
2025-08-28 14:15:36 +01:00
|
|
|
variant="secondary"
|
|
|
|
|
{...props}
|
|
|
|
|
>
|
|
|
|
|
{sources.length ? (
|
|
|
|
|
<>
|
2025-09-21 12:03:29 +01:00
|
|
|
{new URL(sources[0]).hostname}{' '}
|
2025-08-28 14:15:36 +01:00
|
|
|
{sources.length > 1 && `+${sources.length - 1}`}
|
|
|
|
|
</>
|
|
|
|
|
) : (
|
2025-09-21 12:03:29 +01:00
|
|
|
'unknown'
|
2025-08-28 14:15:36 +01:00
|
|
|
)}
|
|
|
|
|
</Badge>
|
|
|
|
|
</HoverCardTrigger>
|
|
|
|
|
);
|
|
|
|
|
|
2025-09-21 12:03:29 +01:00
|
|
|
export type InlineCitationCardBodyProps = ComponentProps<'div'>;
|
2025-08-28 14:15:36 +01:00
|
|
|
|
|
|
|
|
export const InlineCitationCardBody = ({
|
|
|
|
|
className,
|
|
|
|
|
...props
|
|
|
|
|
}: InlineCitationCardBodyProps) => (
|
2025-09-21 12:03:29 +01:00
|
|
|
<HoverCardContent className={cn('relative w-80 p-0', className)} {...props} />
|
2025-08-28 14:15:36 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const CarouselApiContext = createContext<CarouselApi | undefined>(undefined);
|
|
|
|
|
|
|
|
|
|
const useCarouselApi = () => {
|
|
|
|
|
const context = useContext(CarouselApiContext);
|
|
|
|
|
return context;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export type InlineCitationCarouselProps = ComponentProps<typeof Carousel>;
|
|
|
|
|
|
|
|
|
|
export const InlineCitationCarousel = ({
|
|
|
|
|
className,
|
|
|
|
|
children,
|
|
|
|
|
...props
|
|
|
|
|
}: InlineCitationCarouselProps) => {
|
|
|
|
|
const [api, setApi] = useState<CarouselApi>();
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<CarouselApiContext.Provider value={api}>
|
2025-09-21 12:03:29 +01:00
|
|
|
<Carousel className={cn('w-full', className)} setApi={setApi} {...props}>
|
2025-08-28 14:15:36 +01:00
|
|
|
{children}
|
|
|
|
|
</Carousel>
|
|
|
|
|
</CarouselApiContext.Provider>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
2025-09-21 12:03:29 +01:00
|
|
|
export type InlineCitationCarouselContentProps = ComponentProps<'div'>;
|
2025-08-28 14:15:36 +01:00
|
|
|
|
|
|
|
|
export const InlineCitationCarouselContent = (
|
2025-09-21 12:03:29 +01:00
|
|
|
props: InlineCitationCarouselContentProps,
|
2025-08-28 14:15:36 +01:00
|
|
|
) => <CarouselContent {...props} />;
|
|
|
|
|
|
2025-09-21 12:03:29 +01:00
|
|
|
export type InlineCitationCarouselItemProps = ComponentProps<'div'>;
|
2025-08-28 14:15:36 +01:00
|
|
|
|
|
|
|
|
export const InlineCitationCarouselItem = ({
|
|
|
|
|
className,
|
|
|
|
|
...props
|
|
|
|
|
}: InlineCitationCarouselItemProps) => (
|
|
|
|
|
<CarouselItem
|
2025-09-21 12:03:29 +01:00
|
|
|
className={cn('w-full space-y-2 p-4 pl-8', className)}
|
2025-08-28 14:15:36 +01:00
|
|
|
{...props}
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
|
2025-09-21 12:03:29 +01:00
|
|
|
export type InlineCitationCarouselHeaderProps = ComponentProps<'div'>;
|
2025-08-28 14:15:36 +01:00
|
|
|
|
|
|
|
|
export const InlineCitationCarouselHeader = ({
|
|
|
|
|
className,
|
|
|
|
|
...props
|
|
|
|
|
}: InlineCitationCarouselHeaderProps) => (
|
|
|
|
|
<div
|
|
|
|
|
className={cn(
|
2025-09-21 12:03:29 +01:00
|
|
|
'flex items-center justify-between gap-2 rounded-t-md bg-secondary p-2',
|
|
|
|
|
className,
|
2025-08-28 14:15:36 +01:00
|
|
|
)}
|
|
|
|
|
{...props}
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
|
2025-09-21 12:03:29 +01:00
|
|
|
export type InlineCitationCarouselIndexProps = ComponentProps<'div'>;
|
2025-08-28 14:15:36 +01:00
|
|
|
|
|
|
|
|
export const InlineCitationCarouselIndex = ({
|
|
|
|
|
children,
|
|
|
|
|
className,
|
|
|
|
|
...props
|
|
|
|
|
}: InlineCitationCarouselIndexProps) => {
|
|
|
|
|
const api = useCarouselApi();
|
|
|
|
|
const [current, setCurrent] = useState(0);
|
|
|
|
|
const [count, setCount] = useState(0);
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
if (!api) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setCount(api.scrollSnapList().length);
|
|
|
|
|
setCurrent(api.selectedScrollSnap() + 1);
|
|
|
|
|
|
2025-09-21 12:03:29 +01:00
|
|
|
api.on('select', () => {
|
2025-08-28 14:15:36 +01:00
|
|
|
setCurrent(api.selectedScrollSnap() + 1);
|
|
|
|
|
});
|
|
|
|
|
}, [api]);
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div
|
|
|
|
|
className={cn(
|
2025-09-21 12:03:29 +01:00
|
|
|
'flex flex-1 items-center justify-end px-3 py-1 text-muted-foreground text-xs',
|
|
|
|
|
className,
|
2025-08-28 14:15:36 +01:00
|
|
|
)}
|
|
|
|
|
{...props}
|
|
|
|
|
>
|
|
|
|
|
{children ?? `${current}/${count}`}
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
2025-09-21 12:03:29 +01:00
|
|
|
export type InlineCitationCarouselPrevProps = ComponentProps<'button'>;
|
2025-08-28 14:15:36 +01:00
|
|
|
|
|
|
|
|
export const InlineCitationCarouselPrev = ({
|
|
|
|
|
className,
|
|
|
|
|
...props
|
|
|
|
|
}: InlineCitationCarouselPrevProps) => {
|
|
|
|
|
const api = useCarouselApi();
|
|
|
|
|
|
|
|
|
|
const handleClick = useCallback(() => {
|
|
|
|
|
if (api) {
|
|
|
|
|
api.scrollPrev();
|
|
|
|
|
}
|
|
|
|
|
}, [api]);
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<button
|
|
|
|
|
aria-label="Previous"
|
2025-09-21 12:03:29 +01:00
|
|
|
className={cn('shrink-0', className)}
|
2025-08-28 14:15:36 +01:00
|
|
|
onClick={handleClick}
|
|
|
|
|
type="button"
|
|
|
|
|
{...props}
|
|
|
|
|
>
|
|
|
|
|
<ArrowLeftIcon className="size-4 text-muted-foreground" />
|
|
|
|
|
</button>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
2025-09-21 12:03:29 +01:00
|
|
|
export type InlineCitationCarouselNextProps = ComponentProps<'button'>;
|
2025-08-28 14:15:36 +01:00
|
|
|
|
|
|
|
|
export const InlineCitationCarouselNext = ({
|
|
|
|
|
className,
|
|
|
|
|
...props
|
|
|
|
|
}: InlineCitationCarouselNextProps) => {
|
|
|
|
|
const api = useCarouselApi();
|
|
|
|
|
|
|
|
|
|
const handleClick = useCallback(() => {
|
|
|
|
|
if (api) {
|
|
|
|
|
api.scrollNext();
|
|
|
|
|
}
|
|
|
|
|
}, [api]);
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<button
|
|
|
|
|
aria-label="Next"
|
2025-09-21 12:03:29 +01:00
|
|
|
className={cn('shrink-0', className)}
|
2025-08-28 14:15:36 +01:00
|
|
|
onClick={handleClick}
|
|
|
|
|
type="button"
|
|
|
|
|
{...props}
|
|
|
|
|
>
|
|
|
|
|
<ArrowRightIcon className="size-4 text-muted-foreground" />
|
|
|
|
|
</button>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
2025-09-21 12:03:29 +01:00
|
|
|
export type InlineCitationSourceProps = ComponentProps<'div'> & {
|
2025-08-28 14:15:36 +01:00
|
|
|
title?: string;
|
|
|
|
|
url?: string;
|
|
|
|
|
description?: string;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const InlineCitationSource = ({
|
|
|
|
|
title,
|
|
|
|
|
url,
|
|
|
|
|
description,
|
|
|
|
|
className,
|
|
|
|
|
children,
|
|
|
|
|
...props
|
|
|
|
|
}: InlineCitationSourceProps) => (
|
2025-09-21 12:03:29 +01:00
|
|
|
<div className={cn('space-y-1', className)} {...props}>
|
2025-08-28 14:15:36 +01:00
|
|
|
{title && (
|
|
|
|
|
<h4 className="truncate font-medium text-sm leading-tight">{title}</h4>
|
|
|
|
|
)}
|
|
|
|
|
{url && (
|
|
|
|
|
<p className="truncate break-all text-muted-foreground text-xs">{url}</p>
|
|
|
|
|
)}
|
|
|
|
|
{description && (
|
|
|
|
|
<p className="line-clamp-3 text-muted-foreground text-sm leading-relaxed">
|
|
|
|
|
{description}
|
|
|
|
|
</p>
|
|
|
|
|
)}
|
|
|
|
|
{children}
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
|
2025-09-21 12:03:29 +01:00
|
|
|
export type InlineCitationQuoteProps = ComponentProps<'blockquote'>;
|
2025-08-28 14:15:36 +01:00
|
|
|
|
|
|
|
|
export const InlineCitationQuote = ({
|
|
|
|
|
children,
|
|
|
|
|
className,
|
|
|
|
|
...props
|
|
|
|
|
}: InlineCitationQuoteProps) => (
|
|
|
|
|
<blockquote
|
|
|
|
|
className={cn(
|
2025-09-21 12:03:29 +01:00
|
|
|
'border-muted border-l-2 pl-3 text-muted-foreground text-sm italic',
|
|
|
|
|
className,
|
2025-08-28 14:15:36 +01:00
|
|
|
)}
|
|
|
|
|
{...props}
|
|
|
|
|
>
|
|
|
|
|
{children}
|
|
|
|
|
</blockquote>
|
|
|
|
|
);
|