{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "context-menu",
  "type": "registry:ui",
  "title": "Context Menu",
  "description": "The context-menu primitive.",
  "dependencies": [],
  "registryDependencies": [
    "https://ui.klarhimmel.com/r/menu.json",
    "https://ui.klarhimmel.com/r/theme.json",
    "https://ui.klarhimmel.com/r/utils.json"
  ],
  "files": [
    {
      "path": "src/ui/context-menu.tsx",
      "type": "registry:file",
      "target": "components/klarhimmel/ui/context-menu.tsx",
      "content": "import { useEffect, useRef, useState, type KeyboardEvent, type MouseEvent, type ReactNode } from 'react';\nimport { cn } from '../lib/utils';\nimport { Menu, MenuContent, MenuTrigger } from './menu';\n\nexport interface ContextMenuProps {\n  /** Required: names the area. It is a tab stop, so keyboard users can reach the menu too. */\n  'aria-label': string;\n  /** What the area shows. */\n  children: ReactNode;\n  /** The menu: MenuItem, MenuLabel, MenuSeparator... from Menu. */\n  menu: ReactNode;\n  className?: string;\n}\n\n/**\n * The menu that opens where you right-click, and from the keyboard with the Menu key or Shift+F10 (at the focused element). It uses the\n * same Menu as a button's menu, so arrows, Home and End, type-ahead, Escape and focus return are the same. Focus goes back to the area\n * when it closes. A touch screen has no right-click: always offer the same actions another way (a visible button).\n */\nexport function ContextMenu({ children, menu, className, ...aria }: ContextMenuProps) {\n  const [at, setAt] = useState<{ x: number; y: number } | null>(null);\n  const area = useRef<HTMLDivElement>(null);\n  const was = useRef(false);\n  useEffect(() => {\n    if (at) was.current = true;\n    else if (was.current) {\n      was.current = false;\n      area.current?.focus();\n    }\n  }, [at]);\n  const onContext = (e: MouseEvent) => {\n    e.preventDefault();\n    setAt({ x: e.clientX, y: e.clientY });\n  };\n  const onKey = (e: KeyboardEvent) => {\n    if (e.key === 'ContextMenu' || (e.shiftKey && e.key === 'F10')) {\n      e.preventDefault();\n      const r = (e.target as HTMLElement).getBoundingClientRect();\n      setAt({ x: r.left, y: r.bottom });\n    }\n  };\n  return (\n    <div ref={area} role=\"group\" tabIndex={0} onContextMenu={onContext} onKeyDown={onKey} className={cn('rounded-kh focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-(--kh-focus)', className)} {...aria}>\n      {children}\n      <Menu open={at !== null} onOpenChange={(o) => !o && setAt(null)}>\n        {at && (\n          <MenuTrigger asChild>\n            {/* A one-pixel anchor at the pointer. It exists only while the menu is open, so the server-rendered HTML has no style. */}\n            <span aria-hidden tabIndex={-1} className=\"pointer-events-none fixed size-px\" style={{ left: at.x, top: at.y }} />\n          </MenuTrigger>\n        )}\n        <MenuContent align=\"start\">{menu}</MenuContent>\n      </Menu>\n    </div>\n  );\n}\n"
    }
  ]
}
