import * as React from 'react' import { motion } from 'framer-motion' import * as ContextMenuPrimitive from '@radix-ui/react-context-menu' import { cva, type VariantProps } from 'class-variance-authority' import { cn } from '@/lib/utils' import { MOTION_SCALE_IN } from '@/lib/motion' import { ArrowRightSLine, CheckLine } from './icons-inline' import { getThemeFromDocument } from './theme-from-document' const ContextMenu = ContextMenuPrimitive.Root const ContextMenuTrigger = ContextMenuPrimitive.Trigger const ContextMenuGroup = ContextMenuPrimitive.Group const ContextMenuPortal = ContextMenuPrimitive.Portal const ContextMenuSub = ContextMenuPrimitive.Sub const ContextMenuRadioGroup = ContextMenuPrimitive.RadioGroup const contentClasses = 'z-50 min-w-36 overflow-hidden rounded-lg border border-border-tertiary bg-bg-container p-1 text-text shadow-lg outline-none focus:outline-none focus:ring-0 focus-visible:outline-none focus-visible:ring-0 focus-visible:!outline-none focus-visible:!ring-0' export interface ContextMenuContentProps extends React.ComponentPropsWithoutRef { dataStyle?: string dataTheme?: string } const ContextMenuContent = React.forwardRef< React.ElementRef, ContextMenuContentProps >(({ className, children, dataStyle, dataTheme, ...props }, ref) => { const fromDoc = getThemeFromDocument() const dataProps = dataStyle !== undefined ? { 'data-style': dataStyle, 'data-theme': dataTheme ?? fromDoc['data-theme'] ?? '' } : fromDoc return (
{children}
) }) ContextMenuContent.displayName = ContextMenuPrimitive.Content.displayName const subTriggerVariants = cva( 'flex h-[var(--select-item-height)] w-full cursor-pointer select-none items-center gap-2 rounded-md px-[var(--select-item-padding-x)] text-[length:var(--control-font-size-md)] leading-[var(--control-line-height-md)] outline-none focus:outline-none focus:ring-0 focus-visible:outline-none focus-visible:ring-0 focus-visible:!outline-none focus-visible:!ring-0 hover:bg-fill-secondary focus:bg-fill-secondary data-[highlighted]:bg-fill-secondary data-[state=open]:bg-fill-secondary', { variants: { inset: { true: 'pl-8 pr-3', false: '' } }, defaultVariants: { inset: false }, }, ) const ContextMenuSubTrigger = React.forwardRef< React.ElementRef, React.ComponentPropsWithoutRef & VariantProps >(({ className, inset = false, children, ...props }, ref) => ( {children} )) ContextMenuSubTrigger.displayName = ContextMenuPrimitive.SubTrigger.displayName const ContextMenuSubContent = React.forwardRef< React.ElementRef, React.ComponentPropsWithoutRef & { dataStyle?: string dataTheme?: string } >(({ className, sideOffset = 4, dataStyle, dataTheme, ...props }, ref) => { const fromDoc = getThemeFromDocument() const dataProps = dataStyle !== undefined ? { 'data-style': dataStyle, 'data-theme': dataTheme ?? fromDoc['data-theme'] ?? '' } : fromDoc return (
) }) ContextMenuSubContent.displayName = ContextMenuPrimitive.SubContent.displayName const itemVariants = cva( 'relative flex h-[var(--select-item-height)] w-full min-w-0 cursor-pointer select-none items-center gap-2 rounded-md px-[var(--select-item-padding-x)] text-[length:var(--control-font-size-md)] leading-[var(--control-line-height-md)] outline-none focus:outline-none focus:ring-0 focus-visible:outline-none focus-visible:ring-0 focus-visible:!outline-none focus-visible:!ring-0 transition-colors data-[disabled]:pointer-events-none data-[disabled]:opacity-50', { variants: { variant: { default: 'hover:bg-fill-secondary focus:bg-fill-secondary focus:text-text data-[highlighted]:bg-fill-secondary data-[highlighted]:text-text', destructive: 'text-error hover:bg-error-bg focus:bg-error-bg focus:text-error data-[highlighted]:bg-error-bg data-[highlighted]:text-error', }, inset: { true: 'pl-8 pr-3', false: '' }, }, defaultVariants: { variant: 'default', inset: false }, }, ) const ContextMenuItem = React.forwardRef< React.ElementRef, React.ComponentPropsWithoutRef & VariantProps >(({ className, inset = false, variant = 'default', ...props }, ref) => ( )) ContextMenuItem.displayName = ContextMenuPrimitive.Item.displayName const itemIndicatorClasses = 'relative flex h-[var(--select-item-height)] w-full min-w-0 cursor-pointer select-none items-center gap-2 rounded-md pl-8 pr-2 text-[length:var(--control-font-size-md)] leading-[var(--control-line-height-md)] outline-none focus:outline-none focus:ring-0 focus-visible:outline-none focus-visible:ring-0 focus-visible:!outline-none focus-visible:!ring-0 hover:bg-fill-secondary focus:bg-fill-secondary focus:text-text data-[highlighted]:bg-fill-secondary data-[highlighted]:text-text data-[disabled]:pointer-events-none data-[disabled]:opacity-50' const ContextMenuCheckboxItem = React.forwardRef< React.ElementRef, React.ComponentPropsWithoutRef >(({ className, children, checked, ...rest }, ref) => ( {children} )) ContextMenuCheckboxItem.displayName = ContextMenuPrimitive.CheckboxItem.displayName const ContextMenuRadioItem = React.forwardRef< React.ElementRef, React.ComponentPropsWithoutRef >(({ className, children, ...props }, ref) => (
{children} )) ContextMenuRadioItem.displayName = ContextMenuPrimitive.RadioItem.displayName const labelVariants = cva( 'flex h-[var(--select-item-height)] items-center px-[var(--select-item-padding-x)] text-[length:var(--control-font-size-md)] leading-[var(--control-line-height-md)] font-semibold text-text-secondary', { variants: { inset: { true: 'pl-8 pr-3', false: '' } }, defaultVariants: { inset: false }, }, ) const ContextMenuLabel = React.forwardRef< React.ElementRef, React.ComponentPropsWithoutRef & VariantProps >(({ className, inset = false, ...props }, ref) => ( )) ContextMenuLabel.displayName = ContextMenuPrimitive.Label.displayName const ContextMenuSeparator = React.forwardRef< React.ElementRef, React.ComponentPropsWithoutRef >(({ className, ...props }, ref) => ( )) ContextMenuSeparator.displayName = ContextMenuPrimitive.Separator.displayName const ContextMenuShortcut: React.FC> = ({ className, ...props }) => ( ) ContextMenuShortcut.displayName = 'ContextMenuShortcut' export { ContextMenu, ContextMenuTrigger, ContextMenuContent, ContextMenuItem, ContextMenuCheckboxItem, ContextMenuRadioItem, ContextMenuLabel, ContextMenuSeparator, ContextMenuShortcut, ContextMenuGroup, ContextMenuPortal, ContextMenuSub, ContextMenuSubContent, ContextMenuSubTrigger, ContextMenuRadioGroup, }