{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "error-page",
  "title": "Error Page",
  "description": "A 404, 500 or offline screen with honest wording and a way out that can work: one sentence, beside places that still work, or a plain readout for developer tools.",
  "dependencies": [
    "lucide-react"
  ],
  "registryDependencies": [
    "utils",
    "https://miseui.junsu4621.workers.dev/r/button.json",
    "https://miseui.junsu4621.workers.dev/r/clipboard.json"
  ],
  "files": [
    {
      "path": "registry/miseui/blocks/error-page.tsx",
      "content": "import type * as React from \"react\"\r\nimport { cn } from \"@/registry/miseui/lib/utils\"\r\nimport { ERROR_COPY, resolveErrorCode, type ErrorCopy, type ErrorPageCode, type ErrorPageLink } from \"./error-page-copy\"\r\nimport { ErrorActions, ErrorNews, ErrorReference } from \"./error-page-parts\"\r\nimport { ErrorSplit } from \"./error-page-split\"\r\nimport { reloadPage, useRetry } from \"./error-page-state\"\r\nimport { ErrorTerminal } from \"./error-page-terminal\"\r\n\r\ntype ErrorPageVariant = \"centered\" | \"split\" | \"terminal\"\r\n\r\ninterface ErrorPageProps extends Omit<React.ComponentProps<\"section\">, \"title\"> {\r\n  /** `centered` one sentence and a way out, `split` beside places that still work, `terminal` a plain readout for developer tools. Anything else is `centered`. */\r\n  variant?: ErrorPageVariant\r\n  /** Decides the wording and the way out. Another 5xx reads as 500, and anything else as 404. */\r\n  code?: ErrorPageCode | 404 | 500\r\n  title?: string\r\n  /** Continues the title, one tone quieter. Say what happened and what can be done, and do not guess at a cause. */\r\n  detail?: string\r\n  /** The default reloads the page. Return a promise to get the waiting state; a rejection says it did not work. */\r\n  onRetry?: () => void | Promise<void>\r\n  homeHref?: string\r\n  homeLabel?: string\r\n  /** Null removes the link. */\r\n  helpHref?: string | null\r\n  /** Something to quote to support, such as a request id. */\r\n  reference?: string\r\n  /** `split`: your own places that still work. */\r\n  links?: readonly ErrorPageLink[]\r\n  /** `terminal`: the address in the readout. Left out, it reads the current one. */\r\n  path?: string\r\n  /** `terminal`: when it happened. Pass it from the server, or leave it out. */\r\n  time?: string\r\n}\r\n\r\nfunction ErrorHeading({ copy, title, detail }: { copy: ErrorCopy; title?: string; detail?: string }) {\r\n  return (\r\n    <h1 className=\"text-display text-3xl leading-[1.12]! text-balance @3xl:text-4xl\">\r\n      {title ?? copy.title} <span className=\"text-muted-foreground\">{detail ?? copy.detail}</span>\r\n    </h1>\r\n  )\r\n}\r\n\r\nfunction ErrorCentered({ className, children, ...props }: React.ComponentProps<\"section\">) {\r\n  return (\r\n    <section data-slot=\"error-page\" data-variant=\"centered\" className={cn(\"@container flex w-full flex-col bg-muted dark:bg-background\", className)} {...props}>\r\n      <div className=\"flex min-h-[640px] flex-1 flex-col items-center justify-center gap-6 px-4 py-12 text-center\">\r\n        <div className=\"flex w-full max-w-2xl min-w-0 flex-col items-center gap-6\">{children}</div>\r\n      </div>\r\n    </section>\r\n  )\r\n}\r\n\r\nfunction ErrorPage({ variant, code: codeProp = \"404\", title, detail, onRetry = reloadPage, homeHref = \"/\", homeLabel = \"Go to the home page\", helpHref = \"#support\", reference, links, path, time, ...props }: ErrorPageProps) {\r\n  const code = resolveErrorCode(codeProp)\r\n  const copy = ERROR_COPY[code]\r\n  const retry = useRetry(onRetry)\r\n  const centered = variant !== \"split\" && variant !== \"terminal\"\r\n  const body = (\r\n    <>\r\n      <ErrorHeading copy={copy} title={title} detail={detail} />\r\n      <div className={cn(\"flex max-w-full min-w-0 flex-col gap-3\", centered && \"items-center\")}>\r\n        <ErrorActions code={code} retry={retry} homeHref={homeHref} homeLabel={homeLabel} helpHref={helpHref} centered={centered} />\r\n        <ErrorNews code={code} retry={retry} />\r\n        {centered ? <p className=\"text-[13px] text-muted-foreground\">{copy.name}</p> : null}\r\n        {reference && variant !== \"terminal\" ? <ErrorReference reference={reference} /> : null}\r\n      </div>\r\n    </>\r\n  )\r\n  if (variant === \"split\") return <ErrorSplit copy={copy} list={links ?? copy.list} {...props}>{body}</ErrorSplit>\r\n  if (variant === \"terminal\") return <ErrorTerminal code={code} copy={copy} path={path} time={time} reference={reference} {...props}>{body}</ErrorTerminal>\r\n  return <ErrorCentered {...props}>{body}</ErrorCentered>\r\n}\r\n\r\nexport { ErrorPage, type ErrorPageCode, type ErrorPageLink, type ErrorPageProps, type ErrorPageVariant }\r\n",
      "type": "registry:component"
    },
    {
      "path": "registry/miseui/blocks/error-page-copy.ts",
      "content": "type ErrorPageCode = \"404\" | \"500\" | \"offline\"\n\ninterface ErrorPageLink {\n  label: string\n  description?: string\n  /** Without it the row is only something to read, such as a thing to check. */\n  href?: string\n}\n\ninterface ErrorCopy {\n  /** The name of the error, for the small line and the readout. */\n  name: string\n  title: string\n  /** Says what happened and what can be done. Blames nobody, and does not claim a cause nobody knows. */\n  detail: string\n  /** One plain sentence for the terminal readout. */\n  readout: string\n  /** Heads the list on `split`. */\n  listTitle: string\n  list: readonly ErrorPageLink[]\n}\n\nconst ERROR_COPY: Record<ErrorPageCode, ErrorCopy> = {\n  \"404\": {\n    name: \"Error 404\",\n    title: \"We could not find this page.\",\n    detail: \"It may have moved, or the link may be out of date.\",\n    readout: \"Nothing is published at this address.\",\n    listTitle: \"These pages are still here.\",\n    list: [\n      { label: \"Invoices\", description: \"Everything you have sent and drafted.\", href: \"#invoices\" },\n      { label: \"Customers\", description: \"The people and companies you bill.\", href: \"#customers\" },\n      { label: \"Help centre\", description: \"Search the guides.\", href: \"#help\" },\n    ],\n  },\n  \"500\": {\n    name: \"Error 500\",\n    title: \"Something went wrong on our side.\",\n    detail: \"The page did not load. Nothing you did caused this, and trying again may work.\",\n    readout: \"The server could not finish this request.\",\n    listTitle: \"If it keeps happening.\",\n    list: [\n      { label: \"Status page\", description: \"See whether we already know.\", href: \"#status\" },\n      { label: \"Contact support\", description: \"Include the reference, if there is one.\", href: \"#support\" },\n    ],\n  },\n  offline: {\n    name: \"No connection\",\n    title: \"This page needs a connection.\",\n    detail: \"It could not reach the network from this device. Check your connection, then try again.\",\n    readout: \"The request did not reach the network.\",\n    listTitle: \"Worth checking.\",\n    list: [{ label: \"Wi-Fi or mobile data is on\" }, { label: \"Airplane mode is off\" }, { label: \"A VPN or firewall is not blocking the page\" }],\n  },\n}\n\nconst SERVER_ERROR = /^5\\d\\d$/\n\n/** A plain string lookup would hand back Object.prototype members for a value such as \"constructor\". */\nfunction resolveErrorCode(code: unknown): ErrorPageCode {\n  const text = String(code)\n  if (text === \"offline\" || text === \"404\" || text === \"500\") return text\n  // Any other 5xx is still our side; anything else keeps the wording that assumes the least.\n  return SERVER_ERROR.test(text) ? \"500\" : \"404\"\n}\n\nexport { ERROR_COPY, resolveErrorCode, type ErrorCopy, type ErrorPageCode, type ErrorPageLink }\n",
      "type": "registry:component"
    },
    {
      "path": "registry/miseui/blocks/error-page-parts.tsx",
      "content": "import { ArrowLeft, Loader2 } from \"lucide-react\"\r\nimport { cn } from \"@/registry/miseui/lib/utils\"\r\nimport { Button } from \"@/registry/miseui/ui/button\"\r\nimport { Clipboard } from \"@/registry/miseui/ui/clipboard\"\r\nimport type { ErrorPageCode } from \"./error-page-copy\"\r\nimport { useOnline, type Retry } from \"./error-page-state\"\r\n\r\nconst LINK_TOUCH_CLASS = \"relative underline-offset-4 outline-none hover:underline focus-visible:rounded-sm focus-visible:ring-[3px] focus-visible:ring-ring/50 pointer-coarse:after:absolute pointer-coarse:after:-inset-x-1 pointer-coarse:after:-inset-y-3\"\r\n\r\ninterface ErrorActionsProps {\r\n  code: ErrorPageCode\r\n  retry: Retry\r\n  homeHref: string\r\n  homeLabel: string\r\n  /** Null removes the link. */\r\n  helpHref: string | null\r\n  centered: boolean\r\n}\r\n\r\nfunction RetryButton({ retry, primary }: { retry: Retry; primary: boolean }) {\r\n  return (\r\n    <Button\r\n      variant={primary ? \"mise\" : \"outline\"}\r\n      aria-busy={retry.retrying || undefined}\r\n      aria-disabled={retry.retrying || undefined}\r\n      onClick={() => void retry.retry()}\r\n      className=\"pointer-coarse:h-10\"\r\n    >\r\n      {retry.retrying ? <Loader2 aria-hidden=\"true\" className=\"animate-spin motion-reduce:animate-none\" /> : null}\r\n      {retry.retrying ? \"Trying again\" : \"Try again\"}\r\n    </Button>\r\n  )\r\n}\r\n\r\nfunction BackButton() {\r\n  return (\r\n    <Button variant=\"ghost\" onClick={() => window.history.back()} className=\"pointer-coarse:h-10\">\r\n      <ArrowLeft aria-hidden=\"true\" />\r\n      Go back\r\n    </Button>\r\n  )\r\n}\r\n\r\n/** Each error gets the way out that can work: a 404 cannot be retried, and an offline device cannot follow a link home. */\r\nfunction ErrorActions({ code, retry, homeHref, homeLabel, helpHref, centered }: ErrorActionsProps) {\r\n  const home = (\r\n    <Button asChild variant={code === \"404\" ? \"mise\" : \"outline\"} className=\"pointer-coarse:h-10\">\r\n      <a href={homeHref}>{homeLabel}</a>\r\n    </Button>\r\n  )\r\n  return (\r\n    <>\r\n      <div className={cn(\"flex flex-wrap items-center gap-2\", centered && \"justify-center\")}>\r\n        {code === \"404\" ? home : <RetryButton retry={retry} primary />}\r\n        {code === \"500\" ? home : <BackButton />}\r\n      </div>\r\n      {helpHref && code !== \"offline\" ? (\r\n        <p className=\"text-[13px] text-muted-foreground\">\r\n          Still stuck?{\" \"}\r\n          <a href={helpHref} className={cn(\"font-medium text-foreground\", LINK_TOUCH_CLASS)}>\r\n            Contact support\r\n          </a>\r\n        </p>\r\n      ) : null}\r\n    </>\r\n  )\r\n}\r\n\r\n/** Mounted from the start so it is a live region before there is news. The wording only reports what the device says. */\r\nfunction ErrorNews({ code, retry }: { code: ErrorPageCode; retry: Retry }) {\r\n  const online = useOnline()\r\n  const connection = online ? \"Your device reports a connection now. Try again.\" : \"Your device reports no connection yet.\"\r\n  const message = retry.failed ? \"That did not work either. Give it a minute, then try again.\" : code === \"offline\" ? connection : \"\"\r\n  return (\r\n    <p role=\"status\" className=\"text-[13px] leading-5 text-pretty text-muted-foreground empty:sr-only\">\r\n      {message}\r\n    </p>\r\n  )\r\n}\r\n\r\n/** For quoting to support. Copy sits beside it, because nobody should have to retype a request id. */\r\nfunction ErrorReference({ reference, className }: { reference: string; className?: string }) {\r\n  return (\r\n    <div className={cn(\"flex min-w-0 items-center gap-1 text-[13px] text-muted-foreground\", className)}>\r\n      <span className=\"min-w-0 break-all\">\r\n        Reference <span className=\"font-mono text-foreground\">{reference}</span>\r\n      </span>\r\n      <Clipboard value={reference} label=\"Copy reference\" />\r\n    </div>\r\n  )\r\n}\r\n\r\nexport { ErrorActions, ErrorNews, ErrorReference, type ErrorActionsProps }\r\n",
      "type": "registry:component"
    },
    {
      "path": "registry/miseui/blocks/error-page-split.tsx",
      "content": "import type * as React from \"react\"\nimport { ArrowRight } from \"lucide-react\"\nimport { cn } from \"@/registry/miseui/lib/utils\"\nimport type { ErrorCopy, ErrorPageLink } from \"./error-page-copy\"\n\nfunction ListRow({ link }: { link: ErrorPageLink }) {\n  const body = (\n    <span className=\"min-w-0 flex-1\">\n      <span className=\"block text-sm font-medium\">{link.label}</span>\n      {link.description ? <span className=\"block text-[13px] text-pretty text-muted-foreground\">{link.description}</span> : null}\n    </span>\n  )\n  if (!link.href) return <div className=\"flex min-h-10 items-center px-4 py-3\">{body}</div>\n  return (\n    <a href={link.href} className=\"group flex min-h-10 items-center gap-3 rounded-2xl px-4 py-3 outline-none transition-colors duration-(--duration-fast) ease-(--ease-mise) hover:bg-accent/60 focus-visible:ring-[3px] focus-visible:ring-ring/50 focus-visible:ring-inset\">\n      {body}\n      <ArrowRight aria-hidden=\"true\" className=\"size-4 shrink-0 text-muted-foreground transition-[translate] duration-(--duration-fast) ease-(--ease-mise) group-hover:translate-x-0.5 motion-reduce:transition-none\" />\n    </a>\n  )\n}\n\ninterface ErrorSplitProps extends React.ComponentProps<\"section\"> {\n  copy: ErrorCopy\n  list: readonly ErrorPageLink[]\n  /** Heading, actions and notes. */\n  children: React.ReactNode\n}\n\n/** For a product with many ways in: beside the apology, the places that still work, so nobody has to start from the top. */\nfunction ErrorSplit({ copy, list, className, children, ...props }: ErrorSplitProps) {\n  return (\n    <section data-slot=\"error-page\" data-variant=\"split\" className={cn(\"@container flex w-full flex-col bg-muted dark:bg-background\", className)} {...props}>\n      <div className=\"flex min-h-[640px] flex-1 items-center px-4 py-12 @3xl:px-8\">\n        <div className=\"mx-auto grid w-full max-w-5xl grid-cols-[minmax(0,1fr)] items-center gap-8 @3xl:grid-cols-2 @3xl:gap-12\">\n          <div className=\"flex min-w-0 flex-col items-start gap-6\">{children}</div>\n          <div className=\"flex min-w-0 flex-col gap-3\">\n            <h2 className=\"text-title px-1 text-lg text-balance\">{copy.listTitle}</h2>\n            <ul className=\"flex flex-col divide-y rounded-2xl border bg-background dark:bg-card\">\n              {list.map((link) => (\n                <li key={link.label}>\n                  <ListRow link={link} />\n                </li>\n              ))}\n            </ul>\n          </div>\n        </div>\n      </div>\n    </section>\n  )\n}\n\nexport { ErrorSplit }\n",
      "type": "registry:component"
    },
    {
      "path": "registry/miseui/blocks/error-page-state.ts",
      "content": "import { useState, useSyncExternalStore } from \"react\"\n\nconst noSubscribe = () => () => undefined\n\nfunction subscribeToConnection(notify: () => void) {\n  window.addEventListener(\"online\", notify)\n  window.addEventListener(\"offline\", notify)\n  return () => {\n    window.removeEventListener(\"online\", notify)\n    window.removeEventListener(\"offline\", notify)\n  }\n}\n\n/** The server cannot know, so it renders what the error itself says: no connection. */\nfunction useOnline() {\n  return useSyncExternalStore(subscribeToConnection, () => navigator.onLine, () => false)\n}\n\n/** Read from the browser and not faked: the readout shows the address this page is really on. */\nfunction usePathname() {\n  return useSyncExternalStore(noSubscribe, () => window.location.pathname, () => \"\")\n}\n\nfunction reloadPage() {\n  window.location.reload()\n}\n\nfunction useRetry(onRetry: () => void | Promise<void>) {\n  const [retrying, setRetrying] = useState(false)\n  const [failed, setFailed] = useState(false)\n  const retry = async () => {\n    if (retrying) return\n    setRetrying(true)\n    setFailed(false)\n    try {\n      await onRetry()\n    } catch {\n      setFailed(true)\n    } finally {\n      setRetrying(false)\n    }\n  }\n  return { retrying, failed, retry }\n}\n\ntype Retry = ReturnType<typeof useRetry>\n\nexport { reloadPage, useOnline, usePathname, useRetry, type Retry }\n",
      "type": "registry:component"
    },
    {
      "path": "registry/miseui/blocks/error-page-terminal.tsx",
      "content": "import type * as React from \"react\"\r\nimport { cn } from \"@/registry/miseui/lib/utils\"\r\nimport { Clipboard } from \"@/registry/miseui/ui/clipboard\"\r\nimport type { ErrorCopy, ErrorPageCode } from \"./error-page-copy\"\r\nimport { usePathname } from \"./error-page-state\"\r\n\r\ninterface ReadoutRow {\r\n  term: string\r\n  value: string\r\n}\r\n\r\n/** Real values only, and a row with nothing to say is left out. A prompt or a command here would be something to type that does nothing. */\r\nfunction readoutRows(code: ErrorPageCode, copy: ErrorCopy, path: string, time: string | undefined, reference: string | undefined): readonly ReadoutRow[] {\r\n  const rows: readonly (ReadoutRow | null)[] = [\r\n    { term: \"status\", value: code },\r\n    { term: \"reason\", value: copy.readout },\r\n    path ? { term: \"path\", value: path } : null,\r\n    time ? { term: \"time\", value: time } : null,\r\n    reference ? { term: \"reference\", value: reference } : null,\r\n  ]\r\n  return rows.filter((row) => row !== null)\r\n}\r\n\r\ninterface ErrorTerminalProps extends React.ComponentProps<\"section\"> {\r\n  code: ErrorPageCode\r\n  copy: ErrorCopy\r\n  /** The address shown in the readout. Left out, it reads the current one. */\r\n  path?: string\r\n  time?: string\r\n  reference?: string\r\n  /** Heading, actions and notes. */\r\n  children: React.ReactNode\r\n}\r\n\r\n/** For a developer tool, where people want the facts to paste into a ticket. Plain text, selectable, in one block with a copy button. */\r\nfunction ErrorTerminal({ code, copy, path, time, reference, className, children, ...props }: ErrorTerminalProps) {\r\n  const pathname = usePathname()\r\n  const rows = readoutRows(code, copy, path ?? pathname, time, reference)\r\n  const text = rows.map((row) => `${row.term}: ${row.value}`).join(\"\\n\")\r\n  return (\r\n    <section data-slot=\"error-page\" data-variant=\"terminal\" className={cn(\"@container flex w-full flex-col bg-background\", className)} {...props}>\r\n      <div className=\"flex min-h-[640px] flex-1 items-center justify-center px-4 py-12\">\r\n        <div className=\"flex w-full max-w-xl min-w-0 flex-col items-start gap-6\">\r\n          {children}\r\n          <div className=\"relative w-full min-w-0 rounded-2xl bg-muted p-4 pe-12\">\r\n            <dl data-testid=\"error-readout\" className=\"grid grid-cols-[auto_minmax(0,1fr)] gap-x-4 gap-y-1 font-mono text-[13px] leading-5\">\r\n              {rows.map((row) => (\r\n                <div key={row.term} className=\"col-span-2 grid grid-cols-subgrid\">\r\n                  <dt className=\"text-muted-foreground\">{row.term}</dt>\r\n                  <dd className=\"min-w-0 wrap-break-word\">{row.value}</dd>\r\n                </div>\r\n              ))}\r\n            </dl>\r\n            <Clipboard value={text} label=\"Copy these details\" className=\"absolute end-2 top-2\" />\r\n          </div>\r\n        </div>\r\n      </div>\r\n    </section>\r\n  )\r\n}\r\n\r\nexport { ErrorTerminal, readoutRows }\r\n",
      "type": "registry:component"
    }
  ],
  "categories": [
    "blocks"
  ],
  "type": "registry:block"
}