{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "event-calendar-06",
  "title": "Agenda",
  "description": "The next thirty days as a list grouped by day, with the time, title and place of every event",
  "dependencies": [
    "@dnd-kit/core",
    "date-fns",
    "motion",
    "sonner"
  ],
  "registryDependencies": [
    "https://ui.ndekocode.dev/r/animated-size.json",
    "https://ui.ndekocode.dev/r/button.json",
    "https://ui.ndekocode.dev/r/calendar.json",
    "https://ui.ndekocode.dev/r/checkbox.json",
    "https://ui.ndekocode.dev/r/dialog.json",
    "https://ui.ndekocode.dev/r/icons.json",
    "https://ui.ndekocode.dev/r/input.json",
    "https://ui.ndekocode.dev/r/label.json",
    "https://ui.ndekocode.dev/r/popover.json",
    "https://ui.ndekocode.dev/r/radio-group.json",
    "https://ui.ndekocode.dev/r/recipes.json",
    "https://ui.ndekocode.dev/r/select.json",
    "https://ui.ndekocode.dev/r/tabs.json",
    "https://ui.ndekocode.dev/r/textarea.json",
    "https://ui.ndekocode.dev/r/theme.json",
    "https://ui.ndekocode.dev/r/use-prefers-reduced-motion.json",
    "https://ui.ndekocode.dev/r/utils.json"
  ],
  "files": [
    {
      "path": "registry/ndeko/components/event-calendar/event-calendar-06.tsx",
      "content": "'use client';\n\nimport { EventCalendar, useEventList } from './_parts';\nimport { buildSampleEvents } from './_parts/sample-events';\n\nexport default function EventCalendar06() {\n  const { events, addEvent, updateEvent, deleteEvent } =\n    useEventList(buildSampleEvents);\n\n  return (\n    <EventCalendar\n      views={['agenda']}\n      events={events}\n      onEventAdd={addEvent}\n      onEventUpdate={updateEvent}\n      onEventDelete={deleteEvent}\n    />\n  );\n}\n",
      "type": "registry:component",
      "target": "components/event-calendar/event-calendar-06.tsx"
    },
    {
      "path": "registry/ndeko/components/event-calendar/_parts/agenda-view.tsx",
      "content": "'use client';\n\nimport { addDays, format, isSameMonth, isToday } from 'date-fns';\nimport { useMemo } from 'react';\n\nimport { CalendarIcon } from '@/registry/ndeko/lib/icons';\n\nimport { AgendaDaysToShow } from './constants';\nimport { EventListRow } from './event-list-row';\nimport { dayKeyOf } from './navigation';\nimport type { CalendarEvent } from './types';\nimport { getAgendaEventsForDay } from './utils';\n\ntype AgendaViewProps = {\n  currentDate: Date;\n  events: CalendarEvent[];\n  onEventSelect: (event: CalendarEvent) => void;\n};\n\ntype AgendaDay = {\n  day: Date;\n  events: CalendarEvent[];\n};\n\nfunction AgendaEmptyState() {\n  return (\n    <div className='flex flex-col items-center justify-center gap-1 px-4 py-20 text-center'>\n      <span className='keycap-3d text-muted-foreground mb-2 flex size-10 items-center justify-center rounded-lg'>\n        <CalendarIcon className='size-5' />\n      </span>\n      <h3 className='text-sm font-medium'>\n        No events in these {AgendaDaysToShow} days\n      </h3>\n      <p className='text-muted-foreground text-[13px]'>\n        Pick New event to plan one.\n      </p>\n    </div>\n  );\n}\n\nfunction agendaDayLabelOf(day: Date) {\n  const date = format(day, 'EEEE, MMMM d');\n  if (isToday(day)) {\n    return `Today, ${date}`;\n  }\n  return date;\n}\n\nfunction showsMonthOf(agendaDays: AgendaDay[], index: number) {\n  if (index === 0) {\n    return true;\n  }\n  const previousDay = agendaDays[index - 1].day;\n  return !isSameMonth(previousDay, agendaDays[index].day);\n}\n\ntype AgendaDateProps = {\n  day: Date;\n  showsMonth: boolean;\n};\n\nfunction AgendaDate({ day, showsMonth }: AgendaDateProps) {\n  const isTodayDay = isToday(day);\n\n  return (\n    <div\n      aria-hidden='true'\n      className='group/date flex flex-col items-center pt-1.5 leading-none'\n      data-today={isTodayDay || undefined}\n    >\n      <span className='text-muted-foreground group-data-today/date:text-primary-ink text-xs'>\n        {format(day, 'EEE')}\n      </span>\n      <span className='group-data-today/date:text-primary-ink mt-1 text-lg font-semibold tabular-nums'>\n        {format(day, 'd')}\n      </span>\n      {showsMonth && (\n        <span className='text-muted-foreground mt-1 text-[11px]'>\n          {format(day, 'MMM')}\n        </span>\n      )}\n    </div>\n  );\n}\n\nexport function AgendaView({\n  currentDate,\n  events,\n  onEventSelect,\n}: AgendaViewProps) {\n  const agendaDays = useMemo(() => {\n    const days = Array.from({ length: AgendaDaysToShow }, (_, index) =>\n      addDays(currentDate, index)\n    );\n    const withEvents = days.map((day) => ({\n      day,\n      events: getAgendaEventsForDay(events, day),\n    }));\n    return withEvents.filter((agendaDay) => agendaDay.events.length > 0);\n  }, [currentDate, events]);\n  const hasEvents = agendaDays.length > 0;\n\n  return (\n    <div\n      data-slot='agenda-view'\n      className='hairline-t border-border max-h-(--calendar-scroll-height) min-h-0 flex-1 overflow-y-auto'\n    >\n      {!hasEvents && <AgendaEmptyState />}\n      {hasEvents && (\n        <ol className='flex flex-col gap-4 p-2 @2xl:p-3'>\n          {agendaDays.map((agendaDay, index) => (\n            <li\n              key={dayKeyOf(agendaDay.day)}\n              className='grid grid-cols-[3rem_minmax(0,1fr)] gap-1 @2xl:grid-cols-[3.5rem_minmax(0,1fr)] @2xl:gap-2'\n            >\n              <AgendaDate\n                day={agendaDay.day}\n                showsMonth={showsMonthOf(agendaDays, index)}\n              />\n              <ul\n                className='flex flex-col'\n                aria-label={agendaDayLabelOf(agendaDay.day)}\n              >\n                {agendaDay.events.map((event) => (\n                  <li key={event.id}>\n                    <EventListRow\n                      event={event}\n                      day={agendaDay.day}\n                      onClick={() => onEventSelect(event)}\n                    />\n                  </li>\n                ))}\n              </ul>\n            </li>\n          ))}\n        </ol>\n      )}\n    </div>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/event-calendar/_parts/agenda-view.tsx"
    },
    {
      "path": "registry/ndeko/components/event-calendar/_parts/calendar-dnd-context.tsx",
      "content": "'use client';\n\nimport {\n  DndContext,\n  DragOverlay,\n  MouseSensor,\n  PointerSensor,\n  TouchSensor,\n  useSensor,\n  useSensors,\n  type DragEndEvent,\n  type DragOverEvent,\n  type DragStartEvent,\n  type UniqueIdentifier,\n} from '@dnd-kit/core';\nimport {\n  addMinutes,\n  differenceInMinutes,\n  isSameDay,\n  isSameMinute,\n} from 'date-fns';\nimport { motion, type Transition } from 'motion/react';\nimport { createContext, useContext, useId, useState } from 'react';\n\nimport { usePrefersReducedMotion } from '@/registry/ndeko/hooks/use-prefers-reduced-motion';\n\nimport { EventItem } from './event-item';\nimport type { CalendarEvent, TimedView } from './types';\n\nexport const DROP_SPRING: Transition = {\n  type: 'spring',\n  bounce: 0,\n  duration: 0.35,\n};\n\ntype DragState = {\n  activeEvent: CalendarEvent | null;\n  activeId: UniqueIdentifier | null;\n  activeView: TimedView | null;\n  currentTime: Date | null;\n  eventHeight: number | null;\n};\n\ntype CalendarDndContextValue = DragState & {\n  droppedEventId: string | null;\n  clearDroppedEvent: () => void;\n};\n\ntype ActiveData = {\n  event: CalendarEvent;\n  view: TimedView;\n  height?: number | null;\n};\n\ntype OverData = { date: Date; time?: number };\n\nconst IDLE_DRAG: DragState = {\n  activeEvent: null,\n  activeId: null,\n  activeView: null,\n  currentTime: null,\n  eventHeight: null,\n};\n\nconst CalendarDndContext = createContext<CalendarDndContextValue>({\n  ...IDLE_DRAG,\n  droppedEventId: null,\n  clearDroppedEvent: () => undefined,\n});\n\nexport function useCalendarDnd() {\n  return useContext(CalendarDndContext);\n}\n\n/** The minutes of a slot, rounded to the closest quarter hour. */\nfunction quarterMinutesOf(fractionalHour: number) {\n  if (fractionalHour < 0.125) {\n    return 0;\n  }\n  if (fractionalHour < 0.375) {\n    return 15;\n  }\n  if (fractionalHour < 0.625) {\n    return 30;\n  }\n  return 45;\n}\n\nfunction slotTimeOf(date: Date, time: number) {\n  const slotTime = new Date(date);\n  const hours = Math.floor(time);\n  const minutes = quarterMinutesOf(time - hours);\n  slotTime.setHours(hours, minutes, 0, 0);\n  return slotTime;\n}\n\nfunction sameTimeOnDay(date: Date, time: Date) {\n  const moved = new Date(date);\n  moved.setHours(\n    time.getHours(),\n    time.getMinutes(),\n    time.getSeconds(),\n    time.getMilliseconds()\n  );\n  return moved;\n}\n\nfunction overlayHeightOf(eventHeight: number | null) {\n  if (eventHeight) {\n    return `${eventHeight}px`;\n  }\n  return 'auto';\n}\n\nfunction overlayLayoutIdOf(\n  event: CalendarEvent,\n  shouldReduceMotion: boolean | null\n) {\n  if (shouldReduceMotion) {\n    return undefined;\n  }\n  return `dropped-event-${event.id}`;\n}\n\nfunction DragPreview({ drag }: { drag: DragState }) {\n  const shouldReduceMotion = usePrefersReducedMotion();\n  const { activeEvent, activeView } = drag;\n  if (!activeEvent || !activeView) {\n    return null;\n  }\n\n  return (\n    <motion.div\n      layoutId={overlayLayoutIdOf(activeEvent, shouldReduceMotion)}\n      transition={DROP_SPRING}\n      style={{ height: overlayHeightOf(drag.eventHeight) }}\n    >\n      <EventItem\n        event={activeEvent}\n        view={activeView}\n        isDragging\n        showTime={activeView !== 'month'}\n        currentTime={drag.currentTime ?? undefined}\n      />\n    </motion.div>\n  );\n}\n\ntype CalendarDndProviderProps = {\n  children: React.ReactNode;\n  onEventUpdate: (event: CalendarEvent) => void;\n};\n\nexport function CalendarDndProvider({\n  children,\n  onEventUpdate,\n}: CalendarDndProviderProps) {\n  const [drag, setDrag] = useState<DragState>(IDLE_DRAG);\n  const [droppedEventId, setDroppedEventId] = useState<string | null>(null);\n  const dndContextId = useId();\n\n  const sensors = useSensors(\n    useSensor(MouseSensor, { activationConstraint: { distance: 5 } }),\n    useSensor(TouchSensor, {\n      activationConstraint: { delay: 250, tolerance: 5 },\n    }),\n    useSensor(PointerSensor, { activationConstraint: { distance: 5 } })\n  );\n\n  function clearDroppedEvent() {\n    setDroppedEventId(null);\n  }\n\n  function handleDragStart({ active }: DragStartEvent) {\n    const data = active.data.current as ActiveData | undefined;\n    if (!data) {\n      return;\n    }\n    setDrag({\n      activeEvent: data.event,\n      activeId: active.id,\n      activeView: data.view,\n      currentTime: new Date(data.event.start),\n      eventHeight: data.height ?? null,\n    });\n  }\n\n  function handleDragOver({ over }: DragOverEvent) {\n    const overData = over?.data.current as OverData | undefined;\n    if (!overData) {\n      return;\n    }\n    if (!drag.activeEvent) {\n      return;\n    }\n    const isTimeSlot = overData.time !== undefined;\n    const isTimeGrid = drag.activeView !== 'month';\n    const currentTime = drag.currentTime;\n\n    if (isTimeSlot && isTimeGrid) {\n      const slotTime = slotTimeOf(overData.date, overData.time ?? 0);\n      const hasMoved = !currentTime || !isSameMinute(slotTime, currentTime);\n      if (hasMoved) {\n        setDrag((state) => ({ ...state, currentTime: slotTime }));\n      }\n      return;\n    }\n\n    if (drag.activeView !== 'month') {\n      return;\n    }\n    let dayTime = new Date(overData.date);\n    if (currentTime) {\n      dayTime = sameTimeOnDay(overData.date, currentTime);\n    }\n    const hasChangedDay = !currentTime || !isSameDay(dayTime, currentTime);\n    if (hasChangedDay) {\n      setDrag((state) => ({ ...state, currentTime: dayTime }));\n    }\n  }\n\n  function moveEvent(\n    over: NonNullable<DragEndEvent['over']>,\n    currentTime: Date\n  ) {\n    const activeEvent = drag.activeEvent;\n    const overData = over.data.current as OverData | undefined;\n    if (!activeEvent) {\n      return;\n    }\n    if (!overData?.date) {\n      return;\n    }\n\n    let newStart = sameTimeOnDay(overData.date, currentTime);\n    if (overData.time !== undefined) {\n      newStart = slotTimeOf(overData.date, overData.time);\n    }\n    const originalStart = new Date(activeEvent.start);\n    const originalEnd = new Date(activeEvent.end);\n    const durationMinutes = differenceInMinutes(originalEnd, originalStart);\n    const newEnd = addMinutes(newStart, durationMinutes);\n    const hasStartTimeChanged = !isSameMinute(originalStart, newStart);\n\n    if (hasStartTimeChanged) {\n      onEventUpdate({ ...activeEvent, start: newStart, end: newEnd });\n      setDroppedEventId(activeEvent.id);\n    }\n  }\n\n  function handleDragEnd({ over }: DragEndEvent) {\n    const currentTime = drag.currentTime;\n    setDrag(IDLE_DRAG);\n    if (!over) {\n      return;\n    }\n    if (!currentTime) {\n      return;\n    }\n    moveEvent(over, currentTime);\n  }\n\n  const contextValue: CalendarDndContextValue = {\n    ...drag,\n    droppedEventId,\n    clearDroppedEvent,\n  };\n\n  return (\n    <DndContext\n      id={dndContextId}\n      sensors={sensors}\n      onDragStart={handleDragStart}\n      onDragOver={handleDragOver}\n      onDragEnd={handleDragEnd}\n      onDragCancel={() => setDrag(IDLE_DRAG)}\n    >\n      <CalendarDndContext.Provider value={contextValue}>\n        {children}\n\n        <DragOverlay adjustScale={false} dropAnimation={null}>\n          <DragPreview drag={drag} />\n        </DragOverlay>\n      </CalendarDndContext.Provider>\n    </DndContext>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/event-calendar/_parts/calendar-dnd-context.tsx"
    },
    {
      "path": "registry/ndeko/components/event-calendar/_parts/calendar-header.tsx",
      "content": "'use client';\n\nimport {\n  AnimatePresence,\n  motion,\n  type Transition,\n  type Variants,\n} from 'motion/react';\n\nimport { usePrefersReducedMotion } from '@/registry/ndeko/hooks/use-prefers-reduced-motion';\nimport { ChevronLeftIcon, ChevronRightIcon } from '@/registry/ndeko/lib/icons';\nimport { cn } from '@/registry/ndeko/lib/utils';\nimport { Button } from '@/registry/ndeko/ui/button';\n\nimport {\n  periodCaptionOf,\n  periodKeyOf,\n  periodTitleOf,\n  periodUnitOf,\n} from './navigation';\nimport type { CalendarView } from './types';\n\nconst TITLE_SHIFT_PX = 6;\n\nconst TITLE_TRANSITION: Transition = {\n  duration: 0.2,\n  ease: [0.23, 1, 0.32, 1],\n};\n\nconst TITLE_EXIT: Transition = { duration: 0.1, ease: [0.23, 1, 0.32, 1] };\n\nconst TITLE_VARIANTS: Variants = {\n  enter: (direction: number) => {\n    const offset = direction * TITLE_SHIFT_PX;\n    return { opacity: 0, x: offset };\n  },\n  visible: { opacity: 1, x: 0 },\n  exit: (direction: number) => {\n    const offset = direction * TITLE_SHIFT_PX;\n    return { opacity: 0, x: -offset, transition: TITLE_EXIT };\n  },\n};\n\nconst FADE_VARIANTS: Variants = {\n  enter: { opacity: 0 },\n  visible: { opacity: 1 },\n  exit: { opacity: 0, transition: TITLE_EXIT },\n};\n\nfunction titleVariantsOf(shouldReduceMotion: boolean | null) {\n  if (shouldReduceMotion) {\n    return FADE_VARIANTS;\n  }\n  return TITLE_VARIANTS;\n}\n\ntype PeriodHeadingProps = {\n  view: CalendarView;\n  date: Date;\n  direction: number;\n};\n\n/** The period on screen. Only the heading answers previous and next, with a short nudge. */\nfunction PeriodHeading({ view, date, direction }: PeriodHeadingProps) {\n  const shouldReduceMotion = usePrefersReducedMotion();\n  const title = periodTitleOf(date, view);\n  const caption = periodCaptionOf(date, view);\n  const titleKey = `${view}-${periodKeyOf(date, view)}`;\n\n  return (\n    <div className='flex min-w-0 flex-1 items-baseline gap-2'>\n      <h2 className='relative flex min-w-0 text-sm font-semibold @2xl:text-base'>\n        <span className='sr-only' aria-live='polite'>\n          {title.full}\n        </span>\n        <AnimatePresence mode='popLayout' initial={false} custom={direction}>\n          <motion.span\n            key={titleKey}\n            aria-hidden='true'\n            className='min-w-0 truncate'\n            custom={direction}\n            variants={titleVariantsOf(shouldReduceMotion)}\n            initial='enter'\n            animate='visible'\n            exit='exit'\n            transition={TITLE_TRANSITION}\n          >\n            <span className='@xl:hidden'>{title.short}</span>\n            <span className='hidden @xl:inline'>{title.full}</span>\n          </motion.span>\n        </AnimatePresence>\n      </h2>\n      {caption && (\n        <span className='text-muted-foreground hidden shrink-0 text-xs @3xl:inline'>\n          {caption}\n        </span>\n      )}\n    </div>\n  );\n}\n\ntype CalendarHeaderProps = {\n  view: CalendarView;\n  date: Date;\n  /** `1` after next, `-1` after previous, `0` when the view changes. */\n  direction: number;\n  onPrevious: () => void;\n  onNext: () => void;\n  onToday: () => void;\n  /** Placed before Today, for example a button that opens a sidebar. */\n  start?: React.ReactNode;\n  /** Placed after the heading: the view switcher and the actions. */\n  children?: React.ReactNode;\n  className?: string;\n};\n\n/**\n * Today, previous and next, and the period heading. On a narrow calendar the children wrap\n * under it; a child with `order-last w-full` takes the second row on its own.\n */\nexport function CalendarHeader({\n  view,\n  date,\n  direction,\n  onPrevious,\n  onNext,\n  onToday,\n  start,\n  children,\n  className,\n}: CalendarHeaderProps) {\n  const unit = periodUnitOf(view);\n\n  return (\n    <div\n      className={cn(\n        'flex flex-wrap items-center gap-2 p-3 @2xl:flex-nowrap @2xl:gap-3 @2xl:px-4',\n        className\n      )}\n    >\n      {start}\n      <Button variant='outline' onClick={onToday}>\n        Today\n      </Button>\n      <div className='flex items-center'>\n        <Button\n          variant='ghost'\n          size='icon'\n          aria-label={`Previous ${unit}`}\n          onClick={onPrevious}\n        >\n          <ChevronLeftIcon />\n        </Button>\n        <Button\n          variant='ghost'\n          size='icon'\n          aria-label={`Next ${unit}`}\n          onClick={onNext}\n        >\n          <ChevronRightIcon />\n        </Button>\n      </div>\n      <PeriodHeading view={view} date={date} direction={direction} />\n      {children}\n    </div>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/event-calendar/_parts/calendar-header.tsx"
    },
    {
      "path": "registry/ndeko/components/event-calendar/_parts/constants.ts",
      "content": "import type { CalendarView, EventColor, EventColorOption } from './types';\n\nexport const EventHeight = 24;\n\nexport const EventGap = 4;\n\nexport const WeekCellsHeight = 64;\n\nexport const AgendaDaysToShow = 30;\n\nexport const StartHour = 0;\nexport const EndHour = 24;\n\nexport const DefaultStartHour = 9;\nexport const DefaultEndHour = 10;\n\n/** The hour the week and day grids open on, so the morning shows without scrolling. */\nexport const ScrollToHour = 7;\n\nexport const WeekStartsOn = 0;\n\n/** Height of the scrolling time grid and agenda when the calendar sizes itself to its content. */\nexport const ScrollAreaHeight = '34rem';\n\nexport const DefaultEventColor: EventColor = 'info';\n\nexport const EventColors: EventColorOption[] = [\n  { value: 'info', label: 'Blue' },\n  { value: 'primary', label: 'Indigo' },\n  { value: 'success', label: 'Green' },\n  { value: 'warning', label: 'Amber' },\n  { value: 'destructive', label: 'Red' },\n];\n\nexport type ViewOption = {\n  view: CalendarView;\n  label: string;\n  shortcut: string;\n};\n\nexport const ViewOptions: ViewOption[] = [\n  { view: 'day', label: 'Day', shortcut: 'D' },\n  { view: 'week', label: 'Week', shortcut: 'W' },\n  { view: 'month', label: 'Month', shortcut: 'M' },\n  { view: 'year', label: 'Year', shortcut: 'Y' },\n  { view: 'agenda', label: 'Agenda', shortcut: 'A' },\n];\n\nexport const AllViews: CalendarView[] = ViewOptions.map(\n  (option) => option.view\n);\n",
      "type": "registry:component",
      "target": "components/event-calendar/_parts/constants.ts"
    },
    {
      "path": "registry/ndeko/components/event-calendar/_parts/day-events-panel.tsx",
      "content": "'use client';\n\nimport { format, isToday } from 'date-fns';\n\nimport { PlusIcon } from '@/registry/ndeko/lib/icons';\nimport { cn } from '@/registry/ndeko/lib/utils';\nimport { AnimatedSize } from '@/registry/ndeko/ui/animated-size';\nimport { Button } from '@/registry/ndeko/ui/button';\n\nimport { EventListRow } from './event-list-row';\nimport type { CalendarEvent } from './types';\nimport {\n  defaultStartOf,\n  eventCountLabelOf,\n  getAgendaEventsForDay,\n} from './utils';\n\ntype DayEventsPanelProps = {\n  day: Date;\n  events: CalendarEvent[];\n  onEventSelect: (event: CalendarEvent) => void;\n  /** Offers to plan an event when the day is empty. */\n  onEventCreate?: (startTime: Date) => void;\n  className?: string;\n};\n\ntype EmptyDayProps = {\n  day: Date;\n  onEventCreate?: (startTime: Date) => void;\n};\n\nfunction EmptyDay({ day, onEventCreate }: EmptyDayProps) {\n  const canCreate = Boolean(onEventCreate);\n\n  function createEvent() {\n    const start = defaultStartOf(day);\n    onEventCreate?.(start);\n  }\n\n  return (\n    <div className='hairline-border border-border flex flex-wrap items-center justify-between gap-3 rounded-lg border-dashed px-3 py-3'>\n      <p className='text-muted-foreground text-[13px]'>No events on this day</p>\n      {canCreate && (\n        <Button variant='outline' size='sm' onClick={createEvent}>\n          <PlusIcon />\n          New event\n        </Button>\n      )}\n    </div>\n  );\n}\n\n/** The events of one day as a list, with a heading that names the day and counts them. */\nexport function DayEventsPanel({\n  day,\n  events,\n  onEventSelect,\n  onEventCreate,\n  className,\n}: DayEventsPanelProps) {\n  const dayEvents = getAgendaEventsForDay(events, day);\n  const hasEvents = dayEvents.length > 0;\n  const isTodayDay = isToday(day);\n\n  return (\n    <section\n      aria-label={format(day, 'EEEE, MMMM d')}\n      className={cn('flex min-w-0 flex-col gap-2', className)}\n    >\n      <header\n        aria-live='polite'\n        className='flex items-baseline justify-between gap-3 px-2'\n      >\n        <h3 className='flex min-w-0 items-baseline gap-2 text-sm font-medium'>\n          <span className='truncate'>{format(day, 'EEEE, MMMM d')}</span>\n          {isTodayDay && (\n            <span className='text-primary-ink shrink-0 text-xs font-normal'>\n              Today\n            </span>\n          )}\n        </h3>\n        <p className='text-muted-foreground shrink-0 text-xs tabular-nums'>\n          {eventCountLabelOf(dayEvents.length)}\n        </p>\n      </header>\n      <AnimatedSize>\n        {hasEvents && (\n          <ul className='flex flex-col'>\n            {dayEvents.map((event) => (\n              <li key={event.id}>\n                <EventListRow\n                  event={event}\n                  day={day}\n                  onClick={() => onEventSelect(event)}\n                />\n              </li>\n            ))}\n          </ul>\n        )}\n        {!hasEvents && <EmptyDay day={day} onEventCreate={onEventCreate} />}\n      </AnimatedSize>\n    </section>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/event-calendar/_parts/day-events-panel.tsx"
    },
    {
      "path": "registry/ndeko/components/event-calendar/_parts/day-view.tsx",
      "content": "'use client';\n\nimport { format, isSameDay } from 'date-fns';\nimport { useMemo } from 'react';\n\nimport { cn } from '@/registry/ndeko/lib/utils';\n\nimport { EventItem } from './event-item';\nimport {\n  CurrentTimeLine,\n  HourLabels,\n  hoursOfDay,\n  PositionedEvents,\n  QuarterSlots,\n  TimeGridScroller,\n} from './time-grid';\nimport type { CalendarEvent } from './types';\nimport { useCurrentTimeIndicator } from './use-current-time-indicator';\nimport { isMultiDayEvent, occursOnDay, positionTimedEvents } from './utils';\n\nconst DAY_COLUMNS = 'grid grid-cols-[3.5rem_minmax(0,1fr)]';\n\ntype DayViewProps = {\n  currentDate: Date;\n  events: CalendarEvent[];\n  onEventSelect: (event: CalendarEvent) => void;\n  onEventCreate: (startTime: Date) => void;\n};\n\nexport function DayView({\n  currentDate,\n  events,\n  onEventSelect,\n  onEventCreate,\n}: DayViewProps) {\n  const hours = useMemo(() => hoursOfDay(currentDate), [currentDate]);\n\n  const dayEvents = useMemo(\n    () => events.filter((event) => occursOnDay(event, currentDate)),\n    [currentDate, events]\n  );\n\n  const allDayEvents = useMemo(\n    () => dayEvents.filter(isMultiDayEvent),\n    [dayEvents]\n  );\n\n  const positionedEvents = useMemo(() => {\n    const timedEvents = dayEvents.filter((event) => !isMultiDayEvent(event));\n    return positionTimedEvents(timedEvents, currentDate);\n  }, [currentDate, dayEvents]);\n\n  const { currentTimePosition, currentTimeVisible } = useCurrentTimeIndicator(\n    currentDate,\n    'day'\n  );\n  const showAllDaySection = allDayEvents.length > 0;\n\n  function handleEventClick(\n    event: CalendarEvent,\n    clickEvent: React.MouseEvent\n  ) {\n    clickEvent.stopPropagation();\n    onEventSelect(event);\n  }\n\n  return (\n    <div\n      data-slot='day-view'\n      className='hairline-t border-border flex min-h-0 flex-1 flex-col'\n    >\n      <TimeGridScroller label={format(currentDate, 'EEEE, MMMM d')}>\n        {showAllDaySection && (\n          <div\n            className={cn(\n              DAY_COLUMNS,\n              'bg-card hairline-b border-border sticky top-0 z-30'\n            )}\n          >\n            <div className='hairline-r border-border text-muted-foreground flex items-end justify-end pe-2 pb-2 text-[10px] @3xl:text-xs'>\n              All day\n            </div>\n            <div className='relative p-1'>\n              {allDayEvents.map((event) => (\n                <EventItem\n                  key={`spanning-${event.id}`}\n                  onClick={(clickEvent) => handleEventClick(event, clickEvent)}\n                  event={event}\n                  view='month'\n                  isFirstDay={isSameDay(currentDate, new Date(event.start))}\n                  isLastDay={isSameDay(currentDate, new Date(event.end))}\n                >\n                  <span className='truncate' aria-hidden='true'>\n                    {event.title}\n                  </span>\n                </EventItem>\n              ))}\n            </div>\n          </div>\n        )}\n\n        <div className={DAY_COLUMNS}>\n          <div className='hairline-r border-border'>\n            <HourLabels hours={hours} />\n          </div>\n\n          <div className='relative'>\n            <PositionedEvents\n              positionedEvents={positionedEvents}\n              view='day'\n              onEventClick={handleEventClick}\n            />\n            {currentTimeVisible && (\n              <CurrentTimeLine position={currentTimePosition} />\n            )}\n            <QuarterSlots\n              day={currentDate}\n              hours={hours}\n              idPrefix='day-cell'\n              onEventCreate={onEventCreate}\n            />\n          </div>\n        </div>\n      </TimeGridScroller>\n    </div>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/event-calendar/_parts/day-view.tsx"
    },
    {
      "path": "registry/ndeko/components/event-calendar/_parts/draggable-event.tsx",
      "content": "'use client';\n\nimport { useDraggable } from '@dnd-kit/core';\nimport { motion } from 'motion/react';\nimport { useState } from 'react';\n\nimport { usePrefersReducedMotion } from '@/registry/ndeko/hooks/use-prefers-reduced-motion';\n\nimport { DROP_SPRING, useCalendarDnd } from './calendar-dnd-context';\nimport { EventItem } from './event-item';\nimport type { CalendarEvent, TimedView } from './types';\n\ntype DraggableEventProps = {\n  event: CalendarEvent;\n  view: TimedView;\n  showTime?: boolean;\n  onClick?: (event: React.MouseEvent) => void;\n  height?: number;\n  isFirstDay?: boolean;\n  isLastDay?: boolean;\n};\n\nfunction heightStyleOf(height: number | undefined) {\n  if (height) {\n    return height;\n  }\n  return 'auto';\n}\n\nexport function DraggableEvent({\n  event,\n  view,\n  showTime,\n  onClick,\n  height,\n  isFirstDay = true,\n  isLastDay = true,\n}: DraggableEventProps) {\n  const { activeId, droppedEventId, clearDroppedEvent } = useCalendarDnd();\n  const shouldReduceMotion = usePrefersReducedMotion();\n  const [measuredHeight, setMeasuredHeight] = useState<number | null>(null);\n  const draggableId = `${event.id}-${view}`;\n  const { attributes, listeners, setNodeRef, isDragging } = useDraggable({\n    id: draggableId,\n    data: {\n      event,\n      view,\n      height: height ?? measuredHeight,\n    },\n  });\n  const isActive = isDragging || activeId === draggableId;\n  const isJustDropped = droppedEventId === event.id;\n  const hasDropAnimation = isJustDropped && !shouldReduceMotion;\n  let layoutId: string | undefined;\n  if (hasDropAnimation) {\n    layoutId = `dropped-event-${event.id}`;\n  }\n\n  function measure(pointerEvent: React.PointerEvent<HTMLDivElement>) {\n    setMeasuredHeight(pointerEvent.currentTarget.offsetHeight);\n  }\n\n  function settleDrop() {\n    if (isJustDropped) {\n      clearDroppedEvent();\n    }\n  }\n\n  if (isActive) {\n    return (\n      <div\n        ref={setNodeRef}\n        className='opacity-0'\n        style={{ height: heightStyleOf(height) }}\n      />\n    );\n  }\n\n  return (\n    <motion.div\n      ref={setNodeRef}\n      layoutId={layoutId}\n      transition={DROP_SPRING}\n      onLayoutAnimationComplete={settleDrop}\n      onPointerDownCapture={measure}\n      style={{ height: heightStyleOf(height) }}\n      className='touch-none'\n    >\n      <EventItem\n        event={event}\n        view={view}\n        showTime={showTime}\n        isFirstDay={isFirstDay}\n        isLastDay={isLastDay}\n        isDragging={isDragging}\n        onClick={onClick}\n        dndListeners={listeners}\n        dndAttributes={attributes}\n      />\n    </motion.div>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/event-calendar/_parts/draggable-event.tsx"
    },
    {
      "path": "registry/ndeko/components/event-calendar/_parts/droppable-cell.tsx",
      "content": "'use client';\n\nimport { useDroppable } from '@dnd-kit/core';\n\nimport { cn } from '@/registry/ndeko/lib/utils';\n\nimport { useCalendarDnd } from './calendar-dnd-context';\n\ntype DroppableCellProps = {\n  id: string;\n  date: Date;\n  /** Hours of the slot in the week and day views: 9.25 is 9:15. */\n  time?: number;\n  children?: React.ReactNode;\n  className?: string;\n  style?: React.CSSProperties;\n  onClick?: () => void;\n};\n\nexport function DroppableCell({\n  id,\n  date,\n  time,\n  children,\n  className,\n  style,\n  onClick,\n}: DroppableCellProps) {\n  const { activeEvent } = useCalendarDnd();\n  const { setNodeRef, isOver } = useDroppable({ id, data: { date, time } });\n  const isDropTarget = isOver && Boolean(activeEvent);\n\n  return (\n    <div\n      ref={setNodeRef}\n      onClick={onClick}\n      style={style}\n      className={cn(\n        'data-dragging:bg-primary/[0.06] flex h-full flex-col overflow-hidden px-0.5 py-1 transition-colors duration-150 sm:px-1',\n        className\n      )}\n      data-dragging={isDropTarget || undefined}\n    >\n      {children}\n    </div>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/event-calendar/_parts/droppable-cell.tsx"
    },
    {
      "path": "registry/ndeko/components/event-calendar/_parts/event-calendar.tsx",
      "content": "'use client';\n\nimport { useAnimate, type Transition } from 'motion/react';\nimport { useLayoutEffect, useRef, useState } from 'react';\n\nimport { PlusIcon } from '@/registry/ndeko/lib/icons';\nimport { cn } from '@/registry/ndeko/lib/utils';\nimport { AnimatedSize } from '@/registry/ndeko/ui/animated-size';\nimport { Button } from '@/registry/ndeko/ui/button';\n\nimport { AgendaView } from './agenda-view';\nimport { CalendarDndProvider } from './calendar-dnd-context';\nimport { CalendarHeader } from './calendar-header';\nimport {\n  AllViews,\n  EventGap,\n  EventHeight,\n  ScrollAreaHeight,\n  WeekCellsHeight,\n} from './constants';\nimport { DayEventsPanel } from './day-events-panel';\nimport { DayView } from './day-view';\nimport { EventDialog } from './event-dialog';\nimport { MonthView } from './month-view';\nimport { periodKeyOf, shiftDate } from './navigation';\nimport type { CalendarEvent, CalendarView, EventColorOption } from './types';\nimport { useEventEditor, type EventEditor } from './use-event-editor';\nimport { defaultStartOf } from './utils';\nimport { ViewSwitcher } from './view-switcher';\nimport { WeekView } from './week-view';\nimport { YearView } from './year-view';\n\nexport type EventCalendarProps = {\n  events?: CalendarEvent[];\n  onEventAdd?: (event: CalendarEvent) => void;\n  onEventUpdate?: (event: CalendarEvent) => void;\n  onEventDelete?: (eventId: string) => void;\n  className?: string;\n  initialView?: CalendarView;\n  /** The views people can switch between, in this order. A single view hides the switcher. */\n  views?: CalendarView[];\n  /** The day the calendar shows, when the parent drives it, for example from a mini month. */\n  date?: Date;\n  onDateChange?: (date: Date) => void;\n  /** Fills the height of its parent, each view scrolling inside, as in an app shell. */\n  fillHeight?: boolean;\n  /** An editor from `useEventEditor`, when something outside the calendar also opens the dialog. */\n  editor?: EventEditor;\n  /** Named colours for the dialog, such as the calendars of an app. */\n  colorOptions?: EventColorOption[];\n  colorLegend?: string;\n  /** Placed before Today in the header. */\n  headerStart?: React.ReactNode;\n  newEventClassName?: string;\n};\n\nconst ROOT =\n  '@container bg-card hairline-ring ring-border flex w-full min-w-0 flex-col rounded-xl shadow-[0_1px_2px_rgb(0_0_0/0.04)]';\n\nconst VIEW_FADE: Transition = { duration: 0.16, ease: [0.23, 1, 0.32, 1] };\n\n/** The new period starts slightly faded rather than blank, so quick clicks never flash. */\nconst FADE_FROM_OPACITY = 0.35;\n\nconst SHORTCUT_VIEWS: Record<string, CalendarView | undefined> = {\n  d: 'day',\n  w: 'week',\n  m: 'month',\n  y: 'year',\n  a: 'agenda',\n};\n\nconst TODAY_SHORTCUT = 't';\n\nfunction isTypingTarget(target: EventTarget) {\n  const isInput = target instanceof HTMLInputElement;\n  const isTextArea = target instanceof HTMLTextAreaElement;\n  const isEditable = target instanceof HTMLElement && target.isContentEditable;\n  return isInput || isTextArea || isEditable;\n}\n\nfunction hasModifierKey(keyEvent: React.KeyboardEvent) {\n  const modifiers = [keyEvent.metaKey, keyEvent.ctrlKey, keyEvent.altKey];\n  return modifiers.some(Boolean);\n}\n\n/** Keys pressed in the dialog or a popover bubble through React portals; only the calendar's own DOM counts. */\nfunction isInsideRoot(target: EventTarget, root: HTMLElement | null) {\n  if (!root) {\n    return false;\n  }\n  if (!(target instanceof Node)) {\n    return false;\n  }\n  return root.contains(target);\n}\n\nfunction isShortcutEvent(\n  keyEvent: React.KeyboardEvent,\n  root: HTMLElement | null\n) {\n  if (keyEvent.defaultPrevented) {\n    return false;\n  }\n  if (hasModifierKey(keyEvent)) {\n    return false;\n  }\n  if (isTypingTarget(keyEvent.target)) {\n    return false;\n  }\n  return isInsideRoot(keyEvent.target, root);\n}\n\nfunction firstViewOf(initialView: CalendarView, views: CalendarView[]) {\n  if (views.includes(initialView)) {\n    return initialView;\n  }\n  return views[0] ?? initialView;\n}\n\nfunction scrollHeightOf(fillHeight: boolean) {\n  if (fillHeight) {\n    return 'none';\n  }\n  return ScrollAreaHeight;\n}\n\nfunction rootStyleOf(fillHeight: boolean) {\n  return {\n    '--event-height': `${EventHeight}px`,\n    '--event-gap': `${EventGap}px`,\n    '--week-cells-height': `${WeekCellsHeight}px`,\n    '--calendar-scroll-height': scrollHeightOf(fillHeight),\n  } as React.CSSProperties;\n}\n\nfunction directionTowards(target: Date, from: Date) {\n  const difference = target.getTime() - from.getTime();\n  return Math.sign(difference);\n}\n\ntype ViewFadeProps = {\n  changeKey: string;\n  className?: string;\n  children: React.ReactNode;\n};\n\n/** The new period or view replaces the old one in place, with a short fade and no sliding. */\nfunction ViewFade({ changeKey, className, children }: ViewFadeProps) {\n  const [scope, animate] = useAnimate<HTMLDivElement>();\n  const previousKeyRef = useRef(changeKey);\n\n  useLayoutEffect(() => {\n    if (previousKeyRef.current === changeKey) {\n      return;\n    }\n    previousKeyRef.current = changeKey;\n    animate(scope.current, { opacity: [FADE_FROM_OPACITY, 1] }, VIEW_FADE);\n  }, [animate, changeKey, scope]);\n\n  return (\n    <div ref={scope} className={className}>\n      {children}\n    </div>\n  );\n}\n\ntype ViewFrameProps = {\n  fillHeight: boolean;\n  changeKey: string;\n  children: React.ReactNode;\n};\n\nfunction ViewFrame({ fillHeight, changeKey, children }: ViewFrameProps) {\n  if (fillHeight) {\n    return (\n      <ViewFade changeKey={changeKey} className='flex min-h-0 flex-1 flex-col'>\n        {children}\n      </ViewFade>\n    );\n  }\n\n  return (\n    <AnimatedSize className='m-0 rounded-b-xl' contentClassName='p-0'>\n      <ViewFade changeKey={changeKey} className='flex flex-col'>\n        {children}\n      </ViewFade>\n    </AnimatedSize>\n  );\n}\n\ntype YearPaneProps = {\n  currentDate: Date;\n  events: CalendarEvent[];\n  canOpenDay: boolean;\n  onDaySelect: (day: Date) => void;\n  onMonthSelect?: (month: Date) => void;\n  onEventSelect: (event: CalendarEvent) => void;\n  onEventCreate: (startTime: Date) => void;\n};\n\n/** With a day view the year opens the picked day; on its own it lists the picked day beside it. */\nfunction YearPane({\n  currentDate,\n  events,\n  canOpenDay,\n  onDaySelect,\n  onMonthSelect,\n  onEventSelect,\n  onEventCreate,\n}: YearPaneProps) {\n  if (canOpenDay) {\n    return (\n      <div className='hairline-t border-border flex min-h-0 flex-1 flex-col'>\n        <YearView\n          currentDate={currentDate}\n          events={events}\n          onDaySelect={onDaySelect}\n          onMonthSelect={onMonthSelect}\n        />\n      </div>\n    );\n  }\n\n  return (\n    <div className='hairline-t border-border flex min-h-0 flex-1 flex-col @4xl:grid @4xl:grid-cols-[minmax(0,1fr)_18rem]'>\n      <YearView\n        currentDate={currentDate}\n        events={events}\n        onDaySelect={onDaySelect}\n        onMonthSelect={onMonthSelect}\n        selectedDay={currentDate}\n      />\n      <DayEventsPanel\n        day={currentDate}\n        events={events}\n        onEventSelect={onEventSelect}\n        onEventCreate={onEventCreate}\n        className='hairline-t border-border @4xl:hairline-l px-2 py-4 @4xl:border-t-0 @4xl:py-5'\n      />\n    </div>\n  );\n}\n\ntype NewEventButtonProps = {\n  className?: string;\n  onClick: () => void;\n};\n\nfunction NewEventButton({ className, onClick }: NewEventButtonProps) {\n  return (\n    <Button\n      className={cn('@max-md:w-8 @max-md:px-0', className)}\n      onClick={onClick}\n    >\n      <PlusIcon />\n      <span className='sr-only @md:not-sr-only'>New event</span>\n    </Button>\n  );\n}\n\nexport function EventCalendar({\n  events = [],\n  onEventAdd,\n  onEventUpdate,\n  onEventDelete,\n  className,\n  initialView = 'month',\n  views = AllViews,\n  date,\n  onDateChange,\n  fillHeight = false,\n  editor,\n  colorOptions,\n  colorLegend,\n  headerStart,\n  newEventClassName,\n}: EventCalendarProps) {\n  const rootRef = useRef<HTMLDivElement>(null);\n  const [ownDate, setOwnDate] = useState(() => new Date());\n  const [view, setView] = useState<CalendarView>(() =>\n    firstViewOf(initialView, views)\n  );\n  const [direction, setDirection] = useState(0);\n  const ownEditor = useEventEditor({\n    events,\n    onEventAdd,\n    onEventUpdate,\n    onEventDelete,\n  });\n  const activeEditor = editor ?? ownEditor;\n  const currentDate = date ?? ownDate;\n  const periodKey = periodKeyOf(currentDate, view);\n  const canOpenDay = views.includes('day');\n  const canOpenMonth = views.includes('month');\n  const hasSwitcher = views.length > 1;\n\n  function changeDate(nextDate: Date, nextDirection: number) {\n    setOwnDate(nextDate);\n    setDirection(nextDirection);\n    onDateChange?.(nextDate);\n  }\n\n  function changeView(nextView: CalendarView) {\n    setView(nextView);\n    setDirection(0);\n  }\n\n  function navigate(step: number) {\n    const nextDate = shiftDate(currentDate, view, step);\n    changeDate(nextDate, step);\n  }\n\n  function goToToday() {\n    const today = new Date();\n    const todayKey = periodKeyOf(today, view);\n    const isSamePeriod = todayKey === periodKey;\n    let nextDirection = directionTowards(today, currentDate);\n    if (isSamePeriod) {\n      nextDirection = 0;\n    }\n    changeDate(today, nextDirection);\n  }\n\n  function selectDay(day: Date) {\n    if (canOpenDay) {\n      setView('day');\n    }\n    changeDate(day, 0);\n  }\n\n  function selectMonth(month: Date) {\n    setView('month');\n    changeDate(month, 0);\n  }\n\n  let openDay: ((day: Date) => void) | undefined;\n  if (canOpenDay) {\n    openDay = selectDay;\n  }\n  let openMonth: ((month: Date) => void) | undefined;\n  if (canOpenMonth) {\n    openMonth = selectMonth;\n  }\n\n  function createFromHeader() {\n    const today = new Date();\n    const todayKey = periodKeyOf(today, view);\n    const isTodayInView = todayKey === periodKey;\n    let anchorDay = currentDate;\n    if (isTodayInView) {\n      anchorDay = today;\n    }\n    const start = defaultStartOf(anchorDay);\n    activeEditor.openNewEvent(start);\n  }\n\n  function handleShortcut(keyEvent: React.KeyboardEvent<HTMLDivElement>) {\n    if (!isShortcutEvent(keyEvent, rootRef.current)) {\n      return;\n    }\n    const key = keyEvent.key.toLowerCase();\n    if (key === TODAY_SHORTCUT) {\n      keyEvent.preventDefault();\n      goToToday();\n      return;\n    }\n    const nextView = SHORTCUT_VIEWS[key];\n    if (!nextView) {\n      return;\n    }\n    if (!views.includes(nextView)) {\n      return;\n    }\n    keyEvent.preventDefault();\n    changeView(nextView);\n  }\n\n  const viewProps = {\n    currentDate,\n    events,\n    onEventSelect: activeEditor.openEvent,\n    onEventCreate: activeEditor.openNewEvent,\n  };\n\n  return (\n    <div\n      ref={rootRef}\n      data-slot='event-calendar'\n      onKeyDown={handleShortcut}\n      className={cn(ROOT, fillHeight && 'h-full min-h-0', className)}\n      style={rootStyleOf(fillHeight)}\n    >\n      <CalendarDndProvider onEventUpdate={activeEditor.moveEvent}>\n        <CalendarHeader\n          view={view}\n          date={currentDate}\n          direction={direction}\n          start={headerStart}\n          onPrevious={() => navigate(-1)}\n          onNext={() => navigate(1)}\n          onToday={goToToday}\n        >\n          {hasSwitcher && (\n            <ViewSwitcher\n              views={views}\n              value={view}\n              onValueChange={changeView}\n            />\n          )}\n          <NewEventButton\n            className={newEventClassName}\n            onClick={createFromHeader}\n          />\n        </CalendarHeader>\n\n        <ViewFrame fillHeight={fillHeight} changeKey={`${view}-${periodKey}`}>\n          {view === 'month' && (\n            <MonthView\n              {...viewProps}\n              onDaySelect={openDay}\n              fillHeight={fillHeight}\n            />\n          )}\n          {view === 'week' && <WeekView {...viewProps} onDaySelect={openDay} />}\n          {view === 'day' && <DayView {...viewProps} />}\n          {view === 'year' && (\n            <YearPane\n              {...viewProps}\n              canOpenDay={canOpenDay}\n              onDaySelect={selectDay}\n              onMonthSelect={openMonth}\n            />\n          )}\n          {view === 'agenda' && (\n            <AgendaView\n              currentDate={currentDate}\n              events={events}\n              onEventSelect={activeEditor.openEvent}\n            />\n          )}\n        </ViewFrame>\n\n        <EventDialog\n          {...activeEditor.dialogProps}\n          colorOptions={colorOptions}\n          colorLegend={colorLegend}\n        />\n      </CalendarDndProvider>\n    </div>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/event-calendar/_parts/event-calendar.tsx"
    },
    {
      "path": "registry/ndeko/components/event-calendar/_parts/event-dialog.tsx",
      "content": "'use client';\n\nimport { format, isBefore, isSameDay } from 'date-fns';\nimport {\n  AnimatePresence,\n  motion,\n  type Transition,\n  type Variants,\n} from 'motion/react';\nimport { useId, useState } from 'react';\n\nimport { usePrefersReducedMotion } from '@/registry/ndeko/hooks/use-prefers-reduced-motion';\nimport { CalendarIcon, TrashIcon } from '@/registry/ndeko/lib/icons';\nimport { CONTROL_RECIPE, CONTROL_SIZES } from '@/registry/ndeko/lib/recipes';\nimport { cn } from '@/registry/ndeko/lib/utils';\nimport { AnimatedSize } from '@/registry/ndeko/ui/animated-size';\nimport { Button } from '@/registry/ndeko/ui/button';\nimport { Calendar } from '@/registry/ndeko/ui/calendar';\nimport { Checkbox } from '@/registry/ndeko/ui/checkbox';\nimport {\n  Dialog,\n  DialogContent,\n  DialogDescription,\n  DialogFooter,\n  DialogHeader,\n  DialogTitle,\n} from '@/registry/ndeko/ui/dialog';\nimport { Input } from '@/registry/ndeko/ui/input';\nimport { Label } from '@/registry/ndeko/ui/label';\nimport {\n  Popover,\n  PopoverContent,\n  PopoverTrigger,\n} from '@/registry/ndeko/ui/popover';\nimport { RadioGroup, RadioGroupItem } from '@/registry/ndeko/ui/radio-group';\nimport {\n  Select,\n  SelectContent,\n  SelectItem,\n  SelectTrigger,\n  SelectValue,\n} from '@/registry/ndeko/ui/select';\nimport { Textarea } from '@/registry/ndeko/ui/textarea';\n\nimport {\n  DefaultEndHour,\n  DefaultEventColor,\n  DefaultStartHour,\n  EndHour,\n  EventColors,\n  StartHour,\n} from './constants';\nimport type { CalendarEvent, EventColor, EventColorOption } from './types';\n\nconst ENTER: Transition = { duration: 0.15, ease: [0.23, 1, 0.32, 1] };\nconst EXIT: Transition = { duration: 0.1, ease: [0.23, 1, 0.32, 1] };\nconst SWAP: Transition = { duration: 0.15, ease: [0.2, 0, 0, 1] };\n\nconst SWAP_VARIANTS: Variants = {\n  enter: { opacity: 0, scale: 0.6, filter: 'blur(2px)' },\n  visible: { opacity: 1, scale: 1, filter: 'blur(0px)' },\n  exit: { opacity: 0, scale: 0.6, filter: 'blur(2px)' },\n};\n\nconst FADE_VARIANTS: Variants = {\n  enter: { opacity: 0 },\n  visible: { opacity: 1 },\n  exit: { opacity: 0 },\n};\n\nconst DATE_TRIGGER = cn(\n  CONTROL_RECIPE,\n  CONTROL_SIZES.default,\n  'group flex cursor-pointer items-center justify-between gap-2 text-left data-popup-open:border-foreground/30'\n);\n\nconst COLOR_SWATCH = [\n  'size-6 bg-(--swatch) ring-(--swatch) shadow-none',\n  'dark:bg-(--swatch) dark:ring-(--swatch)',\n  'data-checked:bg-(--swatch) data-checked:ring-(--swatch) dark:data-checked:bg-(--swatch) dark:data-checked:ring-(--swatch)',\n].join(' ');\n\nconst UNTITLED = 'Untitled event';\n\nfunction formatQuarterTime(hour: number, minute: number) {\n  const paddedHour = String(hour).padStart(2, '0');\n  const paddedMinute = String(minute).padStart(2, '0');\n  const value = `${paddedHour}:${paddedMinute}`;\n  const label = format(new Date(2000, 0, 1, hour, minute), 'h:mm a');\n  return { value, label };\n}\n\nfunction buildTimeOptions() {\n  const options: { value: string; label: string }[] = [];\n  for (let hour = StartHour; hour <= EndHour; hour++) {\n    for (let minute = 0; minute < 60; minute += 15) {\n      options.push(formatQuarterTime(hour, minute));\n    }\n  }\n  return options;\n}\n\nconst TIME_OPTIONS = buildTimeOptions();\n\nconst DEFAULT_START_TIME = formatQuarterTime(DefaultStartHour, 0).value;\nconst DEFAULT_END_TIME = formatQuarterTime(DefaultEndHour, 0).value;\n\nfunction formatTimeForInput(date: Date) {\n  const quarter = Math.floor(date.getMinutes() / 15);\n  return formatQuarterTime(date.getHours(), quarter * 15).value;\n}\n\nfunction hoursAndMinutesOf(time: string) {\n  const parts = time.split(':');\n  const [hours = 0, minutes = 0] = parts.map(Number);\n  return { hours, minutes };\n}\n\nfunction isHourOutsideDay(hours: number) {\n  return hours < StartHour || hours > EndHour;\n}\n\nfunction isEventColor(value: unknown): value is EventColor {\n  return EventColors.some((option) => option.value === value);\n}\n\nfunction timeOf(date: Date) {\n  return format(date, 'h:mm a');\n}\n\n/** When the event runs, in a sentence: the subtitle of the dialog. */\nfunction whenLabelOf(event: CalendarEvent) {\n  const start = new Date(event.start);\n  const end = new Date(event.end);\n  const isOneDay = isSameDay(start, end);\n  const isAllDayOnOneDay = Boolean(event.allDay) && isOneDay;\n\n  if (isAllDayOnOneDay) {\n    return `${format(start, 'EEEE, MMMM d')}, all day`;\n  }\n  if (event.allDay) {\n    return `${format(start, 'MMM d')} to ${format(end, 'MMM d')}, all day`;\n  }\n  if (isOneDay) {\n    return `${format(start, 'EEEE, MMMM d')}, ${timeOf(start)} to ${timeOf(end)}`;\n  }\n  return `${format(start, 'MMM d, h:mm a')} to ${format(end, 'MMM d, h:mm a')}`;\n}\n\ntype DatePickerFieldProps = {\n  id: string;\n  label: string;\n  date: Date;\n  disabledBefore?: Date;\n  onPick: (date: Date) => void;\n};\n\nfunction DatePickerField({\n  id,\n  label,\n  date,\n  disabledBefore,\n  onPick,\n}: DatePickerFieldProps) {\n  const [isOpen, setIsOpen] = useState(false);\n  let disabled: { before: Date } | undefined;\n  if (disabledBefore) {\n    disabled = { before: disabledBefore };\n  }\n\n  function pick(picked: Date | undefined) {\n    if (!picked) {\n      return;\n    }\n    onPick(picked);\n    setIsOpen(false);\n  }\n\n  return (\n    <div className='flex flex-1 flex-col gap-1.5'>\n      <Label htmlFor={id}>{label}</Label>\n      <Popover open={isOpen} onOpenChange={setIsOpen}>\n        <PopoverTrigger id={id} className={DATE_TRIGGER}>\n          <span className='truncate'>{format(date, 'PPP')}</span>\n          <CalendarIcon className='text-muted-foreground size-4 shrink-0' />\n        </PopoverTrigger>\n        <PopoverContent className='w-auto p-2' align='start'>\n          <AnimatedSize>\n            <Calendar\n              mode='single'\n              selected={date}\n              defaultMonth={date}\n              disabled={disabled}\n              onSelect={pick}\n            />\n          </AnimatedSize>\n        </PopoverContent>\n      </Popover>\n    </div>\n  );\n}\n\ntype TimeSelectFieldProps = {\n  id: string;\n  label: string;\n  value: string;\n  onChange: (value: string) => void;\n};\n\nfunction TimeSelectField({ id, label, value, onChange }: TimeSelectFieldProps) {\n  function pick(nextValue: string | null) {\n    if (nextValue) {\n      onChange(nextValue);\n    }\n  }\n\n  return (\n    <div className='flex min-w-28 flex-col gap-1.5'>\n      <Label htmlFor={id}>{label}</Label>\n      <Select items={TIME_OPTIONS} value={value} onValueChange={pick}>\n        <SelectTrigger id={id} className='tabular-nums'>\n          <SelectValue placeholder='Pick a time' />\n        </SelectTrigger>\n        <SelectContent>\n          {TIME_OPTIONS.map((option) => (\n            <SelectItem\n              key={option.value}\n              value={option.value}\n              className='tabular-nums'\n            >\n              {option.label}\n            </SelectItem>\n          ))}\n        </SelectContent>\n      </Select>\n    </div>\n  );\n}\n\nfunction swapVariantsOf(shouldReduceMotion: boolean | null) {\n  if (shouldReduceMotion) {\n    return FADE_VARIANTS;\n  }\n  return SWAP_VARIANTS;\n}\n\nfunction SwappingLabel({ label }: { label: string }) {\n  const shouldReduceMotion = usePrefersReducedMotion();\n\n  return (\n    <span className='relative inline-flex'>\n      <AnimatePresence mode='popLayout' initial={false}>\n        <motion.span\n          key={label}\n          variants={swapVariantsOf(shouldReduceMotion)}\n          initial='enter'\n          animate='visible'\n          exit='exit'\n          transition={SWAP}\n        >\n          {label}\n        </motion.span>\n      </AnimatePresence>\n    </span>\n  );\n}\n\nfunction labelOfColor(color: EventColor, options: EventColorOption[]) {\n  const option = options.find((candidate) => candidate.value === color);\n  return option?.label ?? '';\n}\n\ntype ColorFieldProps = {\n  color: EventColor;\n  options: EventColorOption[];\n  legend: string;\n  onChange: (color: EventColor) => void;\n};\n\nfunction ColorField({ color, options, legend, onChange }: ColorFieldProps) {\n  function pickColor(value: unknown) {\n    if (isEventColor(value)) {\n      onChange(value);\n    }\n  }\n\n  return (\n    <fieldset>\n      <legend className='text-foreground mb-3 flex items-baseline gap-2 text-[13px] leading-none font-medium'>\n        {legend}\n        <span aria-hidden='true' className='text-muted-foreground font-normal'>\n          <SwappingLabel label={labelOfColor(color, options)} />\n        </span>\n      </legend>\n      <RadioGroup\n        className='flex flex-wrap gap-1.5'\n        value={color}\n        onValueChange={pickColor}\n      >\n        {options.map((option) => (\n          <RadioGroupItem\n            key={option.value}\n            value={option.value}\n            aria-label={option.label}\n            className={COLOR_SWATCH}\n            style={\n              {\n                '--swatch': `var(--${option.value})`,\n              } as React.CSSProperties\n            }\n          />\n        ))}\n      </RadioGroup>\n    </fieldset>\n  );\n}\n\nfunction startDateOf(event: CalendarEvent | null) {\n  if (event) {\n    return new Date(event.start);\n  }\n  return new Date();\n}\n\nfunction endDateOf(event: CalendarEvent | null) {\n  if (event) {\n    return new Date(event.end);\n  }\n  return new Date();\n}\n\nfunction initialTimeOf(date: Date | undefined, fallback: string) {\n  if (date) {\n    return formatTimeForInput(new Date(date));\n  }\n  return fallback;\n}\n\nfunction titleOf(isExisting: boolean) {\n  if (isExisting) {\n    return 'Edit event';\n  }\n  return 'New event';\n}\n\nfunction saveLabelOf(isExisting: boolean) {\n  if (isExisting) {\n    return 'Save changes';\n  }\n  return 'Create event';\n}\n\nfunction subtitleOf(event: CalendarEvent | null) {\n  if (!event) {\n    return 'The title, time, place and colour of the event.';\n  }\n  return whenLabelOf(event);\n}\n\ntype EventFormProps = {\n  event: CalendarEvent | null;\n  colorOptions: EventColorOption[];\n  colorLegend: string;\n  onCancel: () => void;\n  onSave: (event: CalendarEvent) => void;\n  onDelete: (eventId: string) => void;\n};\n\nfunction EventForm({\n  event,\n  colorOptions,\n  colorLegend,\n  onCancel,\n  onSave,\n  onDelete,\n}: EventFormProps) {\n  const id = useId();\n  const [title, setTitle] = useState(event?.title ?? '');\n  const [description, setDescription] = useState(event?.description ?? '');\n  const [startDate, setStartDate] = useState(() => startDateOf(event));\n  const [endDate, setEndDate] = useState(() => endDateOf(event));\n  const [startTime, setStartTime] = useState(() =>\n    initialTimeOf(event?.start, DEFAULT_START_TIME)\n  );\n  const [endTime, setEndTime] = useState(() =>\n    initialTimeOf(event?.end, DEFAULT_END_TIME)\n  );\n  const [allDay, setAllDay] = useState(event?.allDay ?? false);\n  const [location, setLocation] = useState(event?.location ?? '');\n  const [color, setColor] = useState<EventColor>(\n    event?.color ?? DefaultEventColor\n  );\n  const [error, setError] = useState<string | null>(null);\n  const isExisting = Boolean(event?.id);\n  const hasTimes = !allDay;\n\n  function pickStartDate(date: Date) {\n    setStartDate(date);\n    if (isBefore(endDate, date)) {\n      setEndDate(date);\n    }\n    setError(null);\n  }\n\n  function pickEndDate(date: Date) {\n    setEndDate(date);\n    setError(null);\n  }\n\n  function handleSave(submitEvent: React.FormEvent<HTMLFormElement>) {\n    submitEvent.preventDefault();\n    const start = new Date(startDate);\n    const end = new Date(endDate);\n\n    if (allDay) {\n      start.setHours(0, 0, 0, 0);\n      end.setHours(23, 59, 59, 999);\n    } else {\n      const startParts = hoursAndMinutesOf(startTime);\n      const endParts = hoursAndMinutesOf(endTime);\n      const startIsOutside = isHourOutsideDay(startParts.hours);\n      const endIsOutside = isHourOutsideDay(endParts.hours);\n      if (startIsOutside || endIsOutside) {\n        setError(`Pick times between ${StartHour}:00 and ${EndHour}:00.`);\n        return;\n      }\n      start.setHours(startParts.hours, startParts.minutes, 0, 0);\n      end.setHours(endParts.hours, endParts.minutes, 0, 0);\n    }\n\n    if (isBefore(end, start)) {\n      setError('The end is before the start. Pick a later end.');\n      return;\n    }\n\n    let eventTitle = title;\n    if (!title.trim()) {\n      eventTitle = UNTITLED;\n    }\n\n    onSave({\n      id: event?.id ?? '',\n      title: eventTitle,\n      description,\n      start,\n      end,\n      allDay,\n      location,\n      color,\n    });\n  }\n\n  return (\n    <form className='flex flex-col gap-4' onSubmit={handleSave} noValidate>\n      <DialogHeader>\n        <DialogTitle>{titleOf(isExisting)}</DialogTitle>\n        <DialogDescription>{subtitleOf(event)}</DialogDescription>\n      </DialogHeader>\n      <AnimatePresence initial={false}>\n        {error && (\n          <motion.p\n            key='error'\n            role='alert'\n            className='bg-destructive/10 text-destructive-ink rounded-md px-3 py-2 text-[13px]'\n            initial={{ opacity: 0 }}\n            animate={{ opacity: 1, transition: ENTER }}\n            exit={{ opacity: 0, transition: EXIT }}\n          >\n            {error}\n          </motion.p>\n        )}\n      </AnimatePresence>\n      <div className='grid gap-4'>\n        <div className='flex flex-col gap-1.5'>\n          <Label htmlFor={`${id}-title`}>Title</Label>\n          <Input\n            id={`${id}-title`}\n            value={title}\n            placeholder={UNTITLED}\n            onChange={(changeEvent) => setTitle(changeEvent.target.value)}\n          />\n        </div>\n\n        <div className='flex gap-4'>\n          <DatePickerField\n            id={`${id}-start-date`}\n            label='Start date'\n            date={startDate}\n            onPick={pickStartDate}\n          />\n          {hasTimes && (\n            <TimeSelectField\n              id={`${id}-start-time`}\n              label='Start time'\n              value={startTime}\n              onChange={setStartTime}\n            />\n          )}\n        </div>\n\n        <div className='flex gap-4'>\n          <DatePickerField\n            id={`${id}-end-date`}\n            label='End date'\n            date={endDate}\n            disabledBefore={startDate}\n            onPick={pickEndDate}\n          />\n          {hasTimes && (\n            <TimeSelectField\n              id={`${id}-end-time`}\n              label='End time'\n              value={endTime}\n              onChange={setEndTime}\n            />\n          )}\n        </div>\n\n        <div className='flex items-center gap-2'>\n          <Checkbox\n            id={`${id}-all-day`}\n            checked={allDay}\n            onCheckedChange={setAllDay}\n          />\n          <Label htmlFor={`${id}-all-day`}>All day</Label>\n        </div>\n\n        <div className='flex flex-col gap-1.5'>\n          <Label htmlFor={`${id}-location`}>Location</Label>\n          <Input\n            id={`${id}-location`}\n            value={location}\n            onChange={(changeEvent) => setLocation(changeEvent.target.value)}\n          />\n        </div>\n\n        <div className='flex flex-col gap-1.5'>\n          <Label htmlFor={`${id}-description`}>Description</Label>\n          <Textarea\n            id={`${id}-description`}\n            value={description}\n            onChange={(changeEvent) => setDescription(changeEvent.target.value)}\n            rows={3}\n          />\n        </div>\n\n        <ColorField\n          color={color}\n          options={colorOptions}\n          legend={colorLegend}\n          onChange={setColor}\n        />\n      </div>\n      <DialogFooter className='flex-row sm:justify-between'>\n        {isExisting && (\n          <Button\n            type='button'\n            variant='outline'\n            size='icon'\n            onClick={() => onDelete(event?.id ?? '')}\n            aria-label='Delete event'\n          >\n            <TrashIcon />\n          </Button>\n        )}\n        <div className='flex flex-1 justify-end gap-2'>\n          <Button type='button' variant='outline' onClick={onCancel}>\n            Cancel\n          </Button>\n          <Button type='submit'>{saveLabelOf(isExisting)}</Button>\n        </div>\n      </DialogFooter>\n    </form>\n  );\n}\n\ntype EventDialogProps = {\n  event: CalendarEvent | null;\n  isOpen: boolean;\n  /** Changes on every opening, so the form starts from the event it was opened for. */\n  session: number;\n  onClose: () => void;\n  onSave: (event: CalendarEvent) => void;\n  onDelete: (eventId: string) => void;\n  /** The colours to pick from, with their names: plain colours, or the calendars of an app. */\n  colorOptions?: EventColorOption[];\n  colorLegend?: string;\n};\n\n/**\n * One layer for reading and changing an event. A click on an event opens it here, ready to\n * edit; a click on an empty slot opens it as a new event at that time.\n */\nexport function EventDialog({\n  event,\n  isOpen,\n  session,\n  onClose,\n  onSave,\n  onDelete,\n  colorOptions = EventColors,\n  colorLegend = 'Colour',\n}: EventDialogProps) {\n  function handleOpenChange(open: boolean) {\n    if (!open) {\n      onClose();\n    }\n  }\n\n  return (\n    <Dialog open={isOpen} onOpenChange={handleOpenChange}>\n      <DialogContent className='sm:max-w-md'>\n        <EventForm\n          key={session}\n          event={event}\n          colorOptions={colorOptions}\n          colorLegend={colorLegend}\n          onCancel={onClose}\n          onSave={onSave}\n          onDelete={onDelete}\n        />\n      </DialogContent>\n    </Dialog>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/event-calendar/_parts/event-dialog.tsx"
    },
    {
      "path": "registry/ndeko/components/event-calendar/_parts/event-item.tsx",
      "content": "'use client';\n\nimport type {\n  DraggableAttributes,\n  DraggableSyntheticListeners,\n} from '@dnd-kit/core';\nimport { differenceInMinutes, isPast } from 'date-fns';\n\nimport { cn } from '@/registry/ndeko/lib/utils';\n\nimport { EventListRow } from './event-list-row';\nimport type { CalendarEvent, CalendarView } from './types';\nimport {\n  clockLabelOf,\n  eventChipStyle,\n  getBorderRadiusClasses,\n  isMultiDayEvent,\n  timeRangeLabelOf,\n} from './utils';\n\nconst SHORT_EVENT_MINUTES = 45;\n\nconst EVENT_SHARED = [\n  'flex size-full min-w-0 cursor-pointer select-none overflow-hidden text-left outline-none',\n  'transition-[opacity,background-color] duration-150 ease-(--ease-out-strong)',\n  'focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-solid focus-visible:outline-ring',\n  'data-dragging:cursor-grabbing data-past-event:opacity-60',\n].join(' ');\n\n/** A filled block: timed events on the hour grid and anything that spans whole days. */\nconst EVENT_BLOCK =\n  'chip-3d px-1.5 font-medium data-dragging:drop-shadow-lg @3xl:px-2';\n\n/** A dot and a line of text: a timed event inside a month cell, lighter than a span. */\nconst EVENT_DOT_ROW =\n  'items-center gap-1.5 rounded-sm px-1 text-foreground hover:bg-foreground/5 data-dragging:surface-raised @3xl:px-1.5';\n\ntype EventShape = 'block' | 'dot';\n\nfunction shiftedEndOf(event: CalendarEvent, currentTime: Date | undefined) {\n  if (!currentTime) {\n    return new Date(event.end);\n  }\n  const duration =\n    new Date(event.end).getTime() - new Date(event.start).getTime();\n  return new Date(currentTime.getTime() + duration);\n}\n\nfunction startOf(event: CalendarEvent, currentTime: Date | undefined) {\n  if (currentTime) {\n    return currentTime;\n  }\n  return new Date(event.start);\n}\n\nfunction shapeClassOf(\n  shape: EventShape,\n  isFirstDay: boolean,\n  isLastDay: boolean\n) {\n  if (shape === 'dot') {\n    return EVENT_DOT_ROW;\n  }\n  const radius = getBorderRadiusClasses(isFirstDay, isLastDay);\n  return cn(EVENT_BLOCK, radius);\n}\n\nfunction accessibleLabelOf(event: CalendarEvent, start: Date, end: Date) {\n  if (event.allDay) {\n    return `${event.title}, all day`;\n  }\n  return `${event.title}, ${timeRangeLabelOf(start, end)}`;\n}\n\n/** Times stay visible in a popover or a drag preview, and follow the cell width elsewhere. */\nfunction monthTimeClassOf(showTime: boolean | undefined) {\n  if (showTime) {\n    return '';\n  }\n  return 'hidden @3xl:inline';\n}\n\nfunction eventTimeLabelOf(event: CalendarEvent, start: Date, end: Date) {\n  if (event.allDay) {\n    return 'All day';\n  }\n  return timeRangeLabelOf(start, end);\n}\n\ntype DndProps = {\n  dndListeners?: DraggableSyntheticListeners;\n  dndAttributes?: DraggableAttributes;\n};\n\ntype EventWrapperProps = DndProps & {\n  event: CalendarEvent;\n  shape: EventShape;\n  start: Date;\n  end: Date;\n  isFirstDay?: boolean;\n  isLastDay?: boolean;\n  isDragging?: boolean;\n  tabIndex?: number;\n  onClick?: (event: React.MouseEvent) => void;\n  className?: string;\n  children: React.ReactNode;\n};\n\nfunction EventWrapper({\n  event,\n  shape,\n  start,\n  end,\n  isFirstDay = true,\n  isLastDay = true,\n  isDragging,\n  tabIndex,\n  onClick,\n  className,\n  children,\n  dndListeners,\n}: EventWrapperProps) {\n  const isEventInPast = isPast(end);\n\n  // Dragging is for the pointer only: the keyboard moves an event with the dialog's date and\n  // time fields, so dnd-kit's keyboard drag hints are not given to assistive technology.\n  return (\n    <button\n      type='button'\n      className={cn(\n        EVENT_SHARED,\n        shapeClassOf(shape, isFirstDay, isLastDay),\n        className\n      )}\n      style={eventChipStyle(event.color)}\n      data-dragging={isDragging || undefined}\n      data-past-event={isEventInPast || undefined}\n      onClick={onClick}\n      {...dndListeners}\n      aria-label={accessibleLabelOf(event, start, end)}\n      tabIndex={tabIndex}\n    >\n      {children}\n    </button>\n  );\n}\n\ntype MonthLabelProps = {\n  event: CalendarEvent;\n  start: Date;\n  showTime?: boolean;\n};\n\nfunction MonthDotLabel({ event, start, showTime }: MonthLabelProps) {\n  return (\n    <>\n      <span\n        aria-hidden='true'\n        className='size-1.5 shrink-0 rounded-full bg-(--chip)'\n      />\n      <span\n        className={cn(\n          'text-muted-foreground shrink-0 tabular-nums',\n          monthTimeClassOf(showTime)\n        )}\n      >\n        {clockLabelOf(start)}\n      </span>\n      <span className='truncate font-medium'>{event.title}</span>\n    </>\n  );\n}\n\nfunction MonthBarLabel({ event, start, showTime }: MonthLabelProps) {\n  const isTimed = !event.allDay;\n\n  return (\n    <span className='truncate'>\n      {isTimed && (\n        <span\n          className={cn(\n            'font-normal tabular-nums opacity-75',\n            monthTimeClassOf(showTime)\n          )}\n        >\n          {clockLabelOf(start)}{' '}\n        </span>\n      )}\n      {event.title}\n    </span>\n  );\n}\n\ntype EventItemProps = DndProps & {\n  event: CalendarEvent;\n  view: CalendarView;\n  isDragging?: boolean;\n  onClick?: (event: React.MouseEvent) => void;\n  showTime?: boolean;\n  currentTime?: Date;\n  isFirstDay?: boolean;\n  isLastDay?: boolean;\n  /** `-1` for the copies of a multi-day event, so it takes one tab stop. */\n  tabIndex?: number;\n  children?: React.ReactNode;\n  className?: string;\n};\n\nexport function EventItem(props: EventItemProps) {\n  const {\n    event,\n    view,\n    isDragging,\n    onClick,\n    showTime,\n    currentTime,\n    isFirstDay = true,\n    isLastDay = true,\n    tabIndex,\n    children,\n    className,\n    dndListeners,\n  } = props;\n  const start = startOf(event, currentTime);\n  const end = shiftedEndOf(event, currentTime);\n  const isShortEvent = differenceInMinutes(end, start) < SHORT_EVENT_MINUTES;\n  const sharedProps = {\n    event,\n    start,\n    end,\n    isFirstDay,\n    isLastDay,\n    isDragging,\n    tabIndex,\n    onClick,\n    dndListeners,\n  };\n\n  if (view === 'agenda') {\n    return (\n      <EventListRow\n        event={event}\n        day={start}\n        onClick={onClick}\n        className={className}\n      />\n    );\n  }\n\n  if (view === 'month') {\n    const isSpan = isMultiDayEvent(event);\n    let shape: EventShape = 'dot';\n    if (isSpan) {\n      shape = 'block';\n    }\n    let label = (\n      <MonthDotLabel event={event} start={start} showTime={showTime} />\n    );\n    if (isSpan) {\n      label = <MonthBarLabel event={event} start={start} showTime={showTime} />;\n    }\n\n    return (\n      <EventWrapper\n        {...sharedProps}\n        shape={shape}\n        className={cn(\n          'mt-(--event-gap) h-(--event-height) items-center text-[11px] @3xl:text-xs',\n          className\n        )}\n      >\n        {children ?? label}\n      </EventWrapper>\n    );\n  }\n\n  return (\n    <EventWrapper\n      {...sharedProps}\n      shape='block'\n      className={cn(\n        'py-1 text-[11px] @3xl:text-xs',\n        isShortEvent && 'items-center',\n        !isShortEvent && 'flex-col',\n        className\n      )}\n    >\n      {isShortEvent && (\n        <span className='truncate'>\n          {event.title}{' '}\n          {showTime && (\n            <span className='font-normal tabular-nums opacity-75'>\n              {clockLabelOf(start)}\n            </span>\n          )}\n        </span>\n      )}\n      {!isShortEvent && (\n        <>\n          <span className='truncate'>{event.title}</span>\n          {showTime && (\n            <span className='truncate font-normal tabular-nums opacity-75'>\n              {eventTimeLabelOf(event, start, end)}\n            </span>\n          )}\n        </>\n      )}\n    </EventWrapper>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/event-calendar/_parts/event-item.tsx"
    },
    {
      "path": "registry/ndeko/components/event-calendar/_parts/event-list-row.tsx",
      "content": "'use client';\n\nimport { isPast } from 'date-fns';\n\nimport { cn } from '@/registry/ndeko/lib/utils';\n\nimport type { CalendarEvent } from './types';\nimport { eventChipStyle, timeLabelOnDay } from './utils';\n\nconst ROW = [\n  'flex w-full cursor-pointer items-start gap-3 rounded-md px-2 py-2 text-left text-[13px] outline-none',\n  'transition-colors duration-150 hover:bg-foreground/[0.04]',\n  'focus-visible:ring-[3px] focus-visible:ring-ring/25',\n  'data-past-event:opacity-60',\n].join(' ');\n\ntype EventListRowProps = {\n  event: CalendarEvent;\n  /** The day the row is listed under, so a multi-day event says when it runs that day. */\n  day: Date;\n  onClick?: (clickEvent: React.MouseEvent) => void;\n  className?: string;\n};\n\n/** One event in a list: its colour, when it runs that day, its title and its place. */\nexport function EventListRow({\n  event,\n  day,\n  onClick,\n  className,\n}: EventListRowProps) {\n  const end = new Date(event.end);\n  const isEventInPast = isPast(end);\n  const hasLocation = Boolean(event.location);\n\n  return (\n    <button\n      type='button'\n      className={cn(ROW, className)}\n      style={eventChipStyle(event.color)}\n      data-past-event={isEventInPast || undefined}\n      onClick={onClick}\n    >\n      <span\n        aria-hidden='true'\n        className='mt-[5px] size-2 shrink-0 rounded-full bg-(--chip)'\n      />\n      <span className='text-muted-foreground w-20 shrink-0 tabular-nums @2xl:w-32'>\n        {timeLabelOnDay(event, day)}\n      </span>\n      <span className='flex min-w-0 flex-1 flex-col gap-0.5'>\n        <span className='truncate font-medium'>{event.title}</span>\n        {hasLocation && (\n          <span className='text-muted-foreground truncate text-xs'>\n            {event.location}\n          </span>\n        )}\n      </span>\n    </button>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/event-calendar/_parts/event-list-row.tsx"
    },
    {
      "path": "registry/ndeko/components/event-calendar/_parts/index.ts",
      "content": "export { AgendaView } from './agenda-view';\nexport { CalendarDndProvider, useCalendarDnd } from './calendar-dnd-context';\nexport { CalendarHeader } from './calendar-header';\nexport { DayEventsPanel } from './day-events-panel';\nexport { DayView } from './day-view';\nexport { DraggableEvent } from './draggable-event';\nexport { DroppableCell } from './droppable-cell';\nexport { EventCalendar, type EventCalendarProps } from './event-calendar';\nexport { EventDialog } from './event-dialog';\nexport { EventItem } from './event-item';\nexport { EventListRow } from './event-list-row';\nexport { MiniMonth } from './mini-month';\nexport { MonthView } from './month-view';\nexport { ViewSwitcher } from './view-switcher';\nexport { WeekView } from './week-view';\nexport { YearView } from './year-view';\n\nexport * from './constants';\nexport * from './navigation';\nexport * from './utils';\n\nexport * from './use-current-time-indicator';\nexport * from './use-event-editor';\nexport * from './use-event-list';\nexport * from './use-event-visibility';\nexport * from './use-roving-day';\n\nexport type {\n  CalendarEvent,\n  CalendarView,\n  EventColor,\n  EventColorOption,\n  TimedView,\n} from './types';\n",
      "type": "registry:component",
      "target": "components/event-calendar/_parts/index.ts"
    },
    {
      "path": "registry/ndeko/components/event-calendar/_parts/mini-month.tsx",
      "content": "'use client';\n\nimport { useMemo } from 'react';\n\nimport { Calendar } from '@/registry/ndeko/ui/calendar';\n\nimport { dayKeyOf } from './navigation';\nimport type { CalendarEvent } from './types';\nimport { eventDayCountsOf } from './utils';\n\n/** A small dot under the number of a day with events, light on the picked day. */\nconst BUSY_MARK = [\n  '*:before:pointer-events-none *:before:absolute *:before:bottom-1 *:before:start-1/2 *:before:size-[3px] *:before:-translate-x-1/2 *:before:rounded-full *:before:bg-foreground/40',\n  '[&[data-selected]>*]:before:bg-primary-foreground/70',\n].join(' ');\n\nconst COMPACT_CLASS_NAMES = {\n  month_caption: 'mx-8 h-8',\n  weekday: 'size-8',\n  day: 'size-8',\n  day_button: 'size-8',\n};\n\ntype MiniMonthProps = {\n  events: CalendarEvent[];\n  selected: Date;\n  onSelect: (day: Date) => void;\n  /** The month on screen, when the parent follows it. */\n  month?: Date;\n  onMonthChange?: (month: Date) => void;\n  className?: string;\n};\n\n/** A month to pick a day from, with a dot on the days that hold events. */\nexport function MiniMonth({\n  events,\n  selected,\n  onSelect,\n  month,\n  onMonthChange,\n  className,\n}: MiniMonthProps) {\n  const counts = useMemo(() => eventDayCountsOf(events), [events]);\n\n  function isBusy(day: Date) {\n    const dayKey = dayKeyOf(day);\n    return counts.has(dayKey);\n  }\n\n  function pick(day: Date | undefined) {\n    if (day) {\n      onSelect(day);\n    }\n  }\n\n  return (\n    <Calendar\n      mode='single'\n      required\n      selected={selected}\n      onSelect={pick}\n      month={month}\n      onMonthChange={onMonthChange}\n      defaultMonth={selected}\n      modifiers={{ busy: isBusy }}\n      modifiersClassNames={{ busy: BUSY_MARK }}\n      classNames={COMPACT_CLASS_NAMES}\n      className={className}\n    />\n  );\n}\n",
      "type": "registry:component",
      "target": "components/event-calendar/_parts/mini-month.tsx"
    },
    {
      "path": "registry/ndeko/components/event-calendar/_parts/month-view.tsx",
      "content": "'use client';\n\nimport {\n  addDays,\n  eachDayOfInterval,\n  endOfMonth,\n  endOfWeek,\n  format,\n  isSameDay,\n  isSameMonth,\n  isToday,\n  startOfDay,\n  startOfMonth,\n  startOfWeek,\n} from 'date-fns';\nimport { useMemo, useState } from 'react';\n\nimport { cn } from '@/registry/ndeko/lib/utils';\nimport {\n  Popover,\n  PopoverContent,\n  PopoverTrigger,\n} from '@/registry/ndeko/ui/popover';\n\nimport {\n  DefaultStartHour,\n  EventGap,\n  EventHeight,\n  WeekStartsOn,\n} from './constants';\nimport { DraggableEvent } from './draggable-event';\nimport { DroppableCell } from './droppable-cell';\nimport { EventItem } from './event-item';\nimport { dayKeyOf } from './navigation';\nimport type { CalendarEvent } from './types';\nimport { useEventVisibility } from './use-event-visibility';\nimport { useRovingDay } from './use-roving-day';\nimport {\n  ariaCurrentDateOf,\n  eventCountLabelOf,\n  getAllEventsForDay,\n  getEventsForDay,\n  getSpanningEventsForDay,\n  sortEvents,\n} from './utils';\n\nconst REFERENCE_SUNDAY = new Date(2023, 0, 1);\n\nconst WEEKDAYS = Array.from({ length: 7 }, (_, index) =>\n  format(addDays(REFERENCE_SUNDAY, index), 'EEE')\n);\n\nconst DAY_NUMBER =\n  'mt-1 inline-flex size-6 shrink-0 items-center justify-center self-start rounded-full text-[13px] tabular-nums data-today:bg-primary data-today:font-medium data-today:text-primary-foreground';\n\nconst DAY_NUMBER_BUTTON = cn(\n  DAY_NUMBER,\n  'cursor-pointer outline-none transition-[background-color,scale] duration-150 ease-(--ease-out-strong) active:scale-90',\n  'not-data-today:hover:bg-foreground/[0.07] focus-visible:ring-[3px] focus-visible:ring-ring/25'\n);\n\n/** Room for two events on a narrow calendar, up to four on a wide one. */\nconst CELL_CONTENT_AUTO =\n  'min-h-[calc((var(--event-height)+var(--event-gap))*2)] @2xl:min-h-[calc((var(--event-height)+var(--event-gap))*3)] @4xl:min-h-[calc((var(--event-height)+var(--event-gap))*4)]';\n\nconst CELL_CONTENT_FILL = 'min-h-[calc(var(--event-height)+var(--event-gap))]';\n\ntype MonthViewProps = {\n  currentDate: Date;\n  events: CalendarEvent[];\n  onEventSelect: (event: CalendarEvent) => void;\n  onEventCreate: (startTime: Date) => void;\n  /** Opens a day, for example in the day view. Without it the day numbers are plain text. */\n  onDaySelect?: (day: Date) => void;\n  /** The rows share the height of the calendar instead of growing to their events. */\n  fillHeight?: boolean;\n};\n\nfunction weeksOf(days: Date[]) {\n  const weeks: Date[][] = [];\n  for (let index = 0; index < days.length; index += 7) {\n    weeks.push(days.slice(index, index + 7));\n  }\n  return weeks;\n}\n\nfunction cellContentClassOf(fillHeight: boolean | undefined) {\n  if (fillHeight) {\n    return CELL_CONTENT_FILL;\n  }\n  return CELL_CONTENT_AUTO;\n}\n\nfunction dayLabelOf(day: Date, eventCount: number) {\n  const date = format(day, 'EEEE, MMMM d');\n  if (eventCount === 0) {\n    return date;\n  }\n  return `${date}, ${eventCountLabelOf(eventCount)}`;\n}\n\ntype MoreEventsProps = {\n  day: Date;\n  events: CalendarEvent[];\n  remainingCount: number;\n  onEventSelect: (event: CalendarEvent) => void;\n};\n\nfunction MoreEvents({\n  day,\n  events,\n  remainingCount,\n  onEventSelect,\n}: MoreEventsProps) {\n  const [isOpen, setIsOpen] = useState(false);\n\n  function selectEvent(event: CalendarEvent, clickEvent: React.MouseEvent) {\n    clickEvent.stopPropagation();\n    setIsOpen(false);\n    onEventSelect(event);\n  }\n\n  return (\n    <Popover modal open={isOpen} onOpenChange={setIsOpen}>\n      <PopoverTrigger\n        className='text-muted-foreground hover:text-foreground focus-visible:ring-ring/25 hover:bg-foreground/5 mt-(--event-gap) flex h-(--event-height) w-full cursor-pointer items-center overflow-hidden rounded-sm px-1 text-left text-[11px] font-medium tabular-nums outline-none select-none focus-visible:ring-[3px] @3xl:px-1.5 @3xl:text-xs'\n        aria-label={`${remainingCount} more on ${format(day, 'EEEE, MMMM d')}`}\n        onClick={(clickEvent) => clickEvent.stopPropagation()}\n      >\n        +{remainingCount} more\n      </PopoverTrigger>\n      <PopoverContent\n        align='center'\n        className='w-60 p-2'\n        style={\n          {\n            '--event-height': `${EventHeight}px`,\n            '--event-gap': `${EventGap}px`,\n          } as React.CSSProperties\n        }\n      >\n        <p className='px-1.5 pt-1 pb-0.5 text-[13px] font-medium'>\n          {format(day, 'EEEE, MMMM d')}\n        </p>\n        <div className='flex flex-col'>\n          {sortEvents(events).map((event) => (\n            <EventItem\n              key={event.id}\n              onClick={(clickEvent) => selectEvent(event, clickEvent)}\n              event={event}\n              view='month'\n              showTime\n              isFirstDay={isSameDay(day, new Date(event.start))}\n              isLastDay={isSameDay(day, new Date(event.end))}\n            />\n          ))}\n        </div>\n      </PopoverContent>\n    </Popover>\n  );\n}\n\ntype DayEventProps = {\n  event: CalendarEvent;\n  day: Date;\n  isHidden: boolean;\n  onEventClick: (event: CalendarEvent, clickEvent: React.MouseEvent) => void;\n};\n\nfunction DayEvent({ event, day, isHidden, onEventClick }: DayEventProps) {\n  const isFirstDay = isSameDay(day, new Date(event.start));\n  const isLastDay = isSameDay(day, new Date(event.end));\n\n  if (!isFirstDay) {\n    return (\n      <div className='aria-hidden:hidden' aria-hidden={isHidden || undefined}>\n        <EventItem\n          onClick={(clickEvent) => onEventClick(event, clickEvent)}\n          event={event}\n          view='month'\n          tabIndex={-1}\n          isFirstDay={isFirstDay}\n          isLastDay={isLastDay}\n        >\n          <span aria-hidden='true' />\n        </EventItem>\n      </div>\n    );\n  }\n\n  return (\n    <div className='aria-hidden:hidden' aria-hidden={isHidden || undefined}>\n      <DraggableEvent\n        event={event}\n        view='month'\n        onClick={(clickEvent) => onEventClick(event, clickEvent)}\n        isFirstDay={isFirstDay}\n        isLastDay={isLastDay}\n      />\n    </div>\n  );\n}\n\ntype DayNumberProps = {\n  day: Date;\n  eventCount: number;\n  tabIndex: number;\n  onDaySelect?: (day: Date) => void;\n  onFocusDay: (day: Date) => void;\n};\n\nfunction DayNumber({\n  day,\n  eventCount,\n  tabIndex,\n  onDaySelect,\n  onFocusDay,\n}: DayNumberProps) {\n  const isTodayCell = isToday(day);\n  const dayNumber = format(day, 'd');\n\n  if (!onDaySelect) {\n    return (\n      <span className={DAY_NUMBER} data-today={isTodayCell || undefined}>\n        {dayNumber}\n      </span>\n    );\n  }\n\n  function openDay(clickEvent: React.MouseEvent) {\n    clickEvent.stopPropagation();\n    onDaySelect?.(day);\n  }\n\n  return (\n    <button\n      type='button'\n      className={DAY_NUMBER_BUTTON}\n      data-today={isTodayCell || undefined}\n      data-day={dayKeyOf(day)}\n      tabIndex={tabIndex}\n      aria-label={dayLabelOf(day, eventCount)}\n      aria-current={ariaCurrentDateOf(isTodayCell)}\n      onClick={openDay}\n      onFocus={() => onFocusDay(day)}\n    >\n      {dayNumber}\n    </button>\n  );\n}\n\nexport function MonthView({\n  currentDate,\n  events,\n  onEventSelect,\n  onEventCreate,\n  onDaySelect,\n  fillHeight,\n}: MonthViewProps) {\n  const monthStart = startOfMonth(currentDate);\n  const monthEnd = startOfDay(endOfMonth(currentDate));\n  const weeks = useMemo(() => {\n    const firstDay = startOfMonth(currentDate);\n    const lastDay = endOfMonth(firstDay);\n    const calendarStart = startOfWeek(firstDay, { weekStartsOn: WeekStartsOn });\n    const calendarEnd = endOfWeek(lastDay, { weekStartsOn: WeekStartsOn });\n    const days = eachDayOfInterval({ start: calendarStart, end: calendarEnd });\n    return weeksOf(days);\n  }, [currentDate]);\n  const { contentRef, contentHeight, getVisibleEventCount } =\n    useEventVisibility({ eventHeight: EventHeight, eventGap: EventGap });\n  const { gridRef, handleKeyDown, tabIndexOf, rememberDay } = useRovingDay({\n    defaultDay: currentDate,\n    firstDay: monthStart,\n    lastDay: monthEnd,\n  });\n  const isMeasured = contentHeight !== null;\n\n  function handleEventClick(\n    event: CalendarEvent,\n    clickEvent: React.MouseEvent\n  ) {\n    clickEvent.stopPropagation();\n    onEventSelect(event);\n  }\n\n  function createEventOn(day: Date) {\n    const startTime = new Date(day);\n    startTime.setHours(DefaultStartHour, 0, 0);\n    onEventCreate(startTime);\n  }\n\n  return (\n    <div data-slot='month-view' className='flex min-h-0 flex-1 flex-col'>\n      <div className='hairline-b border-border grid grid-cols-7'>\n        {WEEKDAYS.map((weekday) => (\n          <div\n            key={weekday}\n            className='text-muted-foreground py-2 text-center text-xs @3xl:text-[13px]'\n          >\n            {weekday}\n          </div>\n        ))}\n      </div>\n      <div\n        ref={gridRef}\n        onKeyDown={handleKeyDown}\n        className={cn(\n          'grid min-h-0 flex-1 auto-rows-fr',\n          fillHeight && 'overflow-y-auto'\n        )}\n      >\n        {weeks.map((week, weekIndex) => (\n          <div\n            key={dayKeyOf(week[0])}\n            className='grid grid-cols-7 [&:last-child>*]:border-b-0'\n          >\n            {week.map((day, dayIndex) => {\n              const dayEvents = getEventsForDay(events, day);\n              const spanningEvents = getSpanningEventsForDay(events, day);\n              const cellEvents = sortEvents([...spanningEvents, ...dayEvents]);\n              const isCurrentMonth = isSameMonth(day, currentDate);\n              const isReferenceCell = weekIndex === 0 && dayIndex === 0;\n              let visibleCount = 0;\n              if (isMeasured) {\n                visibleCount = getVisibleEventCount(cellEvents.length);\n              }\n              const remainingCount = cellEvents.length - visibleCount;\n              const hasMore = isMeasured && remainingCount > 0;\n              let contentRefOfCell: React.RefObject<HTMLDivElement | null> | null =\n                null;\n              if (isReferenceCell) {\n                contentRefOfCell = contentRef;\n              }\n\n              return (\n                <div\n                  key={dayKeyOf(day)}\n                  className='hairline-b hairline-r border-border data-outside-cell:bg-foreground/[0.025] data-outside-cell:text-muted-foreground last:border-r-0'\n                  data-outside-cell={!isCurrentMonth || undefined}\n                >\n                  <DroppableCell\n                    id={`month-cell-${dayKeyOf(day)}`}\n                    date={day}\n                    className='not-data-dragging:hover:bg-foreground/[0.02] cursor-pointer'\n                    onClick={() => createEventOn(day)}\n                  >\n                    <DayNumber\n                      day={day}\n                      eventCount={cellEvents.length}\n                      tabIndex={tabIndexOf(day)}\n                      onDaySelect={onDaySelect}\n                      onFocusDay={rememberDay}\n                    />\n                    <div\n                      ref={contentRefOfCell}\n                      className={cn('flex-1', cellContentClassOf(fillHeight))}\n                    >\n                      {visibleCount > 0 &&\n                        cellEvents.map((event, index) => (\n                          <DayEvent\n                            key={`${event.id}-${dayKeyOf(day)}`}\n                            event={event}\n                            day={day}\n                            isHidden={index >= visibleCount}\n                            onEventClick={handleEventClick}\n                          />\n                        ))}\n                      {hasMore && (\n                        <MoreEvents\n                          day={day}\n                          events={getAllEventsForDay(events, day)}\n                          remainingCount={remainingCount}\n                          onEventSelect={onEventSelect}\n                        />\n                      )}\n                    </div>\n                  </DroppableCell>\n                </div>\n              );\n            })}\n          </div>\n        ))}\n      </div>\n    </div>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/event-calendar/_parts/month-view.tsx"
    },
    {
      "path": "registry/ndeko/components/event-calendar/_parts/navigation.ts",
      "content": "import {\n  addDays,\n  addMonths,\n  addWeeks,\n  addYears,\n  endOfWeek,\n  format,\n  getWeek,\n  isSameMonth,\n  isSameYear,\n  isToday,\n  isTomorrow,\n  isYesterday,\n  startOfWeek,\n} from 'date-fns';\n\nimport { AgendaDaysToShow, WeekStartsOn } from './constants';\nimport type { CalendarView } from './types';\n\nexport type PeriodTitle = {\n  full: string;\n  short: string;\n};\n\ntype PeriodRange = {\n  start: Date;\n  end: Date;\n};\n\nconst PERIOD_UNITS: Record<CalendarView, string> = {\n  day: 'day',\n  week: 'week',\n  month: 'month',\n  year: 'year',\n  agenda: `${AgendaDaysToShow} days`,\n};\n\n/** A local calendar day as `yyyy-MM-dd`, stable across time zones. */\nexport function dayKeyOf(day: Date) {\n  return format(day, 'yyyy-MM-dd');\n}\n\nexport function shiftDate(date: Date, view: CalendarView, step: number) {\n  if (view === 'year') {\n    return addYears(date, step);\n  }\n  if (view === 'month') {\n    return addMonths(date, step);\n  }\n  if (view === 'week') {\n    return addWeeks(date, step);\n  }\n  if (view === 'day') {\n    return addDays(date, step);\n  }\n  return addDays(date, step * AgendaDaysToShow);\n}\n\nexport function periodKeyOf(date: Date, view: CalendarView) {\n  if (view === 'year') {\n    return format(date, 'yyyy');\n  }\n  if (view === 'month') {\n    return format(date, 'yyyy-MM');\n  }\n  if (view === 'week') {\n    const weekStart = startOfWeek(date, { weekStartsOn: WeekStartsOn });\n    return dayKeyOf(weekStart);\n  }\n  return dayKeyOf(date);\n}\n\nexport function periodUnitOf(view: CalendarView) {\n  return PERIOD_UNITS[view];\n}\n\nfunction periodRangeOf(date: Date, view: CalendarView): PeriodRange {\n  if (view === 'week') {\n    const start = startOfWeek(date, { weekStartsOn: WeekStartsOn });\n    const end = endOfWeek(date, { weekStartsOn: WeekStartsOn });\n    return { start, end };\n  }\n  const end = addDays(date, AgendaDaysToShow - 1);\n  return { start: date, end };\n}\n\nfunction fullRangeTitleOf({ start, end }: PeriodRange) {\n  if (!isSameYear(start, end)) {\n    const startLabel = format(start, 'MMM d, yyyy');\n    const endLabel = format(end, 'MMM d, yyyy');\n    return `${startLabel} – ${endLabel}`;\n  }\n  if (!isSameMonth(start, end)) {\n    const startLabel = format(start, 'MMM d');\n    const endLabel = format(end, 'MMM d, yyyy');\n    return `${startLabel} – ${endLabel}`;\n  }\n  const startLabel = format(start, 'MMM d');\n  const endLabel = format(end, 'd, yyyy');\n  return `${startLabel} – ${endLabel}`;\n}\n\nfunction shortRangeTitleOf({ start, end }: PeriodRange) {\n  const startLabel = format(start, 'MMM d');\n  if (!isSameMonth(start, end)) {\n    const endLabel = format(end, 'MMM d');\n    return `${startLabel} – ${endLabel}`;\n  }\n  const endLabel = format(end, 'd');\n  return `${startLabel} – ${endLabel}`;\n}\n\n/** The heading of a period, in full and in a short form for narrow headers. */\nexport function periodTitleOf(date: Date, view: CalendarView): PeriodTitle {\n  if (view === 'year') {\n    const year = format(date, 'yyyy');\n    return { full: year, short: year };\n  }\n  if (view === 'month') {\n    const full = format(date, 'MMMM yyyy');\n    const short = format(date, 'MMM yyyy');\n    return { full, short };\n  }\n  if (view === 'day') {\n    const full = format(date, 'EEEE, MMMM d, yyyy');\n    const short = format(date, 'EEE, MMM d');\n    return { full, short };\n  }\n  const range = periodRangeOf(date, view);\n  return { full: fullRangeTitleOf(range), short: shortRangeTitleOf(range) };\n}\n\nfunction relativeDayOf(date: Date) {\n  if (isToday(date)) {\n    return 'Today';\n  }\n  if (isTomorrow(date)) {\n    return 'Tomorrow';\n  }\n  if (isYesterday(date)) {\n    return 'Yesterday';\n  }\n  return null;\n}\n\n/** A short hint beside the heading: the week number, or where the day sits from today. */\nexport function periodCaptionOf(date: Date, view: CalendarView) {\n  if (view === 'week') {\n    const weekNumber = getWeek(date, { weekStartsOn: WeekStartsOn });\n    return `Week ${weekNumber}`;\n  }\n  if (view === 'day') {\n    return relativeDayOf(date);\n  }\n  return null;\n}\n",
      "type": "registry:component",
      "target": "components/event-calendar/_parts/navigation.ts"
    },
    {
      "path": "registry/ndeko/components/event-calendar/_parts/sample-events.ts",
      "content": "import {\n  addDays,\n  addMonths,\n  addWeeks,\n  endOfDay,\n  getDay,\n  setHours,\n  setMinutes,\n  startOfDay,\n  startOfMonth,\n  startOfWeek,\n} from 'date-fns';\n\nimport { WeekStartsOn } from './constants';\nimport type { CalendarEvent, EventColor } from './types';\n\nconst THURSDAY = 4;\nconst TUESDAY = 2;\nconst SPRINT_WEEKS = 2;\n\ntype EventDetails = {\n  title: string;\n  color: EventColor;\n  location?: string;\n  description?: string;\n};\n\nexport type TimedSpec = EventDetails & {\n  day: Date;\n  /** Hours as a number: 9.5 is 9:30. */\n  from: number;\n  to: number;\n  /** For an event that ends on a later day. */\n  endDay?: Date;\n};\n\nexport type AllDaySpec = EventDetails & {\n  first: Date;\n  last: Date;\n};\n\n/** A time on a day, from hours written as a number: 14.75 is 2:45 pm. */\nexport function hourOn(day: Date, hour: number) {\n  const wholeHours = Math.floor(hour);\n  const minutes = Math.round((hour - wholeHours) * 60);\n  const dayStart = startOfDay(day);\n  const withHours = setHours(dayStart, wholeHours);\n  return setMinutes(withHours, minutes);\n}\n\nexport function timedEvent(id: string, spec: TimedSpec): CalendarEvent {\n  const endDay = spec.endDay ?? spec.day;\n  return {\n    id,\n    title: spec.title,\n    description: spec.description,\n    location: spec.location,\n    color: spec.color,\n    start: hourOn(spec.day, spec.from),\n    end: hourOn(endDay, spec.to),\n  };\n}\n\nexport function allDayEvent(id: string, spec: AllDaySpec): CalendarEvent {\n  return {\n    id,\n    title: spec.title,\n    description: spec.description,\n    location: spec.location,\n    color: spec.color,\n    start: startOfDay(spec.first),\n    end: endOfDay(spec.last),\n    allDay: true,\n  };\n}\n\n/** The same weekday every few weeks, from `firstStep` to `lastStep` steps around today's week. */\nexport function everyFewWeeks(\n  today: Date,\n  weekday: number,\n  weeksApart: number,\n  firstStep: number,\n  lastStep: number\n) {\n  const weekStart = startOfWeek(today, { weekStartsOn: WeekStartsOn });\n  const anchor = addDays(weekStart, weekday - WeekStartsOn);\n  const days: Date[] = [];\n  for (let step = firstStep; step <= lastStep; step++) {\n    days.push(addWeeks(anchor, step * weeksApart));\n  }\n  return days;\n}\n\n/** The first given weekday of each month, from `firstMonth` to `lastMonth` months around today. */\nexport function firstWeekdayOfMonths(\n  today: Date,\n  weekday: number,\n  firstMonth: number,\n  lastMonth: number\n) {\n  const days: Date[] = [];\n  for (let step = firstMonth; step <= lastMonth; step++) {\n    const monthStart = startOfMonth(addMonths(today, step));\n    const offset = (weekday - getDay(monthStart) + 7) % 7;\n    days.push(addDays(monthStart, offset));\n  }\n  return days;\n}\n\nfunction upcomingEvents(today: Date): CalendarEvent[] {\n  function on(offset: number) {\n    return addDays(today, offset);\n  }\n\n  return [\n    timedEvent('standup-0', {\n      title: 'Team standup',\n      day: today,\n      from: 9.5,\n      to: 9.75,\n      color: 'primary',\n      location: 'Room 2B',\n    }),\n    timedEvent('roadmap', {\n      title: 'Roadmap review',\n      day: today,\n      from: 11,\n      to: 12.5,\n      color: 'info',\n      location: 'Room 4A',\n      description: 'Priorities for the next two quarters',\n    }),\n    timedEvent('interview', {\n      title: 'Interview: product designer',\n      day: today,\n      from: 14,\n      to: 15,\n      color: 'warning',\n      location: 'Video call',\n    }),\n    timedEvent('one-on-one', {\n      title: '1:1 with Tomasz',\n      day: today,\n      from: 16.5,\n      to: 17,\n      color: 'success',\n      location: 'Corner booth',\n    }),\n    timedEvent('standup-1', {\n      title: 'Team standup',\n      day: on(1),\n      from: 9.5,\n      to: 9.75,\n      color: 'primary',\n      location: 'Room 2B',\n    }),\n    timedEvent('critique', {\n      title: 'Design critique',\n      day: on(1),\n      from: 10,\n      to: 11.5,\n      color: 'warning',\n      location: 'Studio',\n      description: 'Onboarding screens, second round',\n    }),\n    timedEvent('client-lunch', {\n      title: 'Lunch with a client',\n      day: on(1),\n      from: 12.5,\n      to: 13.75,\n      color: 'success',\n      location: 'Harbour cafe',\n    }),\n    timedEvent('customer-call', {\n      title: 'Customer call',\n      day: on(2),\n      from: 15,\n      to: 15.75,\n      color: 'info',\n      location: 'Video call',\n    }),\n    timedEvent('budget', {\n      title: 'Budget review',\n      day: on(-1),\n      from: 15,\n      to: 16,\n      color: 'warning',\n      location: 'Room 4A',\n    }),\n    allDayEvent('quarterly-planning', {\n      title: 'Quarterly planning',\n      first: on(-2),\n      last: on(-2),\n      color: 'info',\n      location: 'Main hall',\n    }),\n    allDayEvent('launch-week', {\n      title: 'Launch week',\n      first: on(3),\n      last: on(5),\n      color: 'primary',\n      description: 'The new release goes live',\n    }),\n    timedEvent('summit', {\n      title: 'Customer summit',\n      day: on(4),\n      endDay: on(5),\n      from: 14.5,\n      to: 14.75,\n      color: 'destructive',\n      location: 'Riverside centre',\n    }),\n    timedEvent('weekly-planning', {\n      title: 'Weekly planning',\n      day: on(6),\n      from: 10,\n      to: 11,\n      color: 'info',\n      location: 'Room 2B',\n    }),\n    timedEvent('retro', {\n      title: 'Sprint retro',\n      day: on(-6),\n      from: 10,\n      to: 11,\n      color: 'primary',\n      location: 'Room 2B',\n    }),\n    timedEvent('deadline', {\n      title: 'Project deadline',\n      day: on(-9),\n      from: 13,\n      to: 15.5,\n      color: 'warning',\n      location: 'Office',\n      description: 'Final deliverables are due',\n    }),\n    allDayEvent('freeze', {\n      title: 'Release freeze',\n      first: on(8),\n      last: on(8),\n      color: 'destructive',\n    }),\n    timedEvent('workshop', {\n      title: 'Marketing workshop',\n      day: on(9),\n      from: 10,\n      to: 15.5,\n      color: 'success',\n      location: 'Marketing floor',\n    }),\n    timedEvent('renewals', {\n      title: 'Contract renewals',\n      day: on(12),\n      from: 13,\n      to: 14,\n      color: 'warning',\n    }),\n    allDayEvent('offsite', {\n      title: 'Team offsite',\n      first: on(15),\n      last: on(16),\n      color: 'success',\n      location: 'Lakeside lodge',\n    }),\n    allDayEvent('board', {\n      title: 'Board meeting',\n      first: on(17),\n      last: on(17),\n      color: 'info',\n      location: 'Grand conference centre',\n    }),\n    timedEvent('interviews', {\n      title: 'User interviews',\n      day: on(21),\n      from: 11,\n      to: 12,\n      color: 'info',\n      location: 'Research room',\n    }),\n    timedEvent('research-sprint', {\n      title: 'Research sprint',\n      day: on(26),\n      endDay: on(27),\n      from: 9,\n      to: 17,\n      color: 'destructive',\n      location: 'Innovation lab',\n    }),\n    timedEvent('year-end-dinner', {\n      title: 'Year-end dinner',\n      day: on(38),\n      from: 19,\n      to: 22,\n      color: 'success',\n      location: 'Old mill',\n    }),\n    allDayEvent('annual-planning', {\n      title: 'Annual planning',\n      first: on(-24),\n      last: on(-23),\n      color: 'info',\n      location: 'Main hall',\n    }),\n    allDayEvent('security-audit', {\n      title: 'Security audit',\n      first: on(-45),\n      last: on(-43),\n      color: 'warning',\n    }),\n    allDayEvent('hack-week', {\n      title: 'Hack week',\n      first: on(-200),\n      last: on(-196),\n      color: 'success',\n    }),\n  ];\n}\n\nfunction sprintReviews(today: Date) {\n  const days = everyFewWeeks(today, THURSDAY, SPRINT_WEEKS, -22, 4);\n  return days.map((day, index) =>\n    timedEvent(`sprint-review-${index}`, {\n      title: 'Sprint review',\n      day,\n      from: 15,\n      to: 16,\n      color: 'primary',\n      location: 'Room 4A',\n    })\n  );\n}\n\nfunction allHands(today: Date) {\n  const days = firstWeekdayOfMonths(today, TUESDAY, -11, 2);\n  return days.map((day, index) =>\n    timedEvent(`all-hands-${index}`, {\n      title: 'Company all-hands',\n      day,\n      from: 16,\n      to: 17,\n      color: 'info',\n      location: 'Main hall',\n    })\n  );\n}\n\n/** Fictional events around today, spread so the day, week, month, year and agenda views all have some. */\nexport function buildSampleEvents(): CalendarEvent[] {\n  const today = new Date();\n  return [\n    ...upcomingEvents(today),\n    ...sprintReviews(today),\n    ...allHands(today),\n  ];\n}\n",
      "type": "registry:component",
      "target": "components/event-calendar/_parts/sample-events.ts"
    },
    {
      "path": "registry/ndeko/components/event-calendar/_parts/time-grid.tsx",
      "content": "'use client';\n\nimport {\n  addHours,\n  eachHourOfInterval,\n  format,\n  getHours,\n  startOfDay,\n} from 'date-fns';\nimport { useLayoutEffect, useRef } from 'react';\n\nimport { cn } from '@/registry/ndeko/lib/utils';\n\nimport { EndHour, ScrollToHour, StartHour, WeekCellsHeight } from './constants';\nimport { DraggableEvent } from './draggable-event';\nimport { DroppableCell } from './droppable-cell';\nimport type { CalendarEvent, TimedView } from './types';\nimport type { PositionedEvent } from './utils';\n\nconst QUARTERS = [0, 1, 2, 3];\n\n/** The hour labels sit half a line above their row, so the first one stays readable. */\nconst HOUR_LABEL_ROOM_PX = 16;\n\nexport function hoursOfDay(day: Date) {\n  const dayStart = startOfDay(day);\n  return eachHourOfInterval({\n    start: addHours(dayStart, StartHour),\n    end: addHours(dayStart, EndHour - 1),\n  });\n}\n\ntype TimeGridScrollerProps = {\n  label: string;\n  className?: string;\n  children: React.ReactNode;\n};\n\n/**\n * The scrolling area of the week and day views. It opens on the morning, keeps the day\n * headers on top and the hours on the left, and can be scrolled from the keyboard.\n */\nexport function TimeGridScroller({\n  label,\n  className,\n  children,\n}: TimeGridScrollerProps) {\n  const scrollerRef = useRef<HTMLDivElement>(null);\n\n  useLayoutEffect(() => {\n    const scroller = scrollerRef.current;\n    if (!scroller) {\n      return;\n    }\n    const hourTop = (ScrollToHour - StartHour) * WeekCellsHeight;\n    scroller.scrollTop = hourTop - HOUR_LABEL_ROOM_PX;\n  }, []);\n\n  return (\n    <div\n      ref={scrollerRef}\n      role='region'\n      aria-label={label}\n      tabIndex={0}\n      className={cn(\n        'max-h-(--calendar-scroll-height) min-h-0 flex-1 overflow-auto outline-none',\n        'focus-visible:ring-ring/25 rounded-b-xl focus-visible:ring-[3px] focus-visible:ring-inset',\n        className\n      )}\n    >\n      {children}\n    </div>\n  );\n}\n\nexport function HourLabels({ hours }: { hours: Date[] }) {\n  return (\n    <>\n      {hours.map((hour, index) => {\n        const hasLabel = index > 0;\n        return (\n          <div\n            key={hour.toString()}\n            className='hairline-b border-border relative h-(--week-cells-height) last:border-b-0'\n          >\n            {hasLabel && (\n              <span className='bg-card text-muted-foreground absolute -top-3 left-0 flex h-6 w-full items-center justify-end pe-2 text-[10px] tabular-nums @3xl:text-xs'>\n                {format(hour, 'h a')}\n              </span>\n            )}\n          </div>\n        );\n      })}\n    </>\n  );\n}\n\nexport function CurrentTimeLine({ position }: { position: number }) {\n  return (\n    <div\n      aria-hidden='true'\n      className='pointer-events-none absolute inset-x-0 z-20'\n      style={{ top: `${position}%` }}\n    >\n      <div className='relative flex items-center'>\n        <div className='bg-primary absolute -left-1 size-2 rounded-full' />\n        <div className='bg-primary h-0.5 w-full' />\n      </div>\n    </div>\n  );\n}\n\ntype PositionedEventsProps = {\n  positionedEvents: PositionedEvent[];\n  view: TimedView;\n  onEventClick: (event: CalendarEvent, clickEvent: React.MouseEvent) => void;\n};\n\nexport function PositionedEvents({\n  positionedEvents,\n  view,\n  onEventClick,\n}: PositionedEventsProps) {\n  return (\n    <>\n      {positionedEvents.map((positioned) => (\n        <div\n          key={positioned.event.id}\n          className='absolute z-10 px-0.5'\n          style={{\n            top: `${positioned.top}px`,\n            height: `${positioned.height}px`,\n            left: `${positioned.left * 100}%`,\n            width: `${positioned.width * 100}%`,\n            zIndex: positioned.zIndex,\n          }}\n          onClick={(clickEvent) => clickEvent.stopPropagation()}\n        >\n          <div className='size-full'>\n            <DraggableEvent\n              event={positioned.event}\n              view={view}\n              onClick={(clickEvent) =>\n                onEventClick(positioned.event, clickEvent)\n              }\n              showTime\n              height={positioned.height}\n            />\n          </div>\n        </div>\n      ))}\n    </>\n  );\n}\n\ntype QuarterSlotsProps = {\n  day: Date;\n  hours: Date[];\n  idPrefix: string;\n  onEventCreate: (startTime: Date) => void;\n};\n\n/** Four drop and click targets per hour, one for each quarter. */\nexport function QuarterSlots({\n  day,\n  hours,\n  idPrefix,\n  onEventCreate,\n}: QuarterSlotsProps) {\n  function createEventAt(hourValue: number, quarter: number) {\n    const startTime = new Date(day);\n    startTime.setHours(hourValue, quarter * 15);\n    onEventCreate(startTime);\n  }\n\n  return (\n    <>\n      {hours.map((hour) => {\n        const hourValue = getHours(hour);\n        return (\n          <div\n            key={hour.toString()}\n            className='hairline-b border-border relative h-(--week-cells-height) last:border-b-0'\n          >\n            {QUARTERS.map((quarter) => {\n              const quarterHourTime = hourValue + quarter * 0.25;\n              return (\n                <DroppableCell\n                  key={quarter}\n                  id={`${idPrefix}-${day.toISOString()}-${quarterHourTime}`}\n                  date={day}\n                  time={quarterHourTime}\n                  className='not-data-dragging:hover:bg-foreground/[0.03] absolute h-[calc(var(--week-cells-height)/4)] w-full cursor-pointer'\n                  style={{\n                    top: `calc(var(--week-cells-height) / 4 * ${quarter})`,\n                  }}\n                  onClick={() => createEventAt(hourValue, quarter)}\n                />\n              );\n            })}\n          </div>\n        );\n      })}\n    </>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/event-calendar/_parts/time-grid.tsx"
    },
    {
      "path": "registry/ndeko/components/event-calendar/_parts/types.ts",
      "content": "export type CalendarView = 'day' | 'week' | 'month' | 'year' | 'agenda';\n\nexport type TimedView = 'month' | 'week' | 'day';\n\nexport type EventColor =\n  'primary' | 'info' | 'success' | 'warning' | 'destructive';\n\nexport type EventColorOption = { value: EventColor; label: string };\n\nexport type CalendarEvent = {\n  id: string;\n  title: string;\n  description?: string;\n  start: Date;\n  end: Date;\n  allDay?: boolean;\n  color?: EventColor;\n  location?: string;\n};\n",
      "type": "registry:component",
      "target": "components/event-calendar/_parts/types.ts"
    },
    {
      "path": "registry/ndeko/components/event-calendar/_parts/use-current-time-indicator.ts",
      "content": "'use client';\n\nimport { endOfWeek, isSameDay, isWithinInterval, startOfWeek } from 'date-fns';\nimport { useSyncExternalStore } from 'react';\n\nimport { EndHour, StartHour } from './constants';\n\nconst MINUTE_MS = 60_000;\n\nfunction subscribeToMinutes(onMinute: () => void) {\n  const timer = window.setInterval(onMinute, MINUTE_MS);\n  return () => window.clearInterval(timer);\n}\n\nfunction currentMinute() {\n  const now = Date.now();\n  return Math.floor(now / MINUTE_MS) * MINUTE_MS;\n}\n\nfunction noMinuteOnServer() {\n  return null;\n}\n\nfunction isNowInView(now: Date, currentDate: Date, view: 'day' | 'week') {\n  if (view === 'day') {\n    return isSameDay(now, currentDate);\n  }\n  const weekStart = startOfWeek(currentDate, { weekStartsOn: 0 });\n  const weekEnd = endOfWeek(currentDate, { weekStartsOn: 0 });\n  return isWithinInterval(now, { start: weekStart, end: weekEnd });\n}\n\n/** Where the current time sits on the hour grid, as a percentage, refreshed every minute. */\nexport function useCurrentTimeIndicator(\n  currentDate: Date,\n  view: 'day' | 'week'\n) {\n  const minute = useSyncExternalStore(\n    subscribeToMinutes,\n    currentMinute,\n    noMinuteOnServer\n  );\n\n  if (minute === null) {\n    return { currentTimePosition: 0, currentTimeVisible: false };\n  }\n\n  const now = new Date(minute);\n  const minutesSinceStart =\n    (now.getHours() - StartHour) * 60 + now.getMinutes();\n  const minutesInView = (EndHour - StartHour) * 60;\n  const currentTimePosition = (minutesSinceStart / minutesInView) * 100;\n  const currentTimeVisible = isNowInView(now, currentDate, view);\n\n  return { currentTimePosition, currentTimeVisible };\n}\n",
      "type": "registry:component",
      "target": "components/event-calendar/_parts/use-current-time-indicator.ts"
    },
    {
      "path": "registry/ndeko/components/event-calendar/_parts/use-event-editor.ts",
      "content": "'use client';\n\nimport { addHours, format } from 'date-fns';\nimport { useState } from 'react';\nimport { toast } from 'sonner';\n\nimport type { CalendarEvent } from './types';\nimport { clockLabelOf, snapToQuarterHour } from './utils';\n\ntype EditorDialog = {\n  isOpen: boolean;\n  event: CalendarEvent | null;\n  session: number;\n};\n\nconst IDLE_DIALOG: EditorDialog = { isOpen: false, event: null, session: 0 };\n\nexport type EventEditorOptions = {\n  events: CalendarEvent[];\n  onEventAdd?: (event: CalendarEvent) => void;\n  onEventUpdate?: (event: CalendarEvent) => void;\n  onEventDelete?: (eventId: string) => void;\n};\n\nexport type EventEditor = {\n  /** Spread on `EventDialog`. */\n  dialogProps: {\n    event: CalendarEvent | null;\n    isOpen: boolean;\n    session: number;\n    onClose: () => void;\n    onSave: (event: CalendarEvent) => void;\n    onDelete: (eventId: string) => void;\n  };\n  openEvent: (event: CalendarEvent) => void;\n  openNewEvent: (startTime: Date) => void;\n  moveEvent: (event: CalendarEvent) => void;\n};\n\ntype UndoAction = {\n  label: string;\n  onClick: () => void;\n};\n\nfunction newEventId() {\n  return Math.random().toString(36).substring(2, 11);\n}\n\nfunction draftAt(startTime: Date): CalendarEvent {\n  const start = snapToQuarterHour(startTime);\n  const end = addHours(start, 1);\n  return { id: '', title: '', start, end, allDay: false };\n}\n\nfunction whenOf(event: CalendarEvent) {\n  const start = new Date(event.start);\n  const day = format(start, 'EEE, MMM d');\n  if (event.allDay) {\n    return day;\n  }\n  return `${day}, ${clockLabelOf(start)}`;\n}\n\nfunction notify(message: string, event: CalendarEvent, undo?: () => void) {\n  let action: UndoAction | undefined;\n  if (undo) {\n    action = { label: 'Undo', onClick: undo };\n  }\n  toast(message, {\n    description: whenOf(event),\n    action,\n    position: 'bottom-left',\n  });\n}\n\n/**\n * The state behind the event dialog: which event is open, and what saving, deleting and\n * moving do, each confirmed by a toast. Deleting and moving can be undone from the toast.\n */\nexport function useEventEditor({\n  events,\n  onEventAdd,\n  onEventUpdate,\n  onEventDelete,\n}: EventEditorOptions): EventEditor {\n  const [dialog, setDialog] = useState<EditorDialog>(IDLE_DIALOG);\n\n  function open(event: CalendarEvent | null) {\n    setDialog((current) => ({\n      isOpen: true,\n      event,\n      session: current.session + 1,\n    }));\n  }\n\n  function close() {\n    setDialog((current) => ({ ...current, isOpen: false }));\n  }\n\n  function openEvent(event: CalendarEvent) {\n    open(event);\n  }\n\n  function openNewEvent(startTime: Date) {\n    open(draftAt(startTime));\n  }\n\n  function save(event: CalendarEvent) {\n    if (event.id) {\n      onEventUpdate?.(event);\n      notify(`Saved \"${event.title}\"`, event);\n    } else {\n      onEventAdd?.({ ...event, id: newEventId() });\n      notify(`Added \"${event.title}\"`, event);\n    }\n    close();\n  }\n\n  function remove(eventId: string) {\n    const deletedEvent = events.find((event) => event.id === eventId);\n    onEventDelete?.(eventId);\n    close();\n    if (!deletedEvent) {\n      return;\n    }\n    let undo: (() => void) | undefined;\n    if (onEventAdd) {\n      undo = () => onEventAdd(deletedEvent);\n    }\n    notify(`Deleted \"${deletedEvent.title}\"`, deletedEvent, undo);\n  }\n\n  function moveEvent(movedEvent: CalendarEvent) {\n    const originalEvent = events.find((event) => event.id === movedEvent.id);\n    onEventUpdate?.(movedEvent);\n    let undo: (() => void) | undefined;\n    if (originalEvent && onEventUpdate) {\n      undo = () => onEventUpdate(originalEvent);\n    }\n    notify(`Moved \"${movedEvent.title}\"`, movedEvent, undo);\n  }\n\n  return {\n    dialogProps: {\n      event: dialog.event,\n      isOpen: dialog.isOpen,\n      session: dialog.session,\n      onClose: close,\n      onSave: save,\n      onDelete: remove,\n    },\n    openEvent,\n    openNewEvent,\n    moveEvent,\n  };\n}\n",
      "type": "registry:component",
      "target": "components/event-calendar/_parts/use-event-editor.ts"
    },
    {
      "path": "registry/ndeko/components/event-calendar/_parts/use-event-list.ts",
      "content": "'use client';\n\nimport { useState } from 'react';\n\nimport type { CalendarEvent } from './types';\n\n/** Events kept in local state, with the three handlers the calendar calls. */\nexport function useEventList(initialEvents: () => CalendarEvent[]) {\n  const [events, setEvents] = useState(initialEvents);\n\n  function addEvent(event: CalendarEvent) {\n    setEvents((current) => [...current, event]);\n  }\n\n  function updateEvent(updatedEvent: CalendarEvent) {\n    setEvents((current) =>\n      current.map((event) => {\n        if (event.id === updatedEvent.id) {\n          return updatedEvent;\n        }\n        return event;\n      })\n    );\n  }\n\n  function deleteEvent(eventId: string) {\n    setEvents((current) => current.filter((event) => event.id !== eventId));\n  }\n\n  return { events, addEvent, updateEvent, deleteEvent };\n}\n",
      "type": "registry:component",
      "target": "components/event-calendar/_parts/use-event-list.ts"
    },
    {
      "path": "registry/ndeko/components/event-calendar/_parts/use-event-visibility.ts",
      "content": "'use client';\n\nimport { useCallback, useLayoutEffect, useRef, useState } from 'react';\n\ntype EventVisibilityOptions = {\n  eventHeight: number;\n  eventGap: number;\n};\n\n/**\n * Measures one month cell so every cell shows as many events as fit, keeping a row for\n * the \"more\" button when some are left out.\n */\nexport function useEventVisibility({\n  eventHeight,\n  eventGap,\n}: EventVisibilityOptions) {\n  const contentRef = useRef<HTMLDivElement>(null);\n  const [contentHeight, setContentHeight] = useState<number | null>(null);\n\n  useLayoutEffect(() => {\n    const content = contentRef.current;\n    if (!content) {\n      return;\n    }\n    const observer = new ResizeObserver(() => {\n      setContentHeight(content.clientHeight);\n    });\n    observer.observe(content);\n    return () => observer.disconnect();\n  }, []);\n\n  const getVisibleEventCount = useCallback(\n    (totalEvents: number) => {\n      if (!contentHeight) {\n        return totalEvents;\n      }\n      const maxEvents = Math.floor(contentHeight / (eventHeight + eventGap));\n      if (totalEvents <= maxEvents) {\n        return totalEvents;\n      }\n      return Math.max(0, maxEvents - 1);\n    },\n    [contentHeight, eventHeight, eventGap]\n  );\n\n  return { contentRef, contentHeight, getVisibleEventCount };\n}\n",
      "type": "registry:component",
      "target": "components/event-calendar/_parts/use-event-visibility.ts"
    },
    {
      "path": "registry/ndeko/components/event-calendar/_parts/use-roving-day.ts",
      "content": "'use client';\n\nimport {\n  addDays,\n  addMonths,\n  endOfWeek,\n  isAfter,\n  isBefore,\n  isSameDay,\n  startOfDay,\n  startOfWeek,\n} from 'date-fns';\nimport { useLayoutEffect, useRef, useState } from 'react';\n\nimport { WeekStartsOn } from './constants';\nimport { dayKeyOf } from './navigation';\n\ntype RovingDayOptions = {\n  /** The day that holds the tab stop until one is picked. */\n  defaultDay: Date;\n  firstDay: Date;\n  lastDay: Date;\n};\n\nfunction movedDayOf(day: Date, key: string) {\n  if (key === 'ArrowLeft') {\n    return addDays(day, -1);\n  }\n  if (key === 'ArrowRight') {\n    return addDays(day, 1);\n  }\n  if (key === 'ArrowUp') {\n    return addDays(day, -7);\n  }\n  if (key === 'ArrowDown') {\n    return addDays(day, 7);\n  }\n  if (key === 'Home') {\n    return startOfWeek(day, { weekStartsOn: WeekStartsOn });\n  }\n  if (key === 'End') {\n    const weekEnd = endOfWeek(day, { weekStartsOn: WeekStartsOn });\n    return startOfDay(weekEnd);\n  }\n  if (key === 'PageUp') {\n    return addMonths(day, -1);\n  }\n  if (key === 'PageDown') {\n    return addMonths(day, 1);\n  }\n  return null;\n}\n\nfunction clampedDayOf(day: Date, firstDay: Date, lastDay: Date) {\n  if (isBefore(day, firstDay)) {\n    return firstDay;\n  }\n  if (isAfter(day, lastDay)) {\n    return lastDay;\n  }\n  return day;\n}\n\nfunction isWithinRange(day: Date, firstDay: Date, lastDay: Date) {\n  const isBeforeRange = isBefore(day, firstDay);\n  const isAfterRange = isAfter(day, lastDay);\n  return !isBeforeRange && !isAfterRange;\n}\n\nfunction activeDayOf(\n  storedDay: Date | null,\n  { defaultDay, firstDay, lastDay }: RovingDayOptions\n) {\n  if (!storedDay) {\n    return clampedDayOf(defaultDay, firstDay, lastDay);\n  }\n  if (!isWithinRange(storedDay, firstDay, lastDay)) {\n    return clampedDayOf(defaultDay, firstDay, lastDay);\n  }\n  return storedDay;\n}\n\nfunction isDayButton(target: EventTarget) {\n  if (!(target instanceof HTMLElement)) {\n    return false;\n  }\n  return target.dataset.day !== undefined;\n}\n\n/**\n * One tab stop for a grid of days: the arrow keys move by day and week, Home and End go to\n * the ends of the week, Page Up and Page Down move by month, and focus follows.\n */\nexport function useRovingDay(options: RovingDayOptions) {\n  const gridRef = useRef<HTMLDivElement>(null);\n  const shouldFocusRef = useRef(false);\n  const [storedDay, setStoredDay] = useState<Date | null>(null);\n  const activeDay = activeDayOf(storedDay, options);\n  const activeKey = dayKeyOf(activeDay);\n\n  useLayoutEffect(() => {\n    if (!shouldFocusRef.current) {\n      return;\n    }\n    shouldFocusRef.current = false;\n    const selector = `[data-day=\"${activeKey}\"]`;\n    const target = gridRef.current?.querySelector<HTMLElement>(selector);\n    target?.focus();\n  }, [activeKey]);\n\n  function handleKeyDown(keyEvent: React.KeyboardEvent) {\n    if (!isDayButton(keyEvent.target)) {\n      return;\n    }\n    const movedDay = movedDayOf(activeDay, keyEvent.key);\n    if (!movedDay) {\n      return;\n    }\n    keyEvent.preventDefault();\n    const nextDay = clampedDayOf(movedDay, options.firstDay, options.lastDay);\n    if (isSameDay(nextDay, activeDay)) {\n      return;\n    }\n    shouldFocusRef.current = true;\n    setStoredDay(nextDay);\n  }\n\n  function tabIndexOf(day: Date) {\n    if (isSameDay(day, activeDay)) {\n      return 0;\n    }\n    return -1;\n  }\n\n  return {\n    gridRef,\n    activeDay,\n    handleKeyDown,\n    tabIndexOf,\n    rememberDay: setStoredDay,\n  };\n}\n",
      "type": "registry:component",
      "target": "components/event-calendar/_parts/use-roving-day.ts"
    },
    {
      "path": "registry/ndeko/components/event-calendar/_parts/utils.ts",
      "content": "import {\n  addHours,\n  areIntervalsOverlapping,\n  differenceInMinutes,\n  eachDayOfInterval,\n  format,\n  getHours,\n  getMinutes,\n  isAfter,\n  isSameDay,\n  isToday,\n  startOfDay,\n} from 'date-fns';\n\nimport {\n  DefaultEventColor,\n  DefaultStartHour,\n  StartHour,\n  WeekCellsHeight,\n} from './constants';\nimport { dayKeyOf } from './navigation';\nimport type { CalendarEvent, EventColor } from './types';\n\nconst LAST_START_HOUR = 23;\n\n/** A clock time as `9am` or `9:30am`, short enough for a month cell. */\nexport function clockLabelOf(date: Date) {\n  let pattern = 'h:mma';\n  if (getMinutes(date) === 0) {\n    pattern = 'ha';\n  }\n  return format(date, pattern).toLowerCase();\n}\n\nexport function timeRangeLabelOf(start: Date, end: Date) {\n  const startLabel = clockLabelOf(start);\n  const endLabel = clockLabelOf(end);\n  return `${startLabel} – ${endLabel}`;\n}\n\n/** When the event runs on this day: its hours, its start, its end, or the whole day. */\nexport function timeLabelOnDay(event: CalendarEvent, day: Date) {\n  const start = new Date(event.start);\n  const end = new Date(event.end);\n  const startsThatDay = isSameDay(day, start);\n  const endsThatDay = isSameDay(day, end);\n  const isWithinDay = startsThatDay && endsThatDay;\n\n  if (event.allDay) {\n    return 'All day';\n  }\n  if (isWithinDay) {\n    return timeRangeLabelOf(start, end);\n  }\n  if (startsThatDay) {\n    return `From ${clockLabelOf(start)}`;\n  }\n  if (endsThatDay) {\n    return `Until ${clockLabelOf(end)}`;\n  }\n  return 'All day';\n}\n\nexport function ariaCurrentDateOf(isCurrentDay: boolean) {\n  if (isCurrentDay) {\n    return 'date' as const;\n  }\n  return undefined;\n}\n\nexport function eventCountLabelOf(count: number) {\n  if (count === 0) {\n    return 'No events';\n  }\n  if (count === 1) {\n    return '1 event';\n  }\n  return `${count} events`;\n}\n\n/** How many events touch each day, keyed by `yyyy-MM-dd`. */\nexport function eventDayCountsOf(events: CalendarEvent[]) {\n  const counts = new Map<string, number>();\n  for (const event of events) {\n    const firstDay = startOfDay(new Date(event.start));\n    const lastDay = startOfDay(new Date(event.end));\n    if (isAfter(firstDay, lastDay)) {\n      continue;\n    }\n    const days = eachDayOfInterval({ start: firstDay, end: lastDay });\n    for (const day of days) {\n      const key = dayKeyOf(day);\n      const current = counts.get(key) ?? 0;\n      counts.set(key, current + 1);\n    }\n  }\n  return counts;\n}\n\nfunction nextFullHourOf(time: Date) {\n  const nextHour = getHours(time) + 1;\n  return Math.min(nextHour, LAST_START_HOUR);\n}\n\n/** Where a new event starts on a day: the next full hour today, the morning on any other day. */\nexport function defaultStartOf(day: Date) {\n  const start = startOfDay(day);\n  let hour = DefaultStartHour;\n  if (isToday(day)) {\n    hour = nextFullHourOf(new Date());\n  }\n  start.setHours(hour);\n  return start;\n}\n\nexport function snapToQuarterHour(time: Date) {\n  const snapped = new Date(time);\n  const minutes = snapped.getMinutes();\n  const remainder = minutes % 15;\n  if (remainder === 0) {\n    return snapped;\n  }\n  const isCloserToPrevious = remainder < 7.5;\n  if (isCloserToPrevious) {\n    snapped.setMinutes(minutes - remainder, 0, 0);\n    return snapped;\n  }\n  snapped.setMinutes(minutes + 15 - remainder, 0, 0);\n  return snapped;\n}\n\nexport type PositionedEvent = {\n  event: CalendarEvent;\n  top: number;\n  height: number;\n  left: number;\n  width: number;\n  zIndex: number;\n};\n\n/** The `--chip` colour of an event block, always a theme token. */\nexport function eventChipStyle(color?: EventColor) {\n  const token = color ?? DefaultEventColor;\n  return { '--chip': `var(--${token})` } as React.CSSProperties;\n}\n\nexport function getBorderRadiusClasses(\n  isFirstDay: boolean,\n  isLastDay: boolean\n) {\n  const isSingleDay = isFirstDay && isLastDay;\n  if (isSingleDay) {\n    return 'rounded-sm';\n  }\n  if (isFirstDay) {\n    return 'rounded-s-sm rounded-e-none';\n  }\n  if (isLastDay) {\n    return 'rounded-e-sm rounded-s-none';\n  }\n  return 'rounded-none';\n}\n\nexport function isMultiDayEvent(event: CalendarEvent) {\n  const eventStart = new Date(event.start);\n  const eventEnd = new Date(event.end);\n  const isSpanningDays = !isSameDay(eventStart, eventEnd);\n  return Boolean(event.allDay) || isSpanningDays;\n}\n\n/** Whether the event starts, ends or runs through this day. */\nexport function occursOnDay(event: CalendarEvent, day: Date) {\n  const eventStart = new Date(event.start);\n  const eventEnd = new Date(event.end);\n  const startsThatDay = isSameDay(day, eventStart);\n  const endsThatDay = isSameDay(day, eventEnd);\n  const runsThroughDay = day > eventStart && day < eventEnd;\n  return startsThatDay || endsThatDay || runsThroughDay;\n}\n\nfunction byStart(a: CalendarEvent, b: CalendarEvent) {\n  return new Date(a.start).getTime() - new Date(b.start).getTime();\n}\n\nexport function getEventsForDay(events: CalendarEvent[], day: Date) {\n  const startingThatDay = events.filter((event) =>\n    isSameDay(day, new Date(event.start))\n  );\n  return startingThatDay.sort(byStart);\n}\n\n/** Multi-day events first, then by start time. */\nexport function sortEvents(events: CalendarEvent[]) {\n  return [...events].sort((a, b) => {\n    const aIsMultiDay = isMultiDayEvent(a);\n    const bIsMultiDay = isMultiDayEvent(b);\n    if (aIsMultiDay === bIsMultiDay) {\n      return byStart(a, b);\n    }\n    if (aIsMultiDay) {\n      return -1;\n    }\n    return 1;\n  });\n}\n\n/** Multi-day events that cover this day without starting on it. */\nexport function getSpanningEventsForDay(events: CalendarEvent[], day: Date) {\n  return events.filter((event) => {\n    if (!isMultiDayEvent(event)) {\n      return false;\n    }\n    const startsThatDay = isSameDay(day, new Date(event.start));\n    if (startsThatDay) {\n      return false;\n    }\n    return occursOnDay(event, day);\n  });\n}\n\nexport function getAllEventsForDay(events: CalendarEvent[], day: Date) {\n  return events.filter((event) => occursOnDay(event, day));\n}\n\nexport function getAgendaEventsForDay(events: CalendarEvent[], day: Date) {\n  return getAllEventsForDay(events, day).sort(byStart);\n}\n\nfunction byStartThenLongest(a: CalendarEvent, b: CalendarEvent) {\n  const startDifference = byStart(a, b);\n  if (startDifference !== 0) {\n    return startDifference;\n  }\n  const aDuration = differenceInMinutes(new Date(a.end), new Date(a.start));\n  const bDuration = differenceInMinutes(new Date(b.end), new Date(b.start));\n  return bDuration - aDuration;\n}\n\nfunction hourOf(date: Date) {\n  return getHours(date) + getMinutes(date) / 60;\n}\n\ntype PlacedInterval = { start: Date; end: Date };\n\nfunction firstFreeColumn(\n  columns: PlacedInterval[][],\n  interval: PlacedInterval\n) {\n  let columnIndex = 0;\n  while (columnIndex < columns.length) {\n    const column = columns[columnIndex];\n    const overlaps = column.some((placed) =>\n      areIntervalsOverlapping(interval, placed)\n    );\n    if (!overlaps) {\n      return columnIndex;\n    }\n    columnIndex++;\n  }\n  return columnIndex;\n}\n\nfunction widthOfColumn(columnIndex: number) {\n  if (columnIndex === 0) {\n    return 1;\n  }\n  return 0.9;\n}\n\n/**\n * Places the timed events of one day on the hour grid. Overlapping events move to the next\n * column, indented by 10% and drawn above the previous one.\n */\nexport function positionTimedEvents(events: CalendarEvent[], day: Date) {\n  const dayStart = startOfDay(day);\n  const dayEnd = addHours(dayStart, 24);\n  const columns: PlacedInterval[][] = [];\n  const sortedEvents = [...events].sort(byStartThenLongest);\n\n  return sortedEvents.map((event): PositionedEvent => {\n    const eventStart = new Date(event.start);\n    const eventEnd = new Date(event.end);\n    let visibleStart = dayStart;\n    if (isSameDay(day, eventStart)) {\n      visibleStart = eventStart;\n    }\n    let visibleEnd = dayEnd;\n    if (isSameDay(day, eventEnd)) {\n      visibleEnd = eventEnd;\n    }\n    const startHour = hourOf(visibleStart);\n    const endHour = hourOf(visibleEnd);\n    const columnIndex = firstFreeColumn(columns, {\n      start: visibleStart,\n      end: visibleEnd,\n    });\n    if (!columns[columnIndex]) {\n      columns[columnIndex] = [];\n    }\n    columns[columnIndex].push({ start: eventStart, end: eventEnd });\n\n    return {\n      event,\n      top: (startHour - StartHour) * WeekCellsHeight,\n      height: (endHour - startHour) * WeekCellsHeight,\n      left: columnIndex * 0.1,\n      width: widthOfColumn(columnIndex),\n      zIndex: 10 + columnIndex,\n    };\n  });\n}\n",
      "type": "registry:component",
      "target": "components/event-calendar/_parts/utils.ts"
    },
    {
      "path": "registry/ndeko/components/event-calendar/_parts/view-switcher.tsx",
      "content": "'use client';\n\nimport { cn } from '@/registry/ndeko/lib/utils';\nimport { Tabs, TabsList, TabsTab } from '@/registry/ndeko/ui/tabs';\n\nimport { ViewOptions } from './constants';\nimport type { CalendarView } from './types';\n\ntype ViewSwitcherProps = {\n  views: CalendarView[];\n  value: CalendarView;\n  onValueChange: (view: CalendarView) => void;\n  className?: string;\n};\n\nfunction isCalendarView(value: unknown): value is CalendarView {\n  return ViewOptions.some((option) => option.view === value);\n}\n\n/**\n * A segmented control whose thumb travels to the chosen view. It takes a row of its own on\n * a narrow calendar and sits in the header row on a wide one.\n */\nexport function ViewSwitcher({\n  views,\n  value,\n  onValueChange,\n  className,\n}: ViewSwitcherProps) {\n  const options = ViewOptions.filter((option) => views.includes(option.view));\n\n  function changeView(nextView: unknown) {\n    if (isCalendarView(nextView)) {\n      onValueChange(nextView);\n    }\n  }\n\n  return (\n    <Tabs\n      value={value}\n      onValueChange={changeView}\n      className={cn('order-last w-full @2xl:order-none @2xl:w-auto', className)}\n    >\n      <TabsList\n        variant='segmented'\n        aria-label='Calendar view'\n        className='w-full @2xl:w-fit'\n      >\n        {options.map((option) => (\n          <TabsTab\n            key={option.view}\n            value={option.view}\n            aria-keyshortcuts={option.shortcut}\n            className='flex-1 px-2 @2xl:flex-none @2xl:px-3'\n          >\n            {option.label}\n          </TabsTab>\n        ))}\n      </TabsList>\n    </Tabs>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/event-calendar/_parts/view-switcher.tsx"
    },
    {
      "path": "registry/ndeko/components/event-calendar/_parts/week-view.tsx",
      "content": "'use client';\n\nimport {\n  eachDayOfInterval,\n  endOfWeek,\n  format,\n  isBefore,\n  isSameDay,\n  isToday,\n  startOfWeek,\n} from 'date-fns';\nimport { useMemo } from 'react';\n\nimport { cn } from '@/registry/ndeko/lib/utils';\n\nimport { WeekStartsOn } from './constants';\nimport { EventItem } from './event-item';\nimport {\n  CurrentTimeLine,\n  HourLabels,\n  hoursOfDay,\n  PositionedEvents,\n  QuarterSlots,\n  TimeGridScroller,\n} from './time-grid';\nimport type { CalendarEvent } from './types';\nimport { useCurrentTimeIndicator } from './use-current-time-indicator';\nimport {\n  ariaCurrentDateOf,\n  isMultiDayEvent,\n  occursOnDay,\n  positionTimedEvents,\n} from './utils';\n\n/** An hour gutter, then seven days that keep a readable width by scrolling sideways on a phone. */\nconst WEEK_COLUMNS = 'grid grid-cols-[3.5rem_repeat(7,minmax(0,1fr))]';\n\nconst STICKY_GUTTER = 'bg-card sticky left-0 z-20';\n\nconst DAY_NUMBER =\n  'inline-flex size-6 items-center justify-center rounded-full text-[13px] tabular-nums group-data-today/day:bg-primary group-data-today/day:font-medium group-data-today/day:text-primary-foreground';\n\ntype WeekViewProps = {\n  currentDate: Date;\n  events: CalendarEvent[];\n  onEventSelect: (event: CalendarEvent) => void;\n  onEventCreate: (startTime: Date) => void;\n  /** Opens a day from its heading. Without it the headings are plain text. */\n  onDaySelect?: (day: Date) => void;\n};\n\nfunction isTimedEvent(event: CalendarEvent) {\n  return !isMultiDayEvent(event);\n}\n\nfunction DayHeadingContent({ day }: { day: Date }) {\n  return (\n    <>\n      <span className='text-muted-foreground text-xs'>\n        {format(day, 'EEE')}\n      </span>\n      <span className={DAY_NUMBER}>{format(day, 'd')}</span>\n    </>\n  );\n}\n\ntype DayHeadingProps = {\n  day: Date;\n  onDaySelect?: (day: Date) => void;\n};\n\nfunction DayHeading({ day, onDaySelect }: DayHeadingProps) {\n  const isTodayColumn = isToday(day);\n\n  if (!onDaySelect) {\n    return (\n      <div\n        className='group/day flex items-center justify-center gap-1.5 py-2'\n        data-today={isTodayColumn || undefined}\n      >\n        <DayHeadingContent day={day} />\n      </div>\n    );\n  }\n\n  return (\n    <div className='flex justify-center py-1.5'>\n      <button\n        type='button'\n        className='group/day hover:bg-foreground/5 focus-visible:ring-ring/25 flex cursor-pointer items-center gap-1.5 rounded-md px-1.5 py-0.5 transition-colors duration-150 outline-none focus-visible:ring-[3px]'\n        data-today={isTodayColumn || undefined}\n        aria-label={format(day, 'EEEE, MMMM d')}\n        aria-current={ariaCurrentDateOf(isTodayColumn)}\n        onClick={() => onDaySelect(day)}\n      >\n        <DayHeadingContent day={day} />\n      </button>\n    </div>\n  );\n}\n\ntype AllDayCellProps = {\n  day: Date;\n  isFirstColumn: boolean;\n  weekStart: Date;\n  events: CalendarEvent[];\n  onEventClick: (event: CalendarEvent, clickEvent: React.MouseEvent) => void;\n};\n\nfunction AllDayCell({\n  day,\n  isFirstColumn,\n  weekStart,\n  events,\n  onEventClick,\n}: AllDayCellProps) {\n  const dayEvents = events.filter((event) => occursOnDay(event, day));\n\n  return (\n    <div className='hairline-r border-border relative p-1 last:border-r-0'>\n      {dayEvents.map((event) => {\n        const eventStart = new Date(event.start);\n        const isFirstDay = isSameDay(day, eventStart);\n        const isLastDay = isSameDay(day, new Date(event.end));\n        const startsBeforeWeek = isBefore(eventStart, weekStart);\n        const isFirstVisibleDay = isFirstColumn && startsBeforeWeek;\n        const shouldShowTitle = isFirstDay || isFirstVisibleDay;\n        let tabIndex: number | undefined;\n        if (!shouldShowTitle) {\n          tabIndex = -1;\n        }\n\n        return (\n          <EventItem\n            key={`spanning-${event.id}`}\n            onClick={(clickEvent) => onEventClick(event, clickEvent)}\n            event={event}\n            view='month'\n            tabIndex={tabIndex}\n            isFirstDay={isFirstDay}\n            isLastDay={isLastDay}\n          >\n            <span\n              className={cn('truncate', !shouldShowTitle && 'invisible')}\n              aria-hidden='true'\n            >\n              {event.title}\n            </span>\n          </EventItem>\n        );\n      })}\n    </div>\n  );\n}\n\nexport function WeekView({\n  currentDate,\n  events,\n  onEventSelect,\n  onEventCreate,\n  onDaySelect,\n}: WeekViewProps) {\n  const weekStart = useMemo(\n    () => startOfWeek(currentDate, { weekStartsOn: WeekStartsOn }),\n    [currentDate]\n  );\n  const days = useMemo(() => {\n    const weekEnd = endOfWeek(currentDate, { weekStartsOn: WeekStartsOn });\n    return eachDayOfInterval({ start: weekStart, end: weekEnd });\n  }, [currentDate, weekStart]);\n  const hours = useMemo(() => hoursOfDay(currentDate), [currentDate]);\n\n  const allDayEvents = useMemo(() => {\n    const multiDayEvents = events.filter(isMultiDayEvent);\n    return multiDayEvents.filter((event) =>\n      days.some((day) => occursOnDay(event, day))\n    );\n  }, [events, days]);\n\n  const positionedDayEvents = useMemo(() => {\n    const timedEvents = events.filter(isTimedEvent);\n    return days.map((day) => {\n      const dayEvents = timedEvents.filter((event) => occursOnDay(event, day));\n      return positionTimedEvents(dayEvents, day);\n    });\n  }, [days, events]);\n\n  const { currentTimePosition, currentTimeVisible } = useCurrentTimeIndicator(\n    currentDate,\n    'week'\n  );\n  const showAllDaySection = allDayEvents.length > 0;\n  const gridLabel = `Week of ${format(weekStart, 'MMMM d')}`;\n\n  function handleEventClick(\n    event: CalendarEvent,\n    clickEvent: React.MouseEvent\n  ) {\n    clickEvent.stopPropagation();\n    onEventSelect(event);\n  }\n\n  return (\n    <div data-slot='week-view' className='flex min-h-0 flex-1 flex-col'>\n      <TimeGridScroller label={gridLabel}>\n        <div className='min-w-[42rem] @3xl:min-w-0'>\n          <div className='bg-card hairline-b border-border sticky top-0 z-30'>\n            <div className={WEEK_COLUMNS}>\n              <div className={STICKY_GUTTER} />\n              {days.map((day) => (\n                <DayHeading\n                  key={day.toString()}\n                  day={day}\n                  onDaySelect={onDaySelect}\n                />\n              ))}\n            </div>\n            {showAllDaySection && (\n              <div className={cn(WEEK_COLUMNS, 'hairline-t border-border')}>\n                <div\n                  className={cn(\n                    STICKY_GUTTER,\n                    'hairline-r border-border text-muted-foreground flex items-end justify-end pe-2 pb-2 text-[10px] @3xl:text-xs'\n                  )}\n                >\n                  All day\n                </div>\n                {days.map((day, dayIndex) => (\n                  <AllDayCell\n                    key={day.toString()}\n                    day={day}\n                    isFirstColumn={dayIndex === 0}\n                    weekStart={weekStart}\n                    events={allDayEvents}\n                    onEventClick={handleEventClick}\n                  />\n                ))}\n              </div>\n            )}\n          </div>\n\n          <div className={WEEK_COLUMNS}>\n            <div className={cn(STICKY_GUTTER, 'hairline-r border-border')}>\n              <HourLabels hours={hours} />\n            </div>\n\n            {days.map((day, dayIndex) => {\n              const isTodayColumn = isToday(day);\n              const showsCurrentTime = currentTimeVisible && isTodayColumn;\n\n              return (\n                <div\n                  key={day.toString()}\n                  className='hairline-r border-border data-today:bg-primary/[0.025] relative last:border-r-0'\n                  data-today={isTodayColumn || undefined}\n                >\n                  <PositionedEvents\n                    positionedEvents={positionedDayEvents[dayIndex] ?? []}\n                    view='week'\n                    onEventClick={handleEventClick}\n                  />\n                  {showsCurrentTime && (\n                    <CurrentTimeLine position={currentTimePosition} />\n                  )}\n                  <QuarterSlots\n                    day={day}\n                    hours={hours}\n                    idPrefix='week-cell'\n                    onEventCreate={onEventCreate}\n                  />\n                </div>\n              );\n            })}\n          </div>\n        </div>\n      </TimeGridScroller>\n    </div>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/event-calendar/_parts/week-view.tsx"
    },
    {
      "path": "registry/ndeko/components/event-calendar/_parts/year-view.tsx",
      "content": "'use client';\n\nimport {\n  addDays,\n  eachDayOfInterval,\n  eachMonthOfInterval,\n  endOfMonth,\n  endOfYear,\n  format,\n  getDay,\n  isSameDay,\n  isToday,\n  startOfDay,\n  startOfYear,\n} from 'date-fns';\nimport { useMemo } from 'react';\n\nimport { cn } from '@/registry/ndeko/lib/utils';\n\nimport { WeekStartsOn } from './constants';\nimport { dayKeyOf } from './navigation';\nimport type { CalendarEvent } from './types';\nimport { useRovingDay } from './use-roving-day';\nimport {\n  ariaCurrentDateOf,\n  eventCountLabelOf,\n  eventDayCountsOf,\n} from './utils';\n\nconst REFERENCE_SUNDAY = new Date(2023, 0, 1);\n\nconst WEEKDAY_INITIALS = Array.from({ length: 7 }, (_, index) => {\n  const weekday = addDays(REFERENCE_SUNDAY, index + WeekStartsOn);\n  return { key: format(weekday, 'EEE'), initial: format(weekday, 'EEEEE') };\n});\n\nconst YEAR_DAY = [\n  'mx-auto flex aspect-square w-full max-w-8 cursor-pointer items-center justify-center rounded-full text-[11px] tabular-nums text-foreground outline-none @4xl:text-xs',\n  'transition-[background-color,scale,box-shadow] duration-150 ease-(--ease-out-strong) active:scale-90',\n  'not-data-today:hover:bg-foreground/[0.07] focus-visible:ring-[3px] focus-visible:ring-ring/25',\n  'data-today:bg-primary data-today:font-medium data-today:text-primary-foreground',\n  'data-selected:ring-[1.5px] data-selected:ring-primary-ink',\n].join(' ');\n\n/** Busier days take a deeper tint of the brand: one event, two, three or more. */\nconst DENSITY_CLASSES = [\n  '',\n  'bg-primary/[0.09]',\n  'bg-primary/[0.18]',\n  'bg-primary/[0.3]',\n];\n\nconst LEGEND = [\n  { label: '1 event', className: DENSITY_CLASSES[1] },\n  { label: '2 events', className: DENSITY_CLASSES[2] },\n  { label: '3 or more', className: DENSITY_CLASSES[3] },\n  { label: 'Today', className: 'bg-primary' },\n];\n\nfunction densityClassOf(count: number) {\n  const level = Math.min(count, DENSITY_CLASSES.length - 1);\n  return DENSITY_CLASSES[level];\n}\n\nfunction dayLabelOf(day: Date, count: number) {\n  const date = format(day, 'EEEE, MMMM d');\n  if (count === 0) {\n    return date;\n  }\n  return `${date}, ${eventCountLabelOf(count)}`;\n}\n\nfunction leadingBlanksOf(month: Date) {\n  const weekday = getDay(month);\n  return (weekday - WeekStartsOn + 7) % 7;\n}\n\nfunction isSelectedDay(day: Date, selectedDay: Date | null | undefined) {\n  if (!selectedDay) {\n    return false;\n  }\n  return isSameDay(day, selectedDay);\n}\n\nfunction ariaPressedOf(isSelectable: boolean, isSelected: boolean) {\n  if (!isSelectable) {\n    return undefined;\n  }\n  return isSelected;\n}\n\nfunction tabIndexOf(day: Date, activeDay: Date) {\n  if (isSameDay(day, activeDay)) {\n    return 0;\n  }\n  return -1;\n}\n\ntype YearDayProps = {\n  day: Date;\n  count: number;\n  activeDay: Date;\n  selectedDay?: Date | null;\n  onDaySelect: (day: Date) => void;\n  onFocusDay: (day: Date) => void;\n};\n\nfunction YearDay({\n  day,\n  count,\n  activeDay,\n  selectedDay,\n  onDaySelect,\n  onFocusDay,\n}: YearDayProps) {\n  const isTodayDay = isToday(day);\n  const isSelectable = selectedDay !== undefined;\n  const isSelected = isSelectedDay(day, selectedDay);\n\n  function selectDay() {\n    onFocusDay(day);\n    onDaySelect(day);\n  }\n\n  return (\n    <button\n      type='button'\n      className={cn(YEAR_DAY, densityClassOf(count))}\n      data-day={dayKeyOf(day)}\n      data-today={isTodayDay || undefined}\n      data-selected={isSelected || undefined}\n      tabIndex={tabIndexOf(day, activeDay)}\n      aria-label={dayLabelOf(day, count)}\n      aria-current={ariaCurrentDateOf(isTodayDay)}\n      aria-pressed={ariaPressedOf(isSelectable, isSelected)}\n      onClick={selectDay}\n      onFocus={() => onFocusDay(day)}\n    >\n      {format(day, 'd')}\n    </button>\n  );\n}\n\ntype MonthHeadingProps = {\n  month: Date;\n  onMonthSelect?: (month: Date) => void;\n};\n\nfunction MonthHeading({ month, onMonthSelect }: MonthHeadingProps) {\n  const name = format(month, 'MMMM');\n\n  if (!onMonthSelect) {\n    return <h3 className='px-1 text-[13px] font-medium'>{name}</h3>;\n  }\n\n  return (\n    <h3 className='flex'>\n      <button\n        type='button'\n        className='hover:bg-foreground/5 focus-visible:ring-ring/25 cursor-pointer rounded-md px-1 text-[13px] font-medium transition-colors duration-150 outline-none focus-visible:ring-[3px]'\n        aria-label={`Open ${format(month, 'MMMM yyyy')}`}\n        onClick={() => onMonthSelect(month)}\n      >\n        {name}\n      </button>\n    </h3>\n  );\n}\n\ntype YearMonthProps = {\n  month: Date;\n  counts: Map<string, number>;\n  activeDay: Date;\n  selectedDay?: Date | null;\n  onDaySelect: (day: Date) => void;\n  onFocusDay: (day: Date) => void;\n  onMonthSelect?: (month: Date) => void;\n};\n\nfunction YearMonth({\n  month,\n  counts,\n  activeDay,\n  selectedDay,\n  onDaySelect,\n  onFocusDay,\n  onMonthSelect,\n}: YearMonthProps) {\n  const days = eachDayOfInterval({ start: month, end: endOfMonth(month) });\n  const blanks = Array.from(\n    { length: leadingBlanksOf(month) },\n    (_, index) => index\n  );\n\n  return (\n    <section\n      aria-label={format(month, 'MMMM yyyy')}\n      className='flex min-w-0 flex-col gap-1.5'\n    >\n      <MonthHeading month={month} onMonthSelect={onMonthSelect} />\n      <div className='grid grid-cols-7' aria-hidden='true'>\n        {WEEKDAY_INITIALS.map((weekday) => (\n          <span\n            key={weekday.key}\n            className='text-muted-foreground text-center text-[10px] @4xl:text-[11px]'\n          >\n            {weekday.initial}\n          </span>\n        ))}\n      </div>\n      <div className='grid grid-cols-7 gap-y-0.5'>\n        {blanks.map((blank) => (\n          <span key={`blank-${blank}`} aria-hidden='true' />\n        ))}\n        {days.map((day) => {\n          const dayKey = dayKeyOf(day);\n          const count = counts.get(dayKey) ?? 0;\n          return (\n            <YearDay\n              key={dayKey}\n              day={day}\n              count={count}\n              activeDay={activeDay}\n              selectedDay={selectedDay}\n              onDaySelect={onDaySelect}\n              onFocusDay={onFocusDay}\n            />\n          );\n        })}\n      </div>\n    </section>\n  );\n}\n\nfunction YearLegend() {\n  return (\n    <div\n      aria-hidden='true'\n      className='text-muted-foreground flex flex-wrap items-center justify-end gap-x-4 gap-y-1 px-4 pb-4 text-xs @xl/year:px-5'\n    >\n      {LEGEND.map((entry) => (\n        <span key={entry.label} className='flex items-center gap-1.5'>\n          <span className={cn('size-3 rounded-full', entry.className)} />\n          {entry.label}\n        </span>\n      ))}\n    </div>\n  );\n}\n\ntype YearViewProps = {\n  currentDate: Date;\n  events: CalendarEvent[];\n  /** Picks a day: the all-in-one calendar opens it in the day view. */\n  onDaySelect: (day: Date) => void;\n  /** Opens a month from its name. Without it the names are plain headings. */\n  onMonthSelect?: (month: Date) => void;\n  /** The picked day, ringed. Leave it out when picking a day leaves the year view. */\n  selectedDay?: Date | null;\n};\n\n/** Twelve compact months. Days with events are tinted by how busy they are; today is filled. */\nexport function YearView({\n  currentDate,\n  events,\n  onDaySelect,\n  onMonthSelect,\n  selectedDay,\n}: YearViewProps) {\n  const yearStart = startOfYear(currentDate);\n  const yearEnd = startOfDay(endOfYear(currentDate));\n  const months = eachMonthOfInterval({ start: yearStart, end: yearEnd });\n  const counts = useMemo(() => eventDayCountsOf(events), [events]);\n  const { gridRef, activeDay, handleKeyDown, rememberDay } = useRovingDay({\n    defaultDay: currentDate,\n    firstDay: yearStart,\n    lastDay: yearEnd,\n  });\n\n  return (\n    <div\n      data-slot='year-view'\n      className='@container/year min-h-0 flex-1 overflow-y-auto'\n    >\n      <div\n        ref={gridRef}\n        onKeyDown={handleKeyDown}\n        className='grid grid-cols-2 gap-x-5 gap-y-5 p-4 @xl/year:grid-cols-3 @xl/year:gap-x-8 @xl/year:p-5 @4xl/year:grid-cols-4'\n      >\n        {months.map((month) => (\n          <YearMonth\n            key={format(month, 'yyyy-MM')}\n            month={month}\n            counts={counts}\n            activeDay={activeDay}\n            selectedDay={selectedDay}\n            onDaySelect={onDaySelect}\n            onFocusDay={rememberDay}\n            onMonthSelect={onMonthSelect}\n          />\n        ))}\n      </div>\n      <YearLegend />\n    </div>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/event-calendar/_parts/year-view.tsx"
    }
  ],
  "categories": [
    "components",
    "event-calendar"
  ],
  "type": "registry:component"
}