{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "prompt-13",
  "title": "Slash commands",
  "description": "Typing / lists the commands an agent knows with their arguments, and the chosen command settles into a token followed by its argument, selected so that typing replaces it.",
  "dependencies": [
    "motion"
  ],
  "registryDependencies": [
    "https://ui.ndekocode.dev/r/animated-size.json",
    "https://ui.ndekocode.dev/r/button.json",
    "https://ui.ndekocode.dev/r/chip.json",
    "https://ui.ndekocode.dev/r/demonstration.json",
    "https://ui.ndekocode.dev/r/drawn-check.json",
    "https://ui.ndekocode.dev/r/icons.json",
    "https://ui.ndekocode.dev/r/kbd.json",
    "https://ui.ndekocode.dev/r/live-region.json",
    "https://ui.ndekocode.dev/r/motion-presets.json",
    "https://ui.ndekocode.dev/r/theme.json",
    "https://ui.ndekocode.dev/r/use-autoplay.json",
    "https://ui.ndekocode.dev/r/use-kept-height.json",
    "https://ui.ndekocode.dev/r/use-prefers-reduced-motion.json",
    "https://ui.ndekocode.dev/r/utils.json"
  ],
  "files": [
    {
      "path": "registry/ndeko/components/prompt/prompt-13.tsx",
      "content": "'use client';\n\nimport { AnimatePresence, motion, type Transition } from 'motion/react';\nimport { useId, useImperativeHandle, useRef, useState } from 'react';\n\nimport {\n  typingSteps,\n  useAutoplay,\n  type AutoplayStep,\n} from '@/registry/ndeko/hooks/use-autoplay';\nimport { useKeptHeight } from '@/registry/ndeko/hooks/use-kept-height';\nimport { usePrefersReducedMotion } from '@/registry/ndeko/hooks/use-prefers-reduced-motion';\nimport {\n  hold,\n  PRESS_LEAD_MS,\n  pressedSolidOf,\n  spokenUnless,\n  usePress,\n} from '@/registry/ndeko/lib/demonstration';\nimport {\n  ArrowUpIcon,\n  CircleCheckIcon,\n  EyeIcon,\n  GitPullRequestIcon,\n  ListChecksIcon,\n  ListCollapseIcon,\n  TriangleAlertIcon,\n} from '@/registry/ndeko/lib/icons';\nimport {\n  risePresenceOf,\n  rowPresenceOf,\n  springOf,\n} from '@/registry/ndeko/lib/motion-presets';\nimport { cn } from '@/registry/ndeko/lib/utils';\nimport { AnimatedSize } from '@/registry/ndeko/ui/animated-size';\nimport { Button } from '@/registry/ndeko/ui/button';\nimport { Chip } from '@/registry/ndeko/ui/chip';\nimport { DrawnCheck } from '@/registry/ndeko/ui/drawn-check';\nimport { Kbd } from '@/registry/ndeko/ui/kbd';\nimport { LiveRegion } from '@/registry/ndeko/ui/live-region';\n\nimport { ListKeys, type ListKey } from './_parts/list-keys';\nimport { includesQuery, Marked } from './_parts/marked';\nimport { activeIdOf, wrappedIndexOf } from './_parts/option-list';\nimport { useActiveRowInView } from './_parts/use-active-row';\n\nexport type SlashCommand = {\n  id: string;\n  /** The word after the slash: `test` for `/test`. */\n  name: string;\n  description: string;\n  /** What follows the command, shown in a muted tone: `a path or a name`. */\n  argument: string;\n  /** The command cannot run without it. */\n  isArgumentRequired?: boolean;\n  icon: React.ReactNode;\n};\n\nexport type SlashMessage = {\n  /** Empty for a plain message. */\n  command: SlashCommand | null;\n  argument: string;\n};\n\nexport type SlashComposerHandle = {\n  move: (step: number) => void;\n  pickHighlighted: () => void;\n  send: () => void;\n};\n\nconst SHELL = [\n  'bg-card hairline-ring ring-foreground/12 dark:ring-foreground/15 has-[input:focus]:ring-ring/25 relative flex items-center gap-1 rounded-xl p-1.5',\n  'shadow-[0_1px_2px_rgb(0_0_0/0.04)] transition-shadow duration-150 has-[input:focus]:ring-[3px]',\n].join(' ');\n\nconst TILE =\n  'keycap-3d text-muted-foreground flex shrink-0 items-center justify-center [&_svg:not([class*=\"size-\"])]:size-3.5';\n\nfunction queryOf(command: SlashCommand | null, value: string) {\n  if (command !== null) {\n    return null;\n  }\n  const startsWithSlash = value.startsWith('/');\n  const hasSpace = /\\s/.test(value);\n  if (!startsWithSlash || hasSpace) {\n    return null;\n  }\n  return value.slice(1);\n}\n\nfunction argumentLabelOf(command: SlashCommand) {\n  if (command.isArgumentRequired) {\n    return `<${command.argument}>`;\n  }\n  return `[${command.argument}]`;\n}\n\nfunction typedCommandOf(commands: SlashCommand[], value: string) {\n  const match = /^\\/(\\w+)\\s(.*)$/.exec(value);\n  if (!match) {\n    return null;\n  }\n  const command = commands.find((entry) => entry.name === match[1]);\n  if (!command) {\n    return null;\n  }\n  return { command, rest: match[2] };\n}\n\nfunction activeToneOf(isActive: boolean) {\n  if (isActive) {\n    return 'bg-foreground/5';\n  }\n  return undefined;\n}\n\nfunction shakeOf(shouldReduceMotion: boolean | null) {\n  if (shouldReduceMotion) {\n    return { x: 0 };\n  }\n  return { x: [0, -4, 4, -2, 0] };\n}\n\nfunction activeDescendantOf(\n  isOpen: boolean,\n  optionPrefix: string,\n  activeId: string | null\n) {\n  if (!isOpen || activeId === null) {\n    return undefined;\n  }\n  return `${optionPrefix}-${activeId}`;\n}\n\ntype CommandRowProps = {\n  command: SlashCommand;\n  query: string;\n  optionId: string;\n  isActive: boolean;\n  onHover: (commandId: string) => void;\n  onPick: (command: SlashCommand) => void;\n};\n\nfunction CommandRow({\n  command,\n  query,\n  optionId,\n  isActive,\n  onHover,\n  onPick,\n}: CommandRowProps) {\n  return (\n    <div\n      id={optionId}\n      role='option'\n      aria-selected={isActive}\n      onMouseMove={() => onHover(command.id)}\n      onClick={() => onPick(command)}\n      className={cn(\n        'flex min-h-11 cursor-default items-center gap-2.5 rounded-lg px-2 py-1.5 transition-colors duration-100',\n        activeToneOf(isActive)\n      )}\n    >\n      <span className={cn(TILE, 'size-7 rounded-md')}>{command.icon}</span>\n      <span className='flex min-w-0 flex-1 flex-col'>\n        <span className='truncate font-mono text-[13px]'>\n          <span className='font-medium'>\n            /<Marked text={command.name} query={query} />\n          </span>\n          <span className='text-muted-foreground ms-1.5 text-xs'>\n            {argumentLabelOf(command)}\n          </span>\n        </span>\n        <span className='text-muted-foreground truncate text-xs'>\n          {command.description}\n        </span>\n      </span>\n    </div>\n  );\n}\n\ntype CommandListProps = {\n  matches: SlashCommand[];\n  query: string;\n  listId: string;\n  activeId: string | null;\n  optionIdOf: (commandId: string) => string;\n  listRef: React.RefObject<HTMLDivElement | null>;\n  pressedKey: ListKey | null;\n  onHover: (commandId: string) => void;\n  onPick: (command: SlashCommand) => void;\n};\n\nfunction CommandList({\n  matches,\n  query,\n  listId,\n  activeId,\n  optionIdOf,\n  listRef,\n  pressedKey,\n  onHover,\n  onPick,\n}: CommandListProps) {\n  const isEmpty = matches.length === 0;\n\n  return (\n    <div className='surface-raised flex flex-col overflow-hidden rounded-xl'>\n      <div\n        ref={listRef}\n        id={listId}\n        role='listbox'\n        aria-label='Commands'\n        onMouseDown={(event) => event.preventDefault()}\n        className='relative flex max-h-72 flex-col overflow-y-auto p-1'\n      >\n        {isEmpty && (\n          <p className='text-muted-foreground px-2 py-6 text-center text-xs'>\n            No command starts with “{query}”. Keep typing, or press Escape.\n          </p>\n        )}\n        {matches.map((command) => (\n          <CommandRow\n            key={command.id}\n            command={command}\n            query={query}\n            optionId={optionIdOf(command.id)}\n            isActive={command.id === activeId}\n            onHover={onHover}\n            onPick={onPick}\n          />\n        ))}\n      </div>\n      <ListKeys\n        pressed={pressedKey}\n        enterLabel='inserts'\n        className='bg-foreground/[0.03] px-3 py-2'\n      />\n    </div>\n  );\n}\n\ntype CommandTokenProps = {\n  command: SlashCommand;\n  glide: Transition;\n  isReduced: boolean;\n};\n\nfunction CommandToken({ command, glide, isReduced }: CommandTokenProps) {\n  const startScale = startScaleOf(isReduced);\n\n  return (\n    <motion.span\n      initial={{ opacity: 0, scale: startScale }}\n      animate={{ opacity: 1, scale: 1 }}\n      exit={{ opacity: 0, scale: startScale }}\n      transition={glide}\n      className='inline-flex'\n    >\n      <Chip color='var(--primary)' className='h-6 px-2 font-mono text-[13px]'>\n        /{command.name}\n      </Chip>\n    </motion.span>\n  );\n}\n\nfunction startScaleOf(isReduced: boolean) {\n  if (isReduced) {\n    return 1;\n  }\n  return 0.86;\n}\n\ntype SlashHintProps = {\n  command: SlashCommand | null;\n  isMissing: boolean;\n  nudges: number;\n};\n\nfunction SlashHint({ command, isMissing, nudges }: SlashHintProps) {\n  const shouldReduceMotion = usePrefersReducedMotion();\n  const shake = shakeOf(shouldReduceMotion);\n\n  if (isMissing && command) {\n    return (\n      <motion.p\n        key={nudges}\n        animate={shake}\n        transition={{ duration: 0.24 }}\n        className='text-warning-foreground flex h-5 items-center gap-1.5 px-1 text-xs'\n      >\n        <TriangleAlertIcon className='size-3.5' />/{command.name} needs{' '}\n        {command.argument}\n      </motion.p>\n    );\n  }\n  if (command) {\n    return (\n      <p className='text-muted-foreground flex h-5 items-center gap-1 px-1 text-xs'>\n        <Kbd>Enter</Kbd> sends, <Kbd>Backspace</Kbd> takes the command back\n      </p>\n    );\n  }\n  return (\n    <p className='text-muted-foreground flex h-5 items-center gap-1 px-1 text-xs'>\n      <Kbd>/</Kbd> opens the commands, <Kbd>Enter</Kbd> sends\n    </p>\n  );\n}\n\nexport type SlashComposerProps = {\n  commands: SlashCommand[];\n  /** What is typed: the command being searched for, or the argument once a command is chosen. */\n  value: string;\n  onValueChange: (value: string) => void;\n  /** The command chosen, shown as a token before the argument. */\n  command: SlashCommand | null;\n  onCommandChange: (command: SlashCommand | null) => void;\n  /** `floating` hangs the list over the page above the composer. `inline` draws it under the composer and keeps its place. */\n  listPlacement?: 'inline' | 'floating';\n  /** Shows the list without focus, for a demonstration or a preview nobody types in. */\n  showsUnfocused?: boolean;\n  onSend?: (message: SlashMessage) => void;\n  handleRef?: React.Ref<SlashComposerHandle>;\n  /** The key a demonstration is holding down in the list. */\n  pressedKey?: ListKey | null;\n  /** Shows Send held down, for a demonstration that presses it. */\n  isSendPressed?: boolean;\n  className?: string;\n};\n\nexport function SlashComposer({\n  commands,\n  value,\n  onValueChange,\n  command,\n  onCommandChange,\n  listPlacement = 'floating',\n  showsUnfocused = false,\n  onSend,\n  handleRef,\n  pressedKey = null,\n  isSendPressed = false,\n  className,\n}: SlashComposerProps) {\n  const [isFocused, setIsFocused] = useState(false);\n  const [highlightedId, setHighlightedId] = useState<string | null>(null);\n  const [isDismissed, setIsDismissed] = useState(false);\n  const [nudges, setNudges] = useState(0);\n  const [notice, setNotice] = useState('');\n  const listRef = useRef<HTMLDivElement>(null);\n  const shouldReduceMotion = usePrefersReducedMotion();\n  const risePresence = risePresenceOf(shouldReduceMotion);\n  const glide = springOf(shouldReduceMotion);\n  const listId = useId();\n  const optionPrefix = useId();\n  const query = queryOf(command, value);\n  const isSearching = query !== null;\n  const isShowing = isFocused || showsUnfocused;\n  const isOpen = isSearching && !isDismissed && isShowing;\n  const matches = commandMatchesOf(commands, query);\n  const activeId = activeIdOf(matches, highlightedId);\n  const activeDescendant = activeDescendantOf(isOpen, optionPrefix, activeId);\n  const hasArgument = value.trim() !== '';\n  const hasContent = command !== null || hasArgument;\n  const showsArgumentHint = command !== null && value === '';\n  const isMissing = command?.isArgumentRequired === true && !hasArgument;\n  const resultsMessage = resultsMessageOf(\n    isOpen,\n    matches.length,\n    showsUnfocused\n  );\n  useActiveRowInView(listRef, activeDescendant);\n\n  function optionIdOf(commandId: string) {\n    return `${optionPrefix}-${commandId}`;\n  }\n\n  function move(step: number) {\n    const ids = matches.map((entry) => entry.id);\n    const current = ids.indexOf(activeId ?? '');\n    const next = wrappedIndexOf(current, step, ids.length);\n    const id = ids[next];\n    if (id) {\n      setHighlightedId(id);\n    }\n  }\n\n  function pick(chosen: SlashCommand) {\n    onCommandChange(chosen);\n    onValueChange('');\n    setHighlightedId(null);\n    setIsDismissed(false);\n    setNotice(`/${chosen.name} chosen, ${chosen.argument} comes next`);\n  }\n\n  function pickHighlighted() {\n    const chosen = matches.find((entry) => entry.id === activeId);\n    if (chosen) {\n      pick(chosen);\n    }\n  }\n\n  function send() {\n    if (!hasContent) {\n      return;\n    }\n    if (isMissing) {\n      setNudges((current) => current + 1);\n      setNotice(`/${command?.name} needs ${command?.argument}`);\n      return;\n    }\n    onSend?.({ command, argument: value.trim() });\n    onCommandChange(null);\n    onValueChange('');\n    setNotice('Sent');\n  }\n\n  useImperativeHandle(handleRef, () => ({ move, pickHighlighted, send }));\n\n  function takeCommandBack() {\n    if (!command) {\n      return;\n    }\n    onCommandChange(null);\n    onValueChange(`/${command.name}`);\n    setIsDismissed(false);\n    setNotice(`/${command.name} taken back`);\n  }\n\n  function changeValue(event: React.ChangeEvent<HTMLInputElement>) {\n    const next = event.target.value;\n    setIsDismissed(false);\n    const typed = typedCommandOf(commands, next);\n    if (command === null && typed) {\n      onCommandChange(typed.command);\n      onValueChange(typed.rest);\n      return;\n    }\n    onValueChange(next);\n  }\n\n  function handleKeys(event: React.KeyboardEvent<HTMLInputElement>) {\n    const isComposing = event.nativeEvent.isComposing;\n    if (isComposing) {\n      return;\n    }\n    if (isOpen) {\n      const picksWithTab = event.key === 'Tab' && !event.shiftKey;\n      const picksWithEnter = event.key === 'Enter';\n      if (event.key === 'ArrowDown') {\n        event.preventDefault();\n        move(1);\n        return;\n      }\n      if (event.key === 'ArrowUp') {\n        event.preventDefault();\n        move(-1);\n        return;\n      }\n      if (picksWithEnter || picksWithTab) {\n        event.preventDefault();\n        pickHighlighted();\n        return;\n      }\n      if (event.key === 'Escape') {\n        event.preventDefault();\n        setIsDismissed(true);\n        return;\n      }\n    }\n    if (event.key === 'Enter') {\n      event.preventDefault();\n      send();\n      return;\n    }\n    const isBackspace = event.key === 'Backspace';\n    const canTakeBack = isBackspace && value === '' && command !== null;\n    if (canTakeBack) {\n      event.preventDefault();\n      takeCommandBack();\n    }\n  }\n\n  const list = (\n    <CommandList\n      matches={matches}\n      query={query ?? ''}\n      listId={listId}\n      activeId={activeId}\n      optionIdOf={optionIdOf}\n      listRef={listRef}\n      pressedKey={pressedKey}\n      onHover={setHighlightedId}\n      onPick={pick}\n    />\n  );\n\n  return (\n    <div className={cn('relative flex w-full flex-col gap-2', className)}>\n      <div className='flex flex-col gap-1.5'>\n        <div className={SHELL}>\n          <AnimatedSize as='span' axis='width' className='shrink-0'>\n            <AnimatePresence initial={false}>\n              {command && (\n                <CommandToken\n                  key={command.id}\n                  command={command}\n                  glide={glide}\n                  isReduced={shouldReduceMotion}\n                />\n              )}\n            </AnimatePresence>\n          </AnimatedSize>\n          <div className='relative min-w-0 flex-1'>\n            <input\n              type='text'\n              role='combobox'\n              value={value}\n              onChange={changeValue}\n              onKeyDown={handleKeys}\n              onFocus={() => setIsFocused(true)}\n              onBlur={() => setIsFocused(false)}\n              aria-label='Message'\n              aria-expanded={isOpen}\n              aria-controls={listId}\n              aria-autocomplete='list'\n              aria-activedescendant={activeDescendant}\n              autoComplete='off'\n              spellCheck={false}\n              placeholder={placeholderOf(command)}\n              className={cn(\n                'h-8 w-full min-w-0 bg-transparent px-2 text-base outline-none md:text-[13px]',\n                placeholderToneOf(showsArgumentHint)\n              )}\n            />\n            {showsArgumentHint && (\n              <span\n                aria-hidden='true'\n                className='pointer-events-none absolute inset-y-0 start-2 flex items-center transition-opacity delay-150 duration-200 starting:opacity-0'\n              >\n                <span className='bg-primary/20 rounded-[4px] px-1 text-base md:text-[13px]'>\n                  {command.argument}\n                </span>\n              </span>\n            )}\n          </div>\n          <Button\n            type='button'\n            size='icon'\n            aria-label={sendLabelOf(hasContent)}\n            disabled={!hasContent}\n            focusableWhenDisabled\n            onClick={send}\n            className={pressedSolidOf(isSendPressed)}\n          >\n            <ArrowUpIcon />\n          </Button>\n        </div>\n        <SlashHint command={command} isMissing={isMissing} nudges={nudges} />\n      </div>\n      <AnimatePresence initial={false}>\n        {isOpen && listPlacement === 'inline' && (\n          <motion.div key='list' {...risePresence}>\n            {list}\n          </motion.div>\n        )}\n        {isOpen && listPlacement === 'floating' && (\n          <motion.div\n            key='list'\n            {...risePresence}\n            className='absolute inset-x-0 bottom-full z-20 mb-2'\n          >\n            {list}\n          </motion.div>\n        )}\n      </AnimatePresence>\n      <LiveRegion message={resultsMessage} />\n      <LiveRegion message={spokenUnless(showsUnfocused, notice)} />\n    </div>\n  );\n}\n\nfunction commandMatchesOf(commands: SlashCommand[], query: string | null) {\n  if (query === null) {\n    return [];\n  }\n  return commands.filter((entry) => includesQuery(entry.name, query));\n}\n\nfunction placeholderToneOf(showsArgumentHint: boolean) {\n  if (showsArgumentHint) {\n    return 'placeholder:text-transparent';\n  }\n  return 'placeholder:text-muted-foreground/75';\n}\n\nfunction placeholderOf(command: SlashCommand | null) {\n  if (command) {\n    return command.argument;\n  }\n  return 'Ask something, or type / for commands';\n}\n\nfunction sendLabelOf(hasContent: boolean) {\n  if (hasContent) {\n    return 'Send';\n  }\n  return 'Send, write something first';\n}\n\nfunction resultsMessageOf(\n  isOpen: boolean,\n  count: number,\n  isDemonstrating: boolean\n) {\n  if (!isOpen || isDemonstrating) {\n    return '';\n  }\n  if (count === 1) {\n    return '1 command';\n  }\n  return `${count} commands`;\n}\n\nconst COMMANDS: SlashCommand[] = [\n  {\n    id: 'plan',\n    name: 'plan',\n    description: 'Write a plan before changing anything',\n    argument: 'what to plan',\n    isArgumentRequired: true,\n    icon: <ListChecksIcon />,\n  },\n  {\n    id: 'review',\n    name: 'review',\n    description: 'Read the changes and list what to fix',\n    argument: 'a file or a pull request',\n    icon: <EyeIcon />,\n  },\n  {\n    id: 'compact',\n    name: 'compact',\n    description: 'Summarize the conversation to free up room',\n    argument: 'what to keep',\n    icon: <ListCollapseIcon />,\n  },\n  {\n    id: 'test',\n    name: 'test',\n    description: 'Run the tests for what changed',\n    argument: 'a path or a name',\n    icon: <CircleCheckIcon />,\n  },\n  {\n    id: 'pr',\n    name: 'pr',\n    description: 'Open a pull request from this branch',\n    argument: 'a title',\n    icon: <GitPullRequestIcon />,\n  },\n];\n\nconst RESULTS: Record<string, string> = {\n  plan: 'Plan ready, 4 steps',\n  review: '3 things to fix',\n  compact: 'Conversation compacted',\n  test: '24 tests passed',\n  pr: 'Draft pull request opened',\n};\n\ntype SentEntry = {\n  id: number;\n  command: SlashCommand;\n  argument: string;\n};\n\nconst MAX_SENT = 2;\n\nfunction SentList({ entries }: { entries: SentEntry[] }) {\n  const shouldReduceMotion = usePrefersReducedMotion();\n  const rowPresence = rowPresenceOf(shouldReduceMotion);\n\n  return (\n    <ul aria-label='Sent commands' className='flex min-h-[4.5rem] flex-col'>\n      <AnimatePresence initial={false}>\n        {entries.map((entry) => (\n          <motion.li\n            key={entry.id}\n            className='overflow-hidden'\n            {...rowPresence}\n          >\n            <div className='flex items-center gap-2.5 px-1 py-1.5 text-xs'>\n              <DrawnCheck tone='success' entrance='draw' />\n              <p className='min-w-0 flex-1 truncate'>\n                <span className='font-mono font-medium'>\n                  /{entry.command.name}\n                </span>{' '}\n                <span className='text-muted-foreground'>{entry.argument}</span>\n              </p>\n              <span className='text-muted-foreground shrink-0'>\n                {RESULTS[entry.command.id]}\n              </span>\n            </div>\n          </motion.li>\n        ))}\n      </AnimatePresence>\n    </ul>\n  );\n}\n\nconst START_VALUE = '/';\n\nconst NO_SENT: SentEntry[] = [];\n\nfunction SlashDemo() {\n  const [value, setValue] = useState(START_VALUE);\n  const [command, setCommand] = useState<SlashCommand | null>(null);\n  const [sent, setSent] = useState(NO_SENT);\n  const composer = useRef<SlashComposerHandle>(null);\n  const { pressed, press } = usePress<ListKey | 'send'>();\n  const pressedKey = listKeyOf(pressed);\n\n  function resetDemo() {\n    setValue(START_VALUE);\n    setCommand(null);\n    setSent(NO_SENT);\n  }\n\n  function typeFirst(typed: string) {\n    setValue(`/${typed}`);\n  }\n\n  function noteSent(message: SlashMessage) {\n    const sentCommand = message.command;\n    if (!sentCommand) {\n      return;\n    }\n    const entry = {\n      id: Date.now(),\n      command: sentCommand,\n      argument: message.argument,\n    };\n    setSent((current) => [...current, entry].slice(-MAX_SENT));\n  }\n\n  const steps: AutoplayStep[] = [\n    ...typingSteps('te', typeFirst, { startAfter: 1500, characterMs: 150 }),\n    { after: 1000, run: () => press('enter') },\n    { after: PRESS_LEAD_MS, run: () => composer.current?.pickHighlighted() },\n    ...typingSteps('checkout flow', setValue, {\n      startAfter: 1200,\n      characterMs: 65,\n    }),\n    { after: 900, run: () => press('send') },\n    { after: PRESS_LEAD_MS, run: () => composer.current?.send() },\n    ...typingSteps('/com', setValue, { startAfter: 1800, characterMs: 150 }),\n    { after: 1000, run: () => press('enter') },\n    { after: PRESS_LEAD_MS, run: () => composer.current?.pickHighlighted() },\n    { after: 1400, run: () => press('send') },\n    { after: PRESS_LEAD_MS, run: () => composer.current?.send() },\n    { after: 2600, run: hold },\n  ];\n  const { ref, isAutoplaying } = useAutoplay(steps, {\n    loopAfter: 1600,\n    onReset: resetDemo,\n  });\n\n  useKeptHeight(ref);\n\n  return (\n    <div\n      ref={ref}\n      className='flex min-h-[28rem] w-full max-w-[32rem] flex-col gap-2'\n    >\n      <SentList entries={sent} />\n      <SlashComposer\n        commands={COMMANDS}\n        value={value}\n        onValueChange={setValue}\n        command={command}\n        onCommandChange={setCommand}\n        listPlacement='inline'\n        showsUnfocused={isAutoplaying}\n        onSend={noteSent}\n        handleRef={composer}\n        pressedKey={pressedKey}\n        isSendPressed={pressed === 'send'}\n      />\n      <p className='text-muted-foreground px-1 text-xs'>\n        Illustrative commands on sample work\n      </p>\n    </div>\n  );\n}\n\nfunction listKeyOf(pressed: ListKey | 'send' | null) {\n  if (pressed === 'send') {\n    return null;\n  }\n  return pressed;\n}\n\nexport default function Prompt13() {\n  return <SlashDemo />;\n}\n",
      "type": "registry:component",
      "target": "components/prompt/prompt-13.tsx"
    },
    {
      "path": "registry/ndeko/components/prompt/_parts/list-keys.tsx",
      "content": "import { cn } from '@/registry/ndeko/lib/utils';\nimport { Kbd, KbdGroup } from '@/registry/ndeko/ui/kbd';\n\nexport type ListKey = 'move' | 'enter' | 'tab' | 'escape';\n\nconst KEY_MOTION = 'transition-[scale,background-color,color] duration-150';\n\nconst PRESSED = 'scale-90 bg-primary/15 text-primary-ink';\n\nfunction pressedOf(isPressed: boolean) {\n  if (isPressed) {\n    return PRESSED;\n  }\n  return undefined;\n}\n\ntype ListKeysProps = {\n  /** The key a demonstration is holding down. */\n  pressed: ListKey | null;\n  /** Adds Tab, for a list that has groups to jump between. */\n  hasGroups?: boolean;\n  enterLabel?: string;\n  className?: string;\n};\n\nexport function ListKeys({\n  pressed,\n  hasGroups = false,\n  enterLabel = 'picks',\n  className,\n}: ListKeysProps) {\n  const moveClass = cn(KEY_MOTION, pressedOf(pressed === 'move'));\n  const enterClass = cn(KEY_MOTION, pressedOf(pressed === 'enter'));\n  const tabClass = cn(KEY_MOTION, pressedOf(pressed === 'tab'));\n  const escapeClass = cn(KEY_MOTION, pressedOf(pressed === 'escape'));\n\n  return (\n    <p\n      className={cn(\n        'text-muted-foreground flex flex-wrap items-center gap-x-3 gap-y-1 text-xs',\n        className\n      )}\n    >\n      <span className='inline-flex items-center gap-1'>\n        <KbdGroup aria-hidden='true'>\n          <Kbd className={moveClass}>↑</Kbd>\n          <Kbd className={moveClass}>↓</Kbd>\n        </KbdGroup>\n        <span className='sr-only'>Up and Down arrows</span>\n        move\n      </span>\n      <span className='inline-flex items-center gap-1'>\n        <Kbd className={enterClass}>Enter</Kbd> {enterLabel}\n      </span>\n      {hasGroups && (\n        <span className='inline-flex items-center gap-1'>\n          <Kbd className={tabClass}>Tab</Kbd> next group\n        </span>\n      )}\n      <span className='inline-flex items-center gap-1'>\n        <Kbd className={escapeClass}>Esc</Kbd> closes\n      </span>\n    </p>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/prompt/_parts/list-keys.tsx"
    },
    {
      "path": "registry/ndeko/components/prompt/_parts/marked.tsx",
      "content": "type TextPiece = { text: string; isMatch: boolean };\n\nexport function piecesOf(text: string, query: string): TextPiece[] {\n  const needle = query.trim().toLowerCase();\n  if (needle === '') {\n    return [{ text, isMatch: false }];\n  }\n  const haystack = text.toLowerCase();\n  const pieces: TextPiece[] = [];\n  let cursor = 0;\n  let found = haystack.indexOf(needle, cursor);\n  while (found >= 0) {\n    const before = text.slice(cursor, found);\n    const matchEnd = found + needle.length;\n    const match = text.slice(found, matchEnd);\n    if (before !== '') {\n      pieces.push({ text: before, isMatch: false });\n    }\n    pieces.push({ text: match, isMatch: true });\n    cursor = matchEnd;\n    found = haystack.indexOf(needle, cursor);\n  }\n  const rest = text.slice(cursor);\n  if (rest !== '') {\n    pieces.push({ text: rest, isMatch: false });\n  }\n  return pieces;\n}\n\nexport function includesQuery(text: string, query: string) {\n  const needle = query.trim().toLowerCase();\n  if (needle === '') {\n    return true;\n  }\n  const haystack = text.toLowerCase();\n  return haystack.includes(needle);\n}\n\ntype MarkedProps = {\n  text: string;\n  query: string;\n};\n\nexport function Marked({ text, query }: MarkedProps) {\n  const pieces = piecesOf(text, query);\n\n  return (\n    <>\n      {pieces.map((piece, index) => {\n        if (piece.isMatch) {\n          return (\n            <mark\n              key={index}\n              className='bg-warning/25 text-foreground rounded-[3px] px-px'\n            >\n              {piece.text}\n            </mark>\n          );\n        }\n        return <span key={index}>{piece.text}</span>;\n      })}\n    </>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/prompt/_parts/marked.tsx"
    },
    {
      "path": "registry/ndeko/components/prompt/_parts/option-list.ts",
      "content": "/** The row after a step through a list that wraps round, or the first one when nothing is active. */\nexport function wrappedIndexOf(current: number, step: number, count: number) {\n  if (count === 0) {\n    return -1;\n  }\n  const hasCurrent = current >= 0;\n  if (!hasCurrent) {\n    return firstIndexFor(step, count);\n  }\n  const moved = current + step;\n  const shifted = moved + count;\n  return shifted % count;\n}\n\nfunction firstIndexFor(step: number, count: number) {\n  if (step > 0) {\n    return 0;\n  }\n  return count - 1;\n}\n\n/** Scrolls the list itself, never the page: `list` must be positioned so `offsetTop` is measured from it. */\nexport function keepRowInView(list: HTMLElement, row: HTMLElement) {\n  const rowTop = row.offsetTop;\n  const rowBottom = rowTop + row.offsetHeight;\n  const viewTop = list.scrollTop;\n  const viewBottom = viewTop + list.clientHeight;\n  if (rowTop < viewTop) {\n    list.scrollTop = rowTop;\n    return;\n  }\n  if (rowBottom > viewBottom) {\n    list.scrollTop = rowBottom - list.clientHeight;\n  }\n}\n\n/** The highlighted row if it is still listed, otherwise the first one. */\nexport function activeIdOf(\n  items: { id: string }[],\n  highlightedId: string | null\n) {\n  const stillListed = items.some((item) => item.id === highlightedId);\n  if (stillListed) {\n    return highlightedId;\n  }\n  return items[0]?.id ?? null;\n}\n",
      "type": "registry:component",
      "target": "components/prompt/_parts/option-list.ts"
    },
    {
      "path": "registry/ndeko/components/prompt/_parts/use-active-row.ts",
      "content": "'use client';\n\nimport { useEffect } from 'react';\n\nimport { keepRowInView } from './option-list';\n\n/** Keeps the active row of a list in view as it changes, scrolling the list and never the page. */\nexport function useActiveRowInView(\n  listRef: React.RefObject<HTMLElement | null>,\n  rowId: string | undefined\n) {\n  useEffect(() => {\n    if (rowId === undefined) {\n      return;\n    }\n    const list = listRef.current;\n    const row = document.getElementById(rowId);\n    if (list && row) {\n      keepRowInView(list, row);\n    }\n  }, [listRef, rowId]);\n}\n",
      "type": "registry:component",
      "target": "components/prompt/_parts/use-active-row.ts"
    }
  ],
  "categories": [
    "components",
    "prompt"
  ],
  "type": "registry:component"
}