{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "command-palette",
  "title": "Command palette",
  "description": "A searchable list of commands behind a prompt, in a dialog.",
  "dependencies": [
    "@ui-sdk/react@0.1.0-beta.5",
    "lucide-react@1.73.0"
  ],
  "registryDependencies": [
    "https://www.cyberspec.dev/r/cyber.json",
    "https://www.cyberspec.dev/r/button.json",
    "https://www.cyberspec.dev/r/dialog.json"
  ],
  "files": [
    {
      "path": "registry/cyber/ui/command-palette.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\nimport {\n  Command,\n  CommandEmpty,\n  CommandGroup,\n  CommandGroupLabel,\n  CommandInput,\n  CommandItem,\n  CommandItemIcon,\n  CommandItemText,\n  CommandList,\n  CommandSeparator,\n  CommandShortcut,\n  CommandStatus,\n  type CommandActionDetails,\n  type CommandData,\n} from \"@ui-sdk/react/command\"\nimport {\n  Dialog,\n  DialogBackdrop,\n  DialogClose,\n  DialogContent,\n  DialogShortcut,\n  DialogTitle,\n  DialogTrigger,\n  createDialogController,\n} from \"@ui-sdk/react/dialog\"\nimport { Terminal } from \"lucide-react\"\nimport type { ButtonTone } from \"@/registry/cyber/ui/button\"\nimport \"@/registry/cyber/ui/cyber/button.css\"\nimport \"@/registry/cyber/ui/cyber/dialog.css\"\nimport \"@/registry/cyber/ui/cyber/command-palette.css\"\n\ntype PaletteCommand = {\n  value: string\n  label: string\n  icon?: React.ReactNode\n  shortcut?: string\n  keywords?: string[]\n  disabled?: boolean\n  confirm?: string\n}\ntype PaletteGroup = { label: string; commands: PaletteCommand[] }\n\nconst isGroup = (entry: PaletteCommand | PaletteGroup): entry is PaletteGroup => \"commands\" in entry\n\n// A shell prompt over the page: a key (and Ctrl or Cmd+K) opens it, typing\n// after the \">\" narrows the commands, and Enter runs the lit one and closes\n// it. The foot counts what's left, which is also what a screen reader hears.\n//\n// - `commands` are flat, or grouped as `{ label, commands }`. A command's\n//   `shortcut` (\"mod+shift+s\") runs it while the palette is open, and\n//   `confirm` is a sentence saying what it does, for one an agent must ask a\n//   person about first.\n// - `onAction` gets the value of the command that ran. Return a Promise to\n//   keep the palette open, with the command pending, until it settles.\n// - `trigger` labels the key and `title` names the palette. `shortcut` opens\n//   it from anywhere on the page; pass null for none.\n// - Everything else goes to the SDK's Dialog: `open`, `onOpenChange`,\n//   `controller`.\nfunction CommandPalette({\n  trigger = \"Commands\",\n  triggerIcon = <Terminal aria-hidden />,\n  triggerTone = \"secondary\",\n  title = \"Command palette\",\n  placeholder = \"Run a command\",\n  empty = \"No such command.\",\n  shortcut = \"mod+k\",\n  commands,\n  rankResults = false,\n  onAction,\n  code = \"CS-07 // SHELL\",\n  controller,\n  ...props\n}: Omit<React.ComponentProps<typeof Dialog>, \"children\"> & {\n  trigger?: React.ReactNode\n  triggerIcon?: React.ReactNode\n  triggerTone?: ButtonTone\n  title?: string\n  placeholder?: string\n  empty?: string\n  shortcut?: string | null\n  commands: (PaletteCommand | PaletteGroup)[]\n  /** Keep the opening groups, then rank matches across every group as the user types. */\n  rankResults?: boolean\n  onAction?: (value: string, details: CommandActionDetails) => unknown\n  code?: string\n}) {\n  // Closing goes through a controller, so the dialog can stay uncontrolled\n  // and still be shut by a command running.\n  const [own] = React.useState(() => createDialogController())\n  const dialog = controller ?? own\n\n  const list = React.useMemo(() => {\n    const byValue = new Map<string, { command: PaletteCommand; group?: string }>()\n    const item = (command: PaletteCommand, group?: string) => {\n      byValue.set(command.value, { command, group })\n      const { value, label, keywords, disabled, shortcut } = command\n      return { value, label, keywords, disabled, shortcut }\n    }\n    const grouped = commands.map((entry) =>\n      isGroup(entry)\n        ? { type: \"group\" as const, label: entry.label, items: entry.commands.map((command) => item(command, entry.label)) }\n        : item(entry),\n    )\n    const flat = grouped.flatMap((entry) => \"items\" in entry ? entry.items : [entry])\n    return { grouped, flat, byValue }\n  }, [commands])\n\n  const row = (command: PaletteCommand, group?: string) => (\n    <CommandItem\n      key={command.value}\n      value={command.value}\n      label={command.label}\n      keywords={command.keywords}\n      disabled={command.disabled}\n      shortcut={command.shortcut}\n      data-kit=\"popup-item\"\n      data-agent-confirm={command.confirm}\n    >\n      <CommandItemIcon data-kit=\"command-palette-icon\">{command.icon}</CommandItemIcon>\n      <CommandItemText data-kit=\"command-palette-text\">\n        {(text) =>\n          text.segments.map((segment, index) =>\n            segment.match ? (\n              <mark key={index} data-kit=\"command-palette-match\">\n                {segment.text}\n              </mark>\n            ) : (\n              segment.text\n            ),\n          )\n        }\n      </CommandItemText>\n      {group && <span data-kit=\"popup-shortcut\">{group}</span>}\n      {command.shortcut && <CommandShortcut data-kit=\"popup-shortcut\" />}\n    </CommandItem>\n  )\n\n  const renderEntry = (entry: CommandData[number], index: number, showGroup: boolean): React.ReactNode => {\n    if (typeof entry !== \"string\" && \"type\" in entry) {\n      if (entry.type === \"separator\") return <CommandSeparator key={index} data-kit=\"popup-separator\" />\n      return (\n        <React.Fragment key={entry.label}>\n          {index > 0 && <CommandSeparator data-kit=\"popup-separator\" />}\n          <CommandGroup data-kit=\"command-palette-group\">\n            <CommandGroupLabel data-kit=\"popup-label\">{entry.label}</CommandGroupLabel>\n            {entry.items.map((child, i) => renderEntry(child, i, false))}\n          </CommandGroup>\n        </React.Fragment>\n      )\n    }\n    const found = list.byValue.get(typeof entry === \"string\" ? entry : entry.value)\n    return found && row(found.command, showGroup ? found.group : undefined)\n  }\n\n  return (\n    <Dialog controller={dialog} {...props}>\n      <DialogTrigger\n        data-kit=\"button\"\n        data-frame=\"notch br\"\n        data-press-flash=\"\"\n        data-tone={triggerTone}\n        shortcut={shortcut ?? undefined}\n      >\n        {triggerIcon}\n        {trigger}\n        {shortcut && <DialogShortcut data-kit=\"command-palette-kbd\" />}\n      </DialogTrigger>\n      <DialogBackdrop data-kit=\"backdrop\" />\n      <DialogContent data-kit=\"command-palette\">\n        <span data-micro aria-hidden>\n          {code}\n        </span>\n        <div data-kit=\"command-palette-surface\" data-frame=\"tr bl\">\n          <DialogTitle data-sr-only>{title}</DialogTitle>\n          <Command\n            data-kit=\"command-palette-command\"\n            items={rankResults ? list.flat : undefined}\n            emptyItems={rankResults ? list.grouped : undefined}\n            onAction={(value, details) => {\n              const result = onAction?.(value, details)\n              if (result instanceof Promise) return result.then(() => void dialog.close())\n              dialog.close()\n            }}\n          >\n            {/* Arrow keys keep focus in the input. The prompt line shows\n                which field is receiving keystrokes. */}\n            <div data-kit=\"command-palette-prompt\">\n              <span data-kit=\"command-palette-glyph\" aria-hidden>\n                &gt;\n              </span>\n              <CommandInput aria-label={title} placeholder={placeholder} spellCheck={false} data-focus-quiet=\"\" />\n              <DialogClose data-kit=\"command-palette-key\">\n                Esc<span data-sr-only> — Close palette</span>\n              </DialogClose>\n            </div>\n            <CommandEmpty data-kit=\"command-palette-empty\">\n              <div data-kit=\"popup-empty\">{empty}</div>\n            </CommandEmpty>\n            <CommandList data-kit=\"command-palette-list\">\n              {({ items }) => (rankResults ? items : list.grouped).map((entry, i) => renderEntry(entry, i, rankResults))}\n            </CommandList>\n            <div data-kit=\"command-palette-foot\">\n              <CommandStatus data-kit=\"command-palette-status\">\n                {(state) =>\n                  state.count > 0 && (\n                    <>\n                      <span data-kit=\"value\">{String(state.count).padStart(2, \"0\")}</span>{\" \"}\n                      {state.count === 1 ? \"command\" : \"commands\"}\n                    </>\n                  )\n                }\n              </CommandStatus>\n              <span data-kit=\"command-palette-hints\" aria-hidden>\n                <kbd data-kit=\"command-palette-key\">↑↓</kbd> Move\n                <kbd data-kit=\"command-palette-key\">↵</kbd> Run\n              </span>\n            </div>\n          </Command>\n        </div>\n      </DialogContent>\n    </Dialog>\n  )\n}\n\nexport { CommandPalette }\nexport type { PaletteCommand, PaletteGroup }\n",
      "type": "registry:ui",
      "target": "@ui/command-palette.tsx"
    },
    {
      "path": "registry/cyber/ui/cyber/command-palette.css",
      "content": "@layer ui-sdk, cyber.tokens, cyber.base, cyber.ui, cyber.blocks, cyber.fx, cyber.a11y;\n\n/* The key is the shared button, the page behind is the dialog's backdrop and\n   the rows are the shared popup's (button.css, dialog.css, popup.css); this\n   is the palette's own frame, its prompt line and its foot. */\n@layer cyber.ui {\n  /* The chip on the key that prints its shortcut. */\n  [data-skin=\"cyber\"] [data-kit=\"command-palette-kbd\"] {\n    margin-inline: 2px -6px;\n    padding: 2px 5px;\n    border: 1px solid var(--cy-line-deco);\n    font-family: var(--cy-mono);\n    font-size: 10px;\n    font-weight: 400;\n    letter-spacing: 0;\n    line-height: 1.2;\n    text-transform: none;\n    color: var(--cy-ink-mute);\n\n    &:empty {\n      display: none;\n    }\n\n    :is([data-open], :active) > & {\n      border-color: var(--cy-line-ctl);\n      color: var(--cy-ink-hi);\n    }\n  }\n\n  /* The palette is a column: a line of micro-print, then the frame. It hangs\n     from a fixed point near the top rather than centering, so the prompt\n     stays put while the list under it grows and shrinks. */\n  [data-skin=\"cyber\"] [data-kit=\"command-palette\"] {\n    --top: clamp(16px, 14dvh, 120px);\n\n    position: fixed;\n    inset-block: var(--top) auto;\n    inset-inline: 0;\n    margin: 0 auto;\n    display: flex;\n    flex-direction: column;\n    gap: 6px;\n    width: min(520px, calc(100vw - 32px));\n    max-height: calc(100dvh - var(--top) - 16px);\n\n    &[data-open] {\n      animation: var(--cy-fx-in) 240ms var(--cy-ease-snap) backwards;\n    }\n    &[data-ending-style] {\n      animation: var(--cy-fx-out) 130ms var(--cy-ease-snap) both;\n    }\n  }\n\n  [data-skin=\"cyber\"] [data-kit=\"command-palette-surface\"] {\n    --frame-cut: var(--cy-cut);\n    --frame-line: var(--cy-line-hot);\n    --frame-fill: var(--cy-panel);\n    /* The prompt line's tint. It's painted by the frame, under its edges,\n       because a background on the prompt itself would cover the cut corner's\n       stroke. */\n    --frame-image: linear-gradient(to bottom, var(--cy-fill-hover) 0 48px, transparent 48px);\n\n    display: flex;\n    flex-direction: column;\n    min-height: 0;\n  }\n\n  [data-skin=\"cyber\"] [data-kit=\"command-palette-command\"] {\n    display: flex;\n    flex-direction: column;\n    min-height: 0;\n  }\n\n  /* The prompt: a \">\" in the signal color, the search text, and the key that\n     leaves. Its rule lights while the input has keyboard focus. */\n  [data-skin=\"cyber\"] [data-kit=\"command-palette-prompt\"] {\n    flex: none;\n    display: flex;\n    align-items: center;\n    gap: 10px;\n    height: 48px;\n    padding-inline: 16px 22px;\n    border-block-end: 1px solid var(--cy-line-deco);\n    transition: border-color var(--cy-t-fast) linear;\n\n    &:has(:focus-visible) {\n      border-block-end-color: var(--cy-signal);\n      box-shadow: inset 0 -1px 0 var(--cy-signal);\n    }\n\n    & input {\n      flex: 1;\n      min-width: 0;\n      height: 46px;\n      padding: 0;\n      border: 0;\n      background: none;\n      font-size: var(--cy-text-lg);\n      font-weight: 500;\n      color: var(--cy-ink-hi);\n      caret-color: var(--cy-signal);\n      outline: none;\n\n      &::placeholder {\n        color: var(--cy-ink-mute);\n        opacity: 1;\n      }\n    }\n  }\n\n  [data-skin=\"cyber\"] [data-kit=\"command-palette-glyph\"] {\n    flex: none;\n    font-family: var(--cy-mono);\n    font-size: var(--cy-text-lg);\n    font-weight: 700;\n    line-height: 1;\n    color: var(--cy-signal);\n\n    &:dir(rtl) {\n      scale: -1 1;\n    }\n  }\n\n  /* A key cap, for the hints in the prompt and the foot. */\n  [data-skin=\"cyber\"] [data-kit=\"command-palette-key\"] {\n    flex: none;\n    padding: 1px 5px;\n    border: 1px solid var(--cy-line-deco);\n    font-family: var(--cy-mono);\n    font-size: 10px;\n    line-height: 1.4;\n    text-transform: uppercase;\n    color: var(--cy-ink-mute);\n  }\n\n  [data-skin=\"cyber\"] button[data-kit=\"command-palette-key\"] {\n    min-height: 24px;\n    background: transparent;\n    cursor: pointer;\n\n    &:hover {\n      border-color: var(--cy-line-ctl);\n      color: var(--cy-ink);\n    }\n  }\n\n  /* The empty part is a live region that stays in the page, so it's never\n     hidden: it has no height of its own until its line is put in it. */\n  [data-skin=\"cyber\"] [data-kit=\"command-palette-empty\"] {\n    padding-inline: 6px;\n  }\n\n  [data-skin=\"cyber\"] [data-kit=\"command-palette-list\"] {\n    flex: 1;\n    min-height: 0;\n    max-height: min(320px, 48dvh);\n    padding: 6px;\n    overflow-y: auto;\n    overscroll-behavior: contain;\n    scroll-padding-block: 6px;\n    font-size: var(--cy-text-sm);\n    outline: none;\n\n    &:empty {\n      display: none;\n    }\n\n    /* A command still running: a bar along the foot of its row. */\n    & [data-pending] {\n      cursor: progress;\n\n      &::after {\n        content: \"\";\n        position: absolute;\n        inset: auto 0 0 0;\n        height: 2px;\n        background: linear-gradient(90deg, transparent, var(--cy-signal) 50%, transparent) 0 0 / 300% 100% no-repeat;\n        animation: var(--cy-fx-sweep) 900ms linear infinite;\n      }\n    }\n  }\n\n  [data-skin=\"cyber\"] [data-kit=\"command-palette-group\"] {\n    display: grid;\n  }\n\n  /* Every row keeps an icon column, so names line up with or without one. */\n  [data-skin=\"cyber\"] [data-kit=\"command-palette-icon\"] {\n    flex: none;\n    display: grid;\n    place-items: center;\n    width: 16px;\n    height: 16px;\n    color: var(--cy-ink-mute);\n\n    [data-highlighted] > & {\n      color: var(--cy-signal);\n    }\n  }\n\n  [data-skin=\"cyber\"] [data-kit=\"command-palette-text\"] {\n    flex: 1;\n    min-width: 0;\n    overflow: hidden;\n    text-overflow: ellipsis;\n    white-space: nowrap;\n  }\n\n  /* The letters that matched: the signal color, and underlined, so the\n     emphasis doesn't rest on color. */\n  [data-skin=\"cyber\"] [data-kit=\"command-palette-match\"] {\n    background: none;\n    color: var(--cy-signal);\n    text-decoration: underline;\n    text-decoration-thickness: 1px;\n    text-underline-offset: 3px;\n  }\n\n  /* The foot: how many commands are left, and the keys that work here. */\n  [data-skin=\"cyber\"] [data-kit=\"command-palette-foot\"] {\n    flex: none;\n    display: flex;\n    align-items: center;\n    justify-content: space-between;\n    gap: 12px;\n    min-height: 30px;\n    padding-inline: 22px 14px;\n    border-block-start: 1px solid var(--cy-line-deco);\n    font-family: var(--cy-mono);\n    font-size: 10px;\n    letter-spacing: 0.08em;\n    text-transform: uppercase;\n    color: var(--cy-ink-mute);\n  }\n\n  [data-skin=\"cyber\"] [data-kit=\"command-palette-status\"] {\n    min-width: 0;\n    white-space: nowrap;\n\n    & [data-kit=\"value\"] {\n      font-size: inherit;\n    }\n  }\n\n  [data-skin=\"cyber\"] [data-kit=\"command-palette-hints\"] {\n    display: flex;\n    align-items: center;\n    gap: 6px;\n    margin-inline-start: auto;\n    white-space: nowrap;\n\n    & kbd:not(:first-child) {\n      margin-inline-start: 8px;\n    }\n  }\n}\n",
      "type": "registry:file",
      "target": "@ui/cyber/command-palette.css"
    }
  ],
  "type": "registry:ui"
}
