{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "context-menu",
  "title": "Context menu",
  "description": "A right-click menu on Base UI ContextMenu that reuses the dropdown menu rows.",
  "dependencies": [
    "@base-ui/react@^1.7.0"
  ],
  "registryDependencies": [
    "@khaeli/dropdown-menu",
    "@khaeli/utils"
  ],
  "files": [
    {
      "path": "registry/khaeli/ui/context-menu.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\nimport { ContextMenu as ContextMenuPrimitive } from \"@base-ui/react/context-menu\"\nimport { cn } from \"@/lib/utils\"\n\n/**\n * Right-click (and touch long-press) menus on Base UI's ContextMenu. The\n * popup reuses the dropdown menu's surface and rows — `data-slot` stays\n * \"dropdown-menu-content\" so foundation.css styles both alike, and the item parts\n * below are the dropdown's own (Base UI's ContextMenu items are Menu items).\n *\n * Only motion differs (foundation.css, \"Context menus\"): a pointer-opened menu\n * grows out of the pointer and fades out faster; one opened from the keyboard\n * (the context-menu key, Shift+F10) appears and leaves at once, so the popup\n * carries `data-open-method=\"pointer\" | \"touch\" | \"keyboard\"`.\n */\n\ntype OpenMethod = \"pointer\" | \"touch\" | \"keyboard\"\n\nconst OpenMethodContext = React.createContext<OpenMethod>(\"pointer\")\n\n/** How a `contextmenu` (or long-press touch) event was produced. */\nfunction openMethodOf(event: Event | undefined): OpenMethod {\n  if (!event) return \"pointer\"\n  if (typeof TouchEvent !== \"undefined\" && event instanceof TouchEvent) return \"touch\"\n  if (!(event instanceof MouseEvent)) return \"pointer\"\n  // Chromium dispatches contextmenu as a PointerEvent; the keyboard's has no pointer type.\n  if (typeof PointerEvent !== \"undefined\" && event instanceof PointerEvent) {\n    if (event.pointerType === \"\") return \"keyboard\"\n    return event.pointerType === \"touch\" ? \"touch\" : \"pointer\"\n  }\n  // Firefox marks keyboard-made mouse events; elsewhere a keyboard menu reports the primary button.\n  if ((event as MouseEvent & { mozInputSource?: number }).mozInputSource === 6) return \"keyboard\"\n  return event.button === 2 || event.ctrlKey ? \"pointer\" : \"keyboard\"\n}\n\nfunction ContextMenu({ onOpenChange, ...props }: ContextMenuPrimitive.Root.Props) {\n  const [method, setMethod] = React.useState<OpenMethod>(\"pointer\")\n  return (\n    <OpenMethodContext.Provider value={method}>\n      <ContextMenuPrimitive.Root\n        {...props}\n        onOpenChange={(open, details) => {\n          if (open) setMethod(openMethodOf(details.event))\n          onOpenChange?.(open, details)\n        }}\n      />\n    </OpenMethodContext.Provider>\n  )\n}\n\nfunction ContextMenuTrigger({ ...props }: ContextMenuPrimitive.Trigger.Props) {\n  return <ContextMenuPrimitive.Trigger data-slot=\"context-menu-trigger\" {...props} />\n}\n\nfunction ContextMenuContent({\n  className,\n  ...props\n}: ContextMenuPrimitive.Popup.Props) {\n  const method = React.useContext(OpenMethodContext)\n  return (\n    <ContextMenuPrimitive.Portal>\n      <ContextMenuPrimitive.Positioner className=\"isolate z-50 outline-none\">\n        <ContextMenuPrimitive.Popup\n          data-slot=\"dropdown-menu-content\"\n          data-context-menu=\"\"\n          data-open-method={method}\n          className={cn(\"z-50 max-h-(--available-height) min-w-48 origin-(--transform-origin) overflow-x-hidden overflow-y-auto rounded-lg p-1 text-popover-foreground shadow-md ring-1 ring-foreground/10 outline-none relative bg-popover **:data-[slot$=-item]:focus:bg-foreground/10 **:data-[slot$=-item]:data-highlighted:bg-foreground/10 **:data-[slot$=-separator]:bg-foreground/5 **:data-[slot$=-trigger]:focus:bg-foreground/10 **:data-[slot$=-trigger]:aria-expanded:bg-foreground/10! **:data-[variant=destructive]:focus:bg-foreground/10! **:data-[variant=destructive]:text-accent-foreground! **:data-[variant=destructive]:**:text-accent-foreground!\", className)}\n          {...props}\n        />\n      </ContextMenuPrimitive.Positioner>\n    </ContextMenuPrimitive.Portal>\n  )\n}\n\nexport { ContextMenu, ContextMenuTrigger, ContextMenuContent }\nexport {\n  DropdownMenuGroup as ContextMenuGroup,\n  DropdownMenuLabel as ContextMenuLabel,\n  DropdownMenuItem as ContextMenuItem,\n  DropdownMenuCheckboxItem as ContextMenuCheckboxItem,\n  DropdownMenuRadioGroup as ContextMenuRadioGroup,\n  DropdownMenuRadioItem as ContextMenuRadioItem,\n  DropdownMenuSeparator as ContextMenuSeparator,\n  DropdownMenuShortcut as ContextMenuShortcut,\n  DropdownMenuSub as ContextMenuSub,\n  DropdownMenuSubTrigger as ContextMenuSubTrigger,\n  DropdownMenuSubContent as ContextMenuSubContent,\n} from \"@/components/ui/dropdown-menu\"\n",
      "type": "registry:ui"
    }
  ],
  "docs": "Install @khaeli/foundation first: this item's styling lives in its tokens and [data-slot] rules.",
  "type": "registry:ui"
}