{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "command-palette",
  "type": "registry:component",
  "title": "Command Palette",
  "description": "Canonical shared ⌘K/Ctrl+K command-palette overlay: a Dialog-wrapped, grouped Command list plus the fleet-wide keyboard-shortcut hook.",
  "registryDependencies": [
    "command",
    "dialog"
  ],
  "files": [
    {
      "path": "registry/blocks/command/command-palette.tsx",
      "content": "\"use client\";\n// astro-ui-m8-skin-version: 1.5.3 (A-C6 — run `npx astro-ui-m8-skin-lock` to compare against your installed @mano8/astro-ui-m8)\n\n// Canonical shared `⌘K` command-palette overlay for the M8 Astro plugin fleet\n// (`A-C4`). `cmdk` is already a declared `astro-ui-m8` peer (pulled in\n// transitively by shadcn's `command` primitive, which `data-table`'s faceted\n// filter already depends on) — this block is the first thing in the registry\n// that surfaces it as a standalone, host-level overlay rather than an inline\n// combobox.\n//\n// It composes the same two shadcn primitives every plugin already installs —\n// `@/components/ui/command` (the `cmdk` wrapper) and `@/components/ui/dialog`\n// — rather than importing `cmdk` directly, so a host never carries two\n// competing copies of the same filtering/keyboard-nav logic.\n\nimport * as React from \"react\";\n\nimport {\n  Command,\n  CommandEmpty,\n  CommandGroup,\n  CommandInput,\n  CommandItem,\n  CommandList,\n  CommandSeparator,\n} from \"@/components/ui/command\";\nimport {\n  Dialog,\n  DialogContent,\n  DialogDescription,\n  DialogHeader,\n  DialogTitle,\n} from \"@/components/ui/dialog\";\n\nexport interface CommandPaletteItem {\n  id: string;\n  label: string;\n  description?: string;\n  shortcut?: string;\n  /** Extra terms matched by `cmdk`'s built-in filter alongside `label`. */\n  keywords?: string[];\n  onSelect: () => void;\n}\n\nexport interface CommandPaletteGroup {\n  heading: string;\n  items: CommandPaletteItem[];\n}\n\nexport interface CommandPaletteProps {\n  groups: CommandPaletteGroup[];\n  open: boolean;\n  onOpenChange: (open: boolean) => void;\n  placeholder?: string;\n  emptyLabel?: string;\n  /** Dialog title/description. Rendered visually hidden (`sr-only`) — the\n   * overlay's own input is the visible affordance, same as shadcn's own\n   * `CommandDialog` recipe. */\n  title?: string;\n  description?: string;\n}\n\n/**\n * Fleet-wide `⌘K` / `Ctrl+K` listener. Exported separately from\n * `CommandPalette` so a host that drives `open` from more than one trigger\n * (a header button, a route) can register the shortcut once at whatever level\n * makes sense, rather than being forced through the dialog component itself.\n *\n * `⌘K`/`Ctrl+K` is not a native editing shortcut in any browser, so — unlike a\n * bare single-key shortcut — it is honoured even while focus sits in a text\n * field; there is deliberately no \"editable target\" guard to work around.\n */\nexport function useCommandPaletteShortcut(\n  onToggle: () => void,\n  options: { disabled?: boolean } = {},\n): void {\n  const { disabled = false } = options;\n  React.useEffect(() => {\n    if (disabled) return;\n    function handleKeyDown(event: KeyboardEvent): void {\n      if (event.key.toLowerCase() !== \"k\") return;\n      if (!(event.metaKey || event.ctrlKey)) return;\n      event.preventDefault();\n      onToggle();\n    }\n    document.addEventListener(\"keydown\", handleKeyDown);\n    return () => document.removeEventListener(\"keydown\", handleKeyDown);\n  }, [onToggle, disabled]);\n}\n\nexport function CommandPalette({\n  groups,\n  open,\n  onOpenChange,\n  placeholder = \"Type a command or search…\",\n  emptyLabel = \"No results found.\",\n  title = \"Command palette\",\n  description = \"Search commands and jump to an action.\",\n}: CommandPaletteProps) {\n  const runCommand = React.useCallback(\n    (action: () => void) => {\n      onOpenChange(false);\n      action();\n    },\n    [onOpenChange],\n  );\n\n  return (\n    <Dialog open={open} onOpenChange={onOpenChange}>\n      <DialogContent\n        data-m8-command-palette=\"dialog\"\n        className=\"overflow-hidden p-0 shadow-lg\"\n      >\n        <DialogHeader className=\"sr-only\">\n          <DialogTitle>{title}</DialogTitle>\n          <DialogDescription>{description}</DialogDescription>\n        </DialogHeader>\n        <Command shouldFilter data-m8-command-palette=\"command\">\n          <CommandInput placeholder={placeholder} autoFocus />\n          <CommandList>\n            <CommandEmpty>{emptyLabel}</CommandEmpty>\n            {groups.map((group, index) => (\n              <React.Fragment key={group.heading}>\n                {index > 0 ? <CommandSeparator /> : null}\n                <CommandGroup heading={group.heading}>\n                  {group.items.map((item) => (\n                    <CommandItem\n                      key={item.id}\n                      value={[item.label, ...(item.keywords ?? [])].join(\" \")}\n                      onSelect={() => runCommand(item.onSelect)}\n                    >\n                      <div className=\"flex flex-1 flex-col\">\n                        <span>{item.label}</span>\n                        {item.description ? (\n                          <span className=\"text-xs opacity-60\">{item.description}</span>\n                        ) : null}\n                      </div>\n                      {item.shortcut ? (\n                        <span className=\"ml-auto text-xs tracking-widest opacity-60\">\n                          {item.shortcut}\n                        </span>\n                      ) : null}\n                    </CommandItem>\n                  ))}\n                </CommandGroup>\n              </React.Fragment>\n            ))}\n          </CommandList>\n        </Command>\n      </DialogContent>\n    </Dialog>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/m8-ui/command-palette.tsx"
    }
  ]
}
