{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "changelog-03",
  "title": "What’s new popover",
  "description": "A What’s new button whose unread count rolls down as notes are read, opening a compact list with unread dots that clear, Mark all read and a link to each full note.",
  "dependencies": [
    "motion"
  ],
  "registryDependencies": [
    "https://ui.ndekocode.dev/r/badge.json",
    "https://ui.ndekocode.dev/r/button.json",
    "https://ui.ndekocode.dev/r/chip.json",
    "https://ui.ndekocode.dev/r/company-mark.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/recipes.json",
    "https://ui.ndekocode.dev/r/replay-button.json",
    "https://ui.ndekocode.dev/r/theme.json",
    "https://ui.ndekocode.dev/r/use-prefers-reduced-motion.json",
    "https://ui.ndekocode.dev/r/use-session.json",
    "https://ui.ndekocode.dev/r/utils.json"
  ],
  "files": [
    {
      "path": "registry/ndeko/blocks/changelog/changelog-03/index.tsx",
      "content": "'use client';\n\nimport { AnimatePresence, motion } from 'motion/react';\nimport { useEffect, useId, useRef } from 'react';\n\nimport { MotionNumber } from '@/components/core/motion-number';\nimport { usePrefersReducedMotion } from '@/registry/ndeko/hooks/use-prefers-reduced-motion';\nimport { useSession } from '@/registry/ndeko/hooks/use-session';\nimport {\n  pressedQuietOf,\n  spokenUnless,\n} from '@/registry/ndeko/lib/demonstration';\nimport { ArrowRightIcon, BellIcon } from '@/registry/ndeko/lib/icons';\nimport { cn } from '@/registry/ndeko/lib/utils';\nimport { Badge } from '@/registry/ndeko/ui/badge';\nimport { Button } from '@/registry/ndeko/ui/button';\nimport { CompanyMark } from '@/registry/ndeko/ui/company-mark';\nimport { DrawnCheck } from '@/registry/ndeko/ui/drawn-check';\nimport { LiveRegion } from '@/registry/ndeko/ui/live-region';\nimport { ReplayButton } from '@/registry/ndeko/ui/replay-button';\n\nimport { APP, NOTES } from './data';\nimport { NewsRow } from './news-row';\nimport {\n  INITIAL,\n  LOOP_AFTER_MS,\n  reducer,\n  RESTING,\n  SCRIPT,\n  unreadCountOf,\n} from './session';\n\nconst SESSION = {\n  reducer,\n  initial: INITIAL,\n  resting: RESTING,\n  script: SCRIPT,\n  loopAfter: LOOP_AFTER_MS,\n};\n\nconst PANEL_SHOWN = { opacity: 1, scale: 1 };\n\nconst PANEL_HIDDEN = { opacity: 0, scale: 0.95 };\n\nconst PANEL_FADED = { opacity: 0, scale: 1 };\n\nconst PANEL_ARRIVE = { duration: 0.15, ease: [0.23, 1, 0.32, 1] as const };\n\nconst PANEL_LEAVE = { duration: 0.1, ease: [0.23, 1, 0.32, 1] as const };\n\nfunction panelStartOf(shouldReduceMotion: boolean) {\n  if (shouldReduceMotion) {\n    return PANEL_FADED;\n  }\n  return PANEL_HIDDEN;\n}\n\nconst PILL_SHOWN = { opacity: 1, scale: 1 };\n\nconst PILL_HIDDEN = { opacity: 0, scale: 0.6 };\n\nconst PILL_TRANSITION = { duration: 0.15, ease: [0.2, 0, 0, 1] as const };\n\nfunction pillStartOf(shouldReduceMotion: boolean) {\n  if (shouldReduceMotion) {\n    return PANEL_FADED;\n  }\n  return PILL_HIDDEN;\n}\n\nfunction spokenLineOf(unread: number) {\n  if (unread === 0) {\n    return 'You are up to date';\n  }\n  if (unread === 1) {\n    return '1 note unread';\n  }\n  return `${unread} notes unread`;\n}\n\nexport default function Changelog03() {\n  const { ref, isAutoplaying, state, act, pressed, isFinished, restart } =\n    useSession(SESSION);\n  const shouldReduceMotion = usePrefersReducedMotion();\n  const panelId = useId();\n  const triggerRef = useRef<HTMLButtonElement>(null);\n  const wrapperRef = useRef<HTMLDivElement>(null);\n  const { isOpen, readIds } = state;\n  const unread = unreadCountOf(readIds);\n  const hasUnread = unread > 0;\n  const message = spokenUnless(isAutoplaying, spokenLineOf(unread));\n  const canReplay = isFinished && !isAutoplaying;\n  const listensOutside = isOpen && !isAutoplaying;\n\n  useEffect(() => {\n    if (!listensOutside) {\n      return;\n    }\n    function closeFromOutside(event: PointerEvent) {\n      const wrapper = wrapperRef.current;\n      const target = event.target;\n      const isInside = target instanceof Node && wrapper?.contains(target);\n      if (!isInside) {\n        act({ type: 'closed' });\n      }\n    }\n    document.addEventListener('pointerdown', closeFromOutside);\n    return () => document.removeEventListener('pointerdown', closeFromOutside);\n  }, [listensOutside, act]);\n\n  function toggle() {\n    if (isOpen) {\n      act({ type: 'closed' });\n      return;\n    }\n    act({ type: 'opened' });\n  }\n\n  function closeOnEscape(event: React.KeyboardEvent<HTMLDivElement>) {\n    if (event.key === 'Escape' && isOpen) {\n      event.preventDefault();\n      act({ type: 'closed' });\n      triggerRef.current?.focus();\n    }\n  }\n\n  return (\n    <div ref={ref} className='@container px-4 py-10 @2xl:px-6 @2xl:py-16'>\n      <div className='bg-card hairline-ring ring-border dark:bg-foreground/[0.03] relative mx-auto min-h-[30rem] max-w-3xl rounded-2xl shadow-[0_1px_2px_rgb(0_0_0/0.04)]'>\n        <header className='flex h-14 items-center gap-2 px-4'>\n          <CompanyMark seed={APP.name} size='lg' />\n          <span className='text-sm font-semibold'>{APP.name}</span>\n          <div className='ms-auto flex items-center gap-2'>\n            <ReplayButton\n              isShown={canReplay}\n              onReplay={restart}\n              label='Replay'\n            />\n            <div\n              ref={wrapperRef}\n              onKeyDown={closeOnEscape}\n              className='relative'\n            >\n              <Button\n                ref={triggerRef}\n                type='button'\n                variant='outline'\n                aria-expanded={isOpen}\n                aria-haspopup='dialog'\n                aria-controls={panelId}\n                onClick={toggle}\n                className={cn(pressedQuietOf(pressed === 'trigger'))}\n              >\n                <BellIcon />\n                What’s new\n                <AnimatePresence initial={false}>\n                  {hasUnread && (\n                    <motion.span\n                      key='unread'\n                      initial={pillStartOf(shouldReduceMotion)}\n                      animate={PILL_SHOWN}\n                      exit={pillStartOf(shouldReduceMotion)}\n                      transition={PILL_TRANSITION}\n                      className='bg-primary text-primary-foreground flex h-4 min-w-4 items-center justify-center rounded-full px-1 text-[11px] font-medium'\n                    >\n                      <MotionNumber value={unread} />\n                      <span className='sr-only'> unread</span>\n                    </motion.span>\n                  )}\n                </AnimatePresence>\n              </Button>\n              <AnimatePresence initial={false}>\n                {isOpen && (\n                  <motion.div\n                    key='panel'\n                    id={panelId}\n                    role='dialog'\n                    aria-label='What’s new'\n                    initial={panelStartOf(shouldReduceMotion)}\n                    animate={PANEL_SHOWN}\n                    exit={{\n                      ...panelStartOf(shouldReduceMotion),\n                      transition: PANEL_LEAVE,\n                    }}\n                    transition={PANEL_ARRIVE}\n                    className='surface-raised absolute end-0 top-full z-10 mt-2 w-[min(22rem,calc(100cqw_-_2rem))] origin-top-right rounded-xl'\n                  >\n                    <div className='flex items-center justify-between gap-2 px-3.5 pt-3 pb-1'>\n                      <h3 className='text-sm font-medium'>What’s new</h3>\n                      <Button\n                        type='button'\n                        variant='ghost'\n                        size='sm'\n                        disabled={!hasUnread}\n                        onClick={() => act({ type: 'allRead' })}\n                        className={cn(\n                          'text-primary-ink',\n                          pressedQuietOf(pressed === 'mark-all')\n                        )}\n                      >\n                        Mark all read\n                      </Button>\n                    </div>\n                    <ul className='flex flex-col p-1.5'>\n                      {NOTES.map((note) => (\n                        <NewsRow\n                          key={note.id}\n                          note={note}\n                          isUnread={!readIds.includes(note.id)}\n                          isPressed={pressed === `note-${note.id}`}\n                          onRead={(id) => act({ type: 'read', id })}\n                        />\n                      ))}\n                    </ul>\n                    <div className='flex min-h-11 items-center justify-between gap-3 px-3.5 pb-3'>\n                      <p className='text-muted-foreground flex items-center gap-1.5 text-xs'>\n                        {!hasUnread && (\n                          <>\n                            <DrawnCheck tone='success' entrance='draw' />\n                            You are up to date\n                          </>\n                        )}\n                      </p>\n                      <Button\n                        variant='ghost'\n                        size='sm'\n                        nativeButton={false}\n                        render={<a href={APP.allNotesHref} />}\n                      >\n                        All release notes\n                        <ArrowRightIcon />\n                      </Button>\n                    </div>\n                  </motion.div>\n                )}\n              </AnimatePresence>\n            </div>\n          </div>\n        </header>\n        <div className='px-4 pt-2'>\n          <Badge variant='secondary'>{APP.badge}</Badge>\n        </div>\n      </div>\n      <LiveRegion message={message} />\n    </div>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/blocks/changelog-03/index.tsx"
    },
    {
      "path": "registry/ndeko/blocks/changelog/changelog-03/news-row.tsx",
      "content": "'use client';\n\nimport { pressedQuietOf } from '@/registry/ndeko/lib/demonstration';\nimport { FOCUS_RING } from '@/registry/ndeko/lib/recipes';\nimport { cn } from '@/registry/ndeko/lib/utils';\nimport { Chip } from '@/registry/ndeko/ui/chip';\n\nimport { KIND_STYLES, type Note } from './data';\n\nfunction dotOf(isUnread: boolean) {\n  if (isUnread) {\n    return 'scale-100 opacity-100';\n  }\n  return 'scale-0 opacity-0';\n}\n\nfunction titleToneOf(isUnread: boolean) {\n  if (isUnread) {\n    return 'font-medium text-foreground';\n  }\n  return 'text-muted-foreground';\n}\n\ntype NewsRowProps = {\n  note: Note;\n  isUnread: boolean;\n  isPressed: boolean;\n  onRead: (id: string) => void;\n};\n\nexport function NewsRow({ note, isUnread, isPressed, onRead }: NewsRowProps) {\n  const kind = KIND_STYLES[note.kind];\n\n  return (\n    <li>\n      <a\n        href={note.href}\n        onClick={() => onRead(note.id)}\n        className={cn(\n          'hover:bg-foreground/[0.04] flex items-start gap-3 rounded-md px-2.5 py-2.5 transition-colors duration-100',\n          pressedQuietOf(isPressed),\n          FOCUS_RING\n        )}\n      >\n        <span\n          aria-hidden='true'\n          className='mt-[7px] flex size-2 shrink-0 items-center justify-center'\n        >\n          <span\n            className={cn(\n              'bg-primary size-2 rounded-full transition-[scale,opacity] duration-200 ease-(--ease-out-strong)',\n              dotOf(isUnread)\n            )}\n          />\n        </span>\n        <span className='flex min-w-0 flex-1 flex-col gap-0.5'>\n          <span className='flex items-baseline gap-2'>\n            <span\n              className={cn(\n                'min-w-0 flex-1 truncate text-[13px] transition-colors duration-200',\n                titleToneOf(isUnread)\n              )}\n            >\n              {note.title}\n              {isUnread && <span className='sr-only'>, unread</span>}\n            </span>\n            <span className='text-muted-foreground shrink-0 text-xs tabular-nums'>\n              {note.date}\n            </span>\n          </span>\n          <span className='text-muted-foreground line-clamp-1 text-xs'>\n            {note.summary}\n          </span>\n        </span>\n        <Chip color={kind.color} className='mt-0.5 hidden @sm:inline-flex'>\n          {kind.label}\n        </Chip>\n      </a>\n    </li>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/blocks/changelog-03/news-row.tsx"
    },
    {
      "path": "registry/ndeko/blocks/changelog/changelog-03/session.ts",
      "content": "import type { SessionStep } from '@/registry/ndeko/hooks/use-session';\n\nimport { NOTES, READ_AT_START } from './data';\n\nexport type NewsState = {\n  isOpen: boolean;\n  readIds: string[];\n};\n\nexport type NewsAction =\n  | { type: 'opened' }\n  | { type: 'closed' }\n  | { type: 'read'; id: string }\n  | { type: 'allRead' };\n\ntype Step = SessionStep<NewsState, NewsAction>;\n\nexport const INITIAL: NewsState = {\n  isOpen: false,\n  readIds: READ_AT_START,\n};\n\nexport function unreadCountOf(readIds: string[]) {\n  const unread = NOTES.filter((note) => !readIds.includes(note.id));\n  return unread.length;\n}\n\nfunction read(state: NewsState, id: string): NewsState {\n  if (state.readIds.includes(id)) {\n    return state;\n  }\n  return { ...state, readIds: [...state.readIds, id] };\n}\n\nexport function reducer(state: NewsState, action: NewsAction): NewsState {\n  switch (action.type) {\n    case 'opened':\n      return { ...state, isOpen: true };\n    case 'closed':\n      return { ...state, isOpen: false };\n    case 'read':\n      return read(state, action.id);\n    case 'allRead':\n      return { ...state, readIds: NOTES.map((note) => note.id) };\n  }\n}\n\n/**\n * Someone opens the list, reads two notes so the count rolls down, marks the rest as read and\n * closes it: a round ends with nothing left to read, and starts again with three unread.\n */\nexport const SCRIPT: Step[] = [\n  {\n    after: 2000,\n    by: 'demo',\n    press: 'trigger',\n    action: { type: 'opened' },\n  },\n  {\n    after: 2200,\n    by: 'demo',\n    press: 'note-quiet-hours',\n    action: { type: 'read', id: 'quiet-hours' },\n  },\n  {\n    after: 1500,\n    by: 'demo',\n    press: 'note-zone-strip',\n    action: { type: 'read', id: 'zone-strip' },\n  },\n  {\n    after: 1800,\n    by: 'demo',\n    press: 'mark-all',\n    action: { type: 'allRead' },\n  },\n  {\n    after: 1900,\n    by: 'demo',\n    press: 'trigger',\n    action: { type: 'closed' },\n  },\n];\n\n/** Under reduced motion the list is open with three notes still unread. */\nexport const RESTING: NewsState = {\n  isOpen: true,\n  readIds: READ_AT_START,\n};\n\nexport const LOOP_AFTER_MS = 2600;\n",
      "type": "registry:component",
      "target": "components/blocks/changelog-03/session.ts"
    },
    {
      "path": "registry/ndeko/blocks/changelog/changelog-03/data.ts",
      "content": "export type ChangeKind = 'new' | 'improved' | 'fixed';\n\nexport type Note = {\n  id: string;\n  date: string;\n  title: string;\n  kind: ChangeKind;\n  summary: string;\n  href: string;\n};\n\nexport const KIND_STYLES: Record<ChangeKind, { label: string; color: string }> =\n  {\n    new: { label: 'New', color: 'var(--primary)' },\n    improved: { label: 'Improved', color: 'var(--info)' },\n    fixed: { label: 'Fixed', color: 'var(--success)' },\n  };\n\nexport const APP = {\n  name: 'Tidepool',\n  badge: 'Sample release notes',\n  allNotesHref: '#all-release-notes',\n};\n\nexport const NOTES: Note[] = [\n  {\n    id: 'quiet-hours',\n    date: '27 Oct',\n    title: 'Quiet hours for every teammate',\n    kind: 'new',\n    summary: 'Invites inside your quiet hours suggest other times.',\n    href: '#note-quiet-hours',\n  },\n  {\n    id: 'zone-strip',\n    date: '14 Oct',\n    title: 'A time zone strip on every invite',\n    kind: 'improved',\n    summary: 'See each guest’s local time, from Kinshasa to Lisbon.',\n    href: '#note-zone-strip',\n  },\n  {\n    id: 'recurring-shift',\n    date: '6 Oct',\n    title: 'Recurring events keep their place',\n    kind: 'fixed',\n    summary: 'A weekly event no longer moves when clocks change.',\n    href: '#note-recurring-shift',\n  },\n  {\n    id: 'room-search',\n    date: '23 Sep',\n    title: 'Find a room by what it has',\n    kind: 'new',\n    summary: 'Search free rooms by screen, whiteboard or seats.',\n    href: '#note-room-search',\n  },\n  {\n    id: 'agenda-notes',\n    date: '9 Sep',\n    title: 'Agenda notes follow the event',\n    kind: 'improved',\n    summary: 'Notes stay with a meeting when it moves to another day.',\n    href: '#note-agenda-notes',\n  },\n];\n\nexport const READ_AT_START: string[] = ['room-search', 'agenda-notes'];\n",
      "type": "registry:component",
      "target": "components/blocks/changelog-03/data.ts"
    }
  ],
  "categories": [
    "blocks",
    "changelog"
  ],
  "type": "registry:block"
}