{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "app-scheduling-calendar",
  "type": "registry:block",
  "title": "App, month calendar",
  "description": "A month as a table with its events, today marked in words, previous, next and today buttons, and an agenda list in narrow containers instead of a cramped grid. Filled, empty, loading and error states. Dates are ISO text; the block never reads the clock.",
  "categories": [
    "app"
  ],
  "dependencies": [
    "lucide-react@^1.49.0",
    "zod@^4.6.5"
  ],
  "registryDependencies": [
    "https://ui.klarhimmel.com/r/block-kit.json",
    "https://ui.klarhimmel.com/r/button.json",
    "https://ui.klarhimmel.com/r/editing.json",
    "https://ui.klarhimmel.com/r/icon-button.json",
    "https://ui.klarhimmel.com/r/kit-app.json",
    "https://ui.klarhimmel.com/r/kit-scheduling.json",
    "https://ui.klarhimmel.com/r/utils.json"
  ],
  "files": [
    {
      "path": "src/blocks/app-scheduling-calendar/spec.ts",
      "type": "registry:file",
      "target": "components/klarhimmel/blocks/app-scheduling-calendar/spec.ts",
      "content": "import { z } from 'zod';\nimport { defineSpec, req, t } from '../_shared/schema';\n\nconst schema = z.object({\n  eyebrow: t(60).optional(),\n  title: t(120),\n  description: t(300).optional(),\n  /** The month the calendar opens on, \"YYYY-MM\". Not editable copy. */\n  month: t(7),\n  /** Today, \"YYYY-MM-DD\": a prop, because a block never reads the clock. It is marked in words, not only by colour. */\n  today: t(10),\n  /** The language month and day names are written in (\"en\", \"sv\"). */\n  locale: t(10),\n  firstDay: z.enum(['mon', 'sun']),\n  /** Seven short names starting from the first day of the week. */\n  weekdays: z.array(t(12)).length(7),\n  events: z.array(z.object({ date: t(10), time: t(12).optional(), title: t(60) })).max(40),\n  previous: req(30),\n  next: req(30),\n  todayLabel: req(20),\n  /** The word before an event's time in the agenda and in a cell's name (\"at 14:00\"). */\n  at: t(10),\n  /** filled shows the events; empty says nothing is planned; loading and error say so in words and leave the days in place. */\n  state: z.enum(['filled', 'empty', 'loading', 'error']),\n  /** `invalid` heads the list of dates the block could not read (\"2026-13\", \"2026-11-32\"): they are named, never dropped silently. */\n  messages: z.object({ empty: t(120), loading: t(60), error: t(120), retry: t(30), invalid: t(120) }),\n});\n\nexport const spec = defineSpec({\n  type: 'app-scheduling-calendar',\n  aliases: ['app/scheduling-calendar'],\n  name: 'App, month calendar',\n  category: 'app',\n  role: 'body',\n  description: 'A month as a table with its events, today marked in words, previous, next and today buttons, and an agenda list in narrow containers instead of a cramped grid. Filled, empty, loading and error states. Dates are ISO text; the block never reads the clock.',\n  schema,\n  defaults: {\n    \"eyebrow\": \"Name the calendar's owner\",\n    \"title\": \"Name what the calendar shows\",\n    \"description\": \"Say which kinds of events fill this calendar.\",\n    \"month\": \"2026-11\",\n    \"today\": \"2026-11-16\",\n    \"locale\": \"en\",\n    \"firstDay\": \"mon\",\n    \"weekdays\": [\n      \"Mon\",\n      \"Tue\",\n      \"Wed\",\n      \"Thu\",\n      \"Fri\",\n      \"Sat\",\n      \"Sun\"\n    ],\n    \"events\": [\n      {\n        \"date\": \"2026-11-04\",\n        \"time\": \"10:00\",\n        \"title\": \"Name the first event\"\n      },\n      {\n        \"date\": \"2026-11-13\",\n        \"time\": \"14:00\",\n        \"title\": \"Name the second event\"\n      },\n      {\n        \"date\": \"2026-11-14\",\n        \"time\": \"16:00\",\n        \"title\": \"Name the third event\"\n      },\n      {\n        \"date\": \"2026-11-14\",\n        \"time\": \"09:00\",\n        \"title\": \"Name the fourth event\"\n      },\n      {\n        \"date\": \"2026-11-14\",\n        \"time\": \"12:00\",\n        \"title\": \"Name the fifth event\"\n      },\n      {\n        \"date\": \"2026-11-14\",\n        \"time\": \"19:00\",\n        \"title\": \"Name the sixth event\"\n      },\n      {\n        \"date\": \"2026-11-18\",\n        \"time\": \"09:30\",\n        \"title\": \"Name an event\"\n      },\n      {\n        \"date\": \"2026-11-25\",\n        \"time\": \"13:00\",\n        \"title\": \"Name a longer event\"\n      },\n      {\n        \"date\": \"2026-11-26\",\n        \"title\": \"Name a longer event\"\n      }\n    ],\n    \"previous\": \"Previous month\",\n    \"next\": \"Next month\",\n    \"todayLabel\": \"Today\",\n    \"at\": \"at\",\n    \"state\": \"filled\",\n    \"messages\": {\n      \"empty\": \"Say nothing is planned yet.\",\n      \"loading\": \"Loading events…\",\n      \"error\": \"Say the events did not load.\",\n      \"retry\": \"Try again\",\n      \"invalid\": \"Say which dates could not be read and are hidden:\"\n    }\n  },\n});\n"
    },
    {
      "path": "src/blocks/app-scheduling-calendar/index.tsx",
      "type": "registry:file",
      "target": "components/klarhimmel/blocks/app-scheduling-calendar/index.tsx",
      "content": "import { useEffect, useId, useMemo, useRef } from 'react';\nimport { ChevronLeft, ChevronRight } from 'lucide-react';\nimport { Text, withHeadingLevel } from '../../editing';\nimport { cn } from '../../lib/utils';\nimport { Button } from '../../ui/button';\nimport { IconButton } from '../../ui/icon-button';\nimport { Container, Section, SectionHeader, useEditing } from '../_shared/kit';\nimport { AppPanel, StateSlot, useSynced } from '../_shared/app-kit';\nimport { byWhen, dayName, monthGrid, monthName, shiftMonth } from '../_shared/scheduling-kit';\n\nconst MONTH = /^\\d{4}-(0[1-9]|1[0-2])$/;\nconst realDay = (s: string) => {\n  const m = /^(\\d{4})-(\\d{2})-(\\d{2})$/.exec(s);\n  if (!m) return false;\n  const d = new Date(Date.UTC(Number(m[1]), Number(m[2]) - 1, Number(m[3])));\n  return d.getUTCFullYear() === Number(m[1]) && d.getUTCMonth() === Number(m[2]) - 1 && d.getUTCDate() === Number(m[3]);\n};\nimport { spec } from './spec';\nimport type { BlockProps } from '../types';\nimport type { z } from 'zod';\n\nexport { spec };\ntype Props = z.infer<typeof spec.schema>;\n\n/** A month as a table, or as an agenda in a narrow container. Today is marked in words. The month buttons work in place. */\nfunction AppSchedulingCalendar({ props }: BlockProps<Props>) {\n  const id = useId();\n  const editing = useEditing();\n  // Dates are text; anything that is not a real date is named in a message instead of being dropped without a word.\n  const goodMonth = MONTH.test(props.month) ? props.month : realDay(props.today) ? props.today.slice(0, 7) : '2000-01';\n  const bad = [\n    ...(MONTH.test(props.month) ? [] : [props.month]),\n    ...(realDay(props.today) ? [] : [props.today]),\n    ...props.events.filter((e) => !realDay(e.date)).map((e) => e.date),\n  ];\n  const [month, setMonth] = useSynced(goodMonth);\n  const [retried, setRetried] = useSynced(false, props.state); // Retry was pressed: the block says it is loading until its state prop changes\n  const todayBtn = useRef<HTMLButtonElement>(null);\n  const loadingMsg = useRef<HTMLParagraphElement>(null);\n  const justRetried = useRef(false);\n  useEffect(() => {\n    if (justRetried.current) loadingMsg.current?.focus(); // the Retry button left: focus goes to the message that answers it\n    justRetried.current = false;\n  }, [retried]);\n  const state = retried && props.state === 'error' ? 'loading' : props.state;\n  const weeks = useMemo(() => monthGrid(month, props.firstDay), [month, props.firstDay]);\n  const label = monthName(month, props.locale);\n  const events = useMemo(() => {\n    const by = new Map<string, (Props['events'][number] & { i: number })[]>();\n    for (const e of byWhen(props.events.map((x, i) => ({ ...x, i })).filter((x) => realDay(x.date)))) by.set(e.date, [...(by.get(e.date) ?? []), e]);\n    return by;\n  }, [props.events]);\n  const shown = state === 'filled' || editing;\n  const monthHasEvents = weeks.flat().some((c) => c.inMonth && events.has(c.iso));\n  const quiet = state === 'empty' || (state === 'filled' && !monthHasEvents); // nothing to show in this month, however the person got here\n  const agenda = weeks.flat().filter((c) => c.inMonth && (c.iso === props.today || (shown && events.has(c.iso))));\n  const where = (iso: string) => (shown ? (events.get(iso) ?? []) : []);\n  return (\n    <Section labelledBy={id}>\n      <Container>\n        <SectionHeader id={id} eyebrow={props.eyebrow} title={props.title} description={props.description} />\n        <AppPanel className=\"mt-10\">\n          <div className=\"flex flex-wrap items-center gap-2 border-b border-kh-line p-4 @xl:p-5\">\n            <h3 className=\"w-full text-kh-heading font-semibold @md:mr-auto @md:w-auto\">{label}</h3>\n            <p role=\"status\" className=\"sr-only\">\n              {label}\n            </p>\n            <IconButton label={props.previous} variant=\"secondary\" noTooltip onClick={() => setMonth((m) => shiftMonth(m, -1))}>\n              <ChevronLeft aria-hidden className=\"size-4\" />\n            </IconButton>\n            <Button ref={todayBtn} type=\"button\" variant=\"secondary\" aria-disabled={month === goodMonth || undefined} className=\"aria-disabled:opacity-50\" onClick={() => month !== goodMonth && setMonth(goodMonth)}>\n              <Text path={['todayLabel']} value={props.todayLabel} as=\"span\" />\n            </Button>\n            <IconButton label={props.next} variant=\"secondary\" noTooltip onClick={() => setMonth((m) => shiftMonth(m, 1))}>\n              <ChevronRight aria-hidden className=\"size-4\" />\n            </IconButton>\n          </div>\n          {editing && (\n            <p className=\"px-5 pt-3 text-kh-caption text-kh-muted\">\n              <Text path={['previous']} value={props.previous} as=\"span\" /> · <Text path={['next']} value={props.next} as=\"span\" /> · <Text path={['at']} value={props.at} as=\"span\" />\n            </p>\n          )}\n          <StateSlot show={bad.length > 0}>\n            <div role=\"alert\" className=\"mx-5 mt-4 rounded-kh-lg border border-kh-danger px-4 py-3 text-kh-small\">\n              <Text path={['messages', 'invalid']} value={props.messages.invalid} as=\"span\" /> <code className=\"font-kh-mono\">{bad.join(', ')}</code>\n            </div>\n          </StateSlot>\n          <StateSlot show={quiet}>\n            <p role=\"status\" className=\"px-5 pt-4 text-kh-small text-kh-muted\">\n              <Text path={['messages', 'empty']} value={props.messages.empty} as=\"span\" />\n            </p>\n          </StateSlot>\n          <StateSlot show={state === 'loading'}>\n            <p ref={loadingMsg} tabIndex={-1} role=\"status\" className=\"px-5 pt-4 text-kh-small text-kh-muted outline-none\">\n              <Text path={['messages', 'loading']} value={props.messages.loading} as=\"span\" />\n            </p>\n          </StateSlot>\n          <StateSlot show={state === 'error'}>\n            <div role=\"alert\" className=\"mx-5 mt-4 flex flex-wrap items-center gap-3 rounded-kh-lg border border-kh-danger px-4 py-3 text-kh-small\">\n              <Text path={['messages', 'error']} value={props.messages.error} as=\"span\" />\n              <Button type=\"button\" variant=\"secondary\" onClick={() => {\n                  justRetried.current = true;\n                  setRetried(true);\n                }}>\n                <Text path={['messages', 'retry']} value={props.messages.retry} as=\"span\" />\n              </Button>\n            </div>\n          </StateSlot>\n\n          <div aria-busy={state === 'loading' || undefined} className=\"hidden p-4 @3xl:block @3xl:p-5\">\n            <table className=\"w-full table-fixed border-collapse text-left\">\n              <caption className=\"sr-only\">{label}</caption>\n              <thead>\n                <tr>\n                  {props.weekdays.map((w, i) => (\n                    <th key={i} scope=\"col\" className=\"border-b border-kh-line px-2 py-2 text-kh-caption font-medium text-kh-muted\">\n                      <Text path={['weekdays', i]} value={w} as=\"span\" />\n                    </th>\n                  ))}\n                </tr>\n              </thead>\n              <tbody>\n                {weeks.map((week, r) => (\n                  <tr key={r}>\n                    {week.map((c) => {\n                      const today = c.iso === props.today;\n                      return (\n                        <td key={c.iso} aria-current={today ? 'date' : undefined} className={cn('h-28 border border-kh-line p-2 align-top', !c.inMonth && 'bg-kh-surface-2 text-kh-muted', today && 'border-kh-ink')}>\n                          <div className=\"flex items-center gap-2\">\n                            <time dateTime={c.iso} className=\"text-kh-small font-medium\">\n                              <span aria-hidden>{c.day}</span>\n                              <span className=\"sr-only\">{dayName(c.iso, props.locale)}</span>\n                            </time>\n                            {today && <span className=\"rounded-kh-pill bg-kh-ink px-2 text-kh-caption font-medium text-kh-on-ink\">{props.todayLabel}</span>}\n                          </div>\n                          <ul className=\"mt-1 flex flex-col gap-1\">\n                            {where(c.iso).map((e, k) => (\n                              <li key={k} className=\"rounded-kh-sm bg-kh-accent-soft px-1.5 py-0.5 text-kh-caption text-kh-accent-ink [overflow-wrap:anywhere]\">\n                                {e.time && <span className=\"tabular-nums\">{e.time} </span>}\n                                <Text path={['events', e.i, 'title']} value={e.title} as=\"span\" />\n                              </li>\n                            ))}\n                          </ul>\n                        </td>\n                      );\n                    })}\n                  </tr>\n                ))}\n              </tbody>\n            </table>\n          </div>\n\n          <div className=\"p-4 @3xl:hidden\">\n            <ol className=\"flex flex-col divide-y divide-kh-line\">\n              {agenda.map((c) => (\n                <li key={c.iso} aria-current={c.iso === props.today ? 'date' : undefined} className=\"py-3\">\n                  <h4 className=\"flex flex-wrap items-center gap-2 text-kh-small font-medium\">\n                    <time dateTime={c.iso}>{dayName(c.iso, props.locale)}</time>\n                    {c.iso === props.today && <span className=\"rounded-kh-pill bg-kh-ink px-2 text-kh-caption font-medium text-kh-on-ink\">{props.todayLabel}</span>}\n                  </h4>\n                  <ul className=\"mt-1 flex flex-col gap-1 text-kh-small\">\n                    {where(c.iso).map((e, k) => (\n                      <li key={k} className=\"[overflow-wrap:anywhere]\">\n                        {e.time && <span className=\"tabular-nums text-kh-muted\">{props.at} {e.time}: </span>}\n                        <Text path={['events', e.i, 'title']} value={e.title} as=\"span\" />\n                      </li>\n                    ))}\n                  </ul>\n                </li>\n              ))}\n            </ol>\n          </div>\n        </AppPanel>\n      </Container>\n    </Section>\n  );\n}\n\nexport default withHeadingLevel(AppSchedulingCalendar);\n"
    }
  ]
}
