{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "ai-product-06",
  "title": "App shelf",
  "description": "A row of app tiles that walks along itself: the tile in focus lifts a preview card out of itself with a Connect button while its neighbours dim, with arrows to move and Enter to connect.",
  "dependencies": [
    "motion"
  ],
  "registryDependencies": [
    "https://ui.ndekocode.dev/r/brand-logos.json",
    "https://ui.ndekocode.dev/r/brand-tile.json",
    "https://ui.ndekocode.dev/r/button.json",
    "https://ui.ndekocode.dev/r/chat-motion.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/live-region.json",
    "https://ui.ndekocode.dev/r/motion-number.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-prefers-reduced-motion.json",
    "https://ui.ndekocode.dev/r/utils.json"
  ],
  "files": [
    {
      "path": "registry/ndeko/blocks/ai-product/ai-product-06/index.tsx",
      "content": "'use client';\n\nimport { useState } from 'react';\n\nimport { MotionNumber } from '@/components/core/motion-number';\nimport { useAutoplay } from '@/registry/ndeko/hooks/use-autoplay';\nimport { usePrefersReducedMotion } from '@/registry/ndeko/hooks/use-prefers-reduced-motion';\nimport {\n  PRESS_LEAD_MS,\n  spokenUnless,\n  usePress,\n} from '@/registry/ndeko/lib/demonstration';\nimport { PlugIcon } from '@/registry/ndeko/lib/icons';\nimport { LiveRegion } from '@/registry/ndeko/ui/live-region';\n\nimport { AppTile, type Anchor } from './app-tile';\nimport {\n  APPS,\n  appOf,\n  DEMO_CONNECT,\n  RESTING_ID,\n  SECTION,\n  type AppId,\n} from './data';\n\nconst LOOP_AFTER_MS = 2800;\n\nfunction anchorOf(index: number): Anchor {\n  const lastIndex = APPS.length - 1;\n  if (index <= 1) {\n    return 'start';\n  }\n  if (index >= lastIndex - 1) {\n    return 'end';\n  }\n  return 'center';\n}\n\n/** Under reduced motion nothing walks, so the shelf rests with one card open. */\nfunction shownIdOf(activeId: AppId | null, shouldReduceMotion: boolean) {\n  if (activeId === null && shouldReduceMotion) {\n    return RESTING_ID;\n  }\n  return activeId;\n}\n\nfunction tabStopIdOf(shownId: AppId | null) {\n  if (shownId === null) {\n    return APPS[0].id;\n  }\n  return shownId;\n}\n\nfunction targetIndexOf(key: string, index: number) {\n  const lastIndex = APPS.length - 1;\n  if (key === 'ArrowRight') {\n    const after = index + 1;\n    return Math.min(lastIndex, after);\n  }\n  if (key === 'ArrowLeft') {\n    const before = index - 1;\n    return Math.max(0, before);\n  }\n  if (key === 'Home') {\n    return 0;\n  }\n  if (key === 'End') {\n    return lastIndex;\n  }\n  return null;\n}\n\nexport default function AiProduct06() {\n  const [activeId, setActiveId] = useState<AppId | null>(null);\n  const [connected, setConnected] = useState<AppId[]>([]);\n  const [message, setMessage] = useState('');\n  const [isPointerInside, setIsPointerInside] = useState(false);\n  const { pressed, press } = usePress<string>();\n  const shouldReduceMotion = usePrefersReducedMotion();\n\n  function connect(id: AppId) {\n    const app = appOf(id);\n    const isConnected = connected.includes(id);\n    setActiveId(id);\n    if (isConnected) {\n      return;\n    }\n    setConnected((current) => [...current, id]);\n    setMessage(`${app.name} connected`);\n  }\n\n  function resetDemonstration() {\n    setActiveId(null);\n    setConnected([]);\n    setMessage('');\n  }\n\n  const steps = [\n    { after: 900, run: () => setActiveId(APPS[0].id) },\n    { after: 1800, run: () => setActiveId(APPS[1].id) },\n    { after: 1800, run: () => setActiveId(APPS[2].id) },\n    { after: 1200, run: () => press(`connect-${DEMO_CONNECT}`) },\n    { after: PRESS_LEAD_MS, run: () => connect(DEMO_CONNECT) },\n    { after: 1800, run: () => setActiveId(APPS[3].id) },\n    { after: 1800, run: () => setActiveId(APPS[4].id) },\n  ];\n  const { ref, isAutoplaying } = useAutoplay<HTMLElement>(steps, {\n    loopAfter: LOOP_AFTER_MS,\n    onReset: resetDemonstration,\n    isEnabled: !isPointerInside,\n  });\n  const shownId = shownIdOf(activeId, shouldReduceMotion);\n  const tabStopId = tabStopIdOf(shownId);\n  const hasActive = shownId !== null;\n  const spoken = spokenUnless(isAutoplaying, message);\n\n  function enterRow(event: React.PointerEvent<HTMLElement>) {\n    if (event.pointerType === 'mouse') {\n      setIsPointerInside(true);\n    }\n  }\n\n  function leaveRow(event: React.PointerEvent<HTMLElement>) {\n    if (event.pointerType !== 'mouse') {\n      return;\n    }\n    setIsPointerInside(false);\n    setActiveId(null);\n  }\n\n  /** A click on a button that takes no focus (Safari) leaves no next element: the card stays for it. */\n  function leaveFocus(event: React.FocusEvent<HTMLUListElement>) {\n    const next = event.relatedTarget;\n    if (!(next instanceof Node)) {\n      return;\n    }\n    const isStillInside = event.currentTarget.contains(next);\n    if (!isStillInside) {\n      setActiveId(null);\n    }\n  }\n\n  function moveFocus(event: React.KeyboardEvent<HTMLUListElement>) {\n    if (event.key === 'Escape') {\n      setActiveId(null);\n      return;\n    }\n    const target = event.target;\n    if (!(target instanceof HTMLElement)) {\n      return;\n    }\n    const currentId = target.dataset.appTile;\n    const index = APPS.findIndex((app) => app.id === currentId);\n    if (index < 0) {\n      return;\n    }\n    const nextIndex = targetIndexOf(event.key, index);\n    if (nextIndex === null) {\n      return;\n    }\n    event.preventDefault();\n    const next = APPS[nextIndex];\n    const tile = ref.current?.querySelector<HTMLElement>(\n      `[data-app-tile=\"${next.id}\"]`\n    );\n    tile?.focus();\n  }\n\n  return (\n    <section ref={ref} className='@container'>\n      <div className='mx-auto flex max-w-3xl flex-col gap-10 px-4 py-16 @2xl:px-6 @2xl:py-24'>\n        <header className='flex flex-wrap items-end justify-between gap-x-6 gap-y-3'>\n          <div className='flex max-w-xl flex-col gap-3'>\n            <p className='text-primary-ink flex items-center gap-1.5 text-[13px] font-medium'>\n              <PlugIcon className='size-4' />\n              {SECTION.label}\n            </p>\n            <h2 className='text-2xl font-semibold text-balance @2xl:text-3xl'>\n              {SECTION.title}\n            </h2>\n            <p className='text-muted-foreground text-base text-pretty'>\n              {SECTION.lead}\n            </p>\n          </div>\n          <p className='text-muted-foreground flex items-baseline gap-1 text-[13px]'>\n            <MotionNumber\n              value={connected.length}\n              className='text-foreground'\n            />\n            of {APPS.length} connected\n          </p>\n        </header>\n        <ul\n          aria-label='Apps'\n          onKeyDown={moveFocus}\n          onBlur={leaveFocus}\n          onPointerEnter={enterRow}\n          onPointerLeave={leaveRow}\n          className='flex justify-center gap-2 pb-44 @lg:gap-5 @2xl:gap-6'\n        >\n          {APPS.map((app, index) => (\n            <AppTile\n              key={app.id}\n              app={app}\n              anchor={anchorOf(index)}\n              isActive={shownId === app.id}\n              isDimmed={hasActive && shownId !== app.id}\n              isConnected={connected.includes(app.id)}\n              isTabStop={tabStopId === app.id}\n              pressed={pressed}\n              onActivate={setActiveId}\n              onConnect={connect}\n            />\n          ))}\n        </ul>\n      </div>\n      <LiveRegion message={spoken} />\n    </section>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/blocks/ai-product-06/index.tsx"
    },
    {
      "path": "registry/ndeko/blocks/ai-product/ai-product-06/app-tile.tsx",
      "content": "'use client';\n\nimport { AnimatePresence, motion, type Transition } from 'motion/react';\nimport { useId } from 'react';\n\nimport { usePrefersReducedMotion } from '@/registry/ndeko/hooks/use-prefers-reduced-motion';\nimport { pressedSolidOf } from '@/registry/ndeko/lib/demonstration';\nimport { EASE_OUT_STRONG } from '@/registry/ndeko/lib/motion-presets';\nimport { cn } from '@/registry/ndeko/lib/utils';\nimport { BrandTile } from '@/registry/ndeko/ui/brand-tile';\nimport { Button } from '@/registry/ndeko/ui/button';\nimport { Swap } from '@/registry/ndeko/ui/chat-motion';\nimport { DrawnCheck } from '@/registry/ndeko/ui/drawn-check';\n\nimport type { App } from './data';\n\nexport type Anchor = 'start' | 'center' | 'end';\n\n/** The cards of the outer tiles hang from the edge of the row, so none leaves the block. */\nconst ANCHOR_CLASS: Record<Anchor, string> = {\n  start: 'start-0 origin-top-left',\n  center: 'left-1/2 -translate-x-1/2 origin-top',\n  end: 'end-0 origin-top-right',\n};\n\nconst LIFT: Transition = { duration: 0.22, ease: EASE_OUT_STRONG };\n\nconst LEAVE: Transition = { duration: 0.1, ease: EASE_OUT_STRONG };\n\nfunction liftOf(shouldReduceMotion: boolean) {\n  if (shouldReduceMotion) {\n    return {\n      initial: { opacity: 0 },\n      animate: { opacity: 1, transition: LIFT },\n      exit: { opacity: 0, transition: LEAVE },\n    };\n  }\n  return {\n    initial: { opacity: 0, scale: 0.94, y: -12 },\n    animate: { opacity: 1, scale: 1, y: 0, transition: LIFT },\n    exit: { opacity: 0, scale: 0.96, y: -6, transition: LEAVE },\n  };\n}\n\nfunction toneOf(isActive: boolean, isDimmed: boolean) {\n  if (isActive) {\n    return 'bg-foreground/[0.09] -translate-y-0.5';\n  }\n  if (isDimmed) {\n    return 'bg-foreground/[0.04] opacity-40';\n  }\n  return 'bg-foreground/[0.04]';\n}\n\nfunction stateWordOf(isConnected: boolean) {\n  if (isConnected) {\n    return 'connected';\n  }\n  return 'not connected';\n}\n\ntype AppTileProps = {\n  app: App;\n  anchor: Anchor;\n  isActive: boolean;\n  isDimmed: boolean;\n  isConnected: boolean;\n  isTabStop: boolean;\n  pressed: string | null;\n  onActivate: (id: App['id']) => void;\n  onConnect: (id: App['id']) => void;\n};\n\nexport function AppTile({\n  app,\n  anchor,\n  isActive,\n  isDimmed,\n  isConnected,\n  isTabStop,\n  pressed,\n  onActivate,\n  onConnect,\n}: AppTileProps) {\n  const shouldReduceMotion = usePrefersReducedMotion();\n  const cardId = useId();\n  const lift = liftOf(shouldReduceMotion);\n  const label = `${app.name}, ${stateWordOf(isConnected)}`;\n  let tabIndex = -1;\n  if (isTabStop) {\n    tabIndex = 0;\n  }\n  let describedBy: string | undefined;\n  if (isActive) {\n    describedBy = cardId;\n  }\n\n  function connectFromKeyboard(event: React.KeyboardEvent<HTMLButtonElement>) {\n    const isEnter = event.key === 'Enter';\n    const isSpace = event.key === ' ';\n    if (isEnter || isSpace) {\n      event.preventDefault();\n      onConnect(app.id);\n    }\n  }\n\n  return (\n    <li\n      data-app-item={app.id}\n      onPointerEnter={(event) => {\n        if (event.pointerType === 'mouse') {\n          onActivate(app.id);\n        }\n      }}\n      className='relative'\n    >\n      <button\n        type='button'\n        data-app-tile={app.id}\n        aria-label={label}\n        aria-describedby={describedBy}\n        tabIndex={tabIndex}\n        onFocus={() => onActivate(app.id)}\n        onClick={() => onActivate(app.id)}\n        onKeyDown={connectFromKeyboard}\n        className={cn(\n          'focus-visible:ring-ring focus-visible:ring-offset-background relative flex size-12 cursor-pointer items-center justify-center rounded-2xl transition-[background-color,opacity,translate] duration-150 ease-(--ease-out-strong) outline-none focus-visible:ring-2 focus-visible:ring-offset-2 @xs:size-14 @md:size-20',\n          toneOf(isActive, isDimmed)\n        )}\n      >\n        <BrandTile brand={app.brand} size='2xl' />\n        <AnimatePresence>\n          {isConnected && (\n            <span className='absolute -end-1 -top-1'>\n              <DrawnCheck tone='success' />\n            </span>\n          )}\n        </AnimatePresence>\n      </button>\n      <AnimatePresence>\n        {isActive && (\n          <motion.div\n            key='card'\n            id={cardId}\n            initial={lift.initial}\n            animate={lift.animate}\n            exit={lift.exit}\n            className={cn(\n              'surface-raised absolute top-full z-10 mt-2 flex w-60 flex-col gap-3 rounded-xl p-3 @md:w-64',\n              ANCHOR_CLASS[anchor]\n            )}\n          >\n            <div className='flex items-center gap-2'>\n              <BrandTile brand={app.brand} size='md' />\n              <p className='text-[13px] font-medium'>{app.name}</p>\n            </div>\n            <p className='text-muted-foreground text-xs text-pretty'>\n              {app.line}\n            </p>\n            <Swap swapKey={stateWordOf(isConnected)} className='self-start'>\n              {!isConnected && (\n                <Button\n                  type='button'\n                  size='sm'\n                  onClick={() => onConnect(app.id)}\n                  className={pressedSolidOf(pressed === `connect-${app.id}`)}\n                >\n                  Connect {app.name}\n                </Button>\n              )}\n              {isConnected && (\n                <span className='text-success-foreground flex h-7 items-center gap-1.5 text-xs font-medium'>\n                  <DrawnCheck tone='success' entrance='draw' />\n                  Connected\n                </span>\n              )}\n            </Swap>\n          </motion.div>\n        )}\n      </AnimatePresence>\n    </li>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/blocks/ai-product-06/app-tile.tsx"
    },
    {
      "path": "registry/ndeko/blocks/ai-product/ai-product-06/data.ts",
      "content": "import type { BrandSlug } from '@/registry/ndeko/lib/brand-logos';\n\nexport const SECTION = {\n  label: 'Connected apps',\n  title: 'The apps your agent can use',\n  lead: 'Point at an app to see what the agent does with it, then connect it.',\n};\n\nexport type AppId = 'notion' | 'linear' | 'github' | 'calendar' | 'gmail';\n\nexport type App = {\n  id: AppId;\n  name: string;\n  brand: BrandSlug;\n  line: string;\n};\n\nexport const APPS: App[] = [\n  {\n    id: 'notion',\n    name: 'Notion',\n    brand: 'notion',\n    line: 'Reads your pages and writes the weekly summary',\n  },\n  {\n    id: 'linear',\n    name: 'Linear',\n    brand: 'linear',\n    line: 'Opens issues and moves them when the work is done',\n  },\n  {\n    id: 'github',\n    name: 'GitHub',\n    brand: 'github',\n    line: 'Reviews pull requests and drafts release notes',\n  },\n  {\n    id: 'calendar',\n    name: 'Google Calendar',\n    brand: 'googlecalendar',\n    line: 'Finds a slot that suits everyone you invite',\n  },\n  {\n    id: 'gmail',\n    name: 'Gmail',\n    brand: 'gmail',\n    line: 'Drafts replies and waits for your go before sending',\n  },\n];\n\nexport const RESTING_ID: AppId = 'linear';\n\nexport const DEMO_CONNECT: AppId = 'github';\n\nexport function appOf(id: AppId) {\n  const app = APPS.find((candidate) => candidate.id === id);\n  return app ?? APPS[0];\n}\n",
      "type": "registry:component",
      "target": "components/blocks/ai-product-06/data.ts"
    }
  ],
  "categories": [
    "blocks",
    "ai-product"
  ],
  "type": "registry:block"
}