# Add the "Article with Contents" block to this P1 project

Add a Puck component from P1 Blocks (https://p1-blocks.prolificdigital.io/blocks/article-toc) to this Pantheon Content Publisher (P1) Next.js project. A long-form article in titled sections with a sticky table of contents on desktop and a collapsible one on phones.

## Steps

1. Create `components/puck/article-toc-block.tsx` with the exact file contents below. If `components/puck/` doesn't exist, find the folder where this project keeps its Puck components (look at the imports in `puck.config.tsx`) and put it there.
2. In `puck.config.tsx`, import it: `import { articleTocBlock } from "./components/puck/article-toc-block";`
3. Register it under `components` as `ArticleTocBlock: articleTocBlock`.
4. Add `"ArticleTocBlock"` to the best-fitting entry in `categories` (this block's library category is "Content"). Create a category only if none fits.
5. Run the project's type check (usually `pnpm typecheck`) and resolve anything project-specific.
6. If `package.json` has a `sync:registry` script, tell the user it must run (or that CI will run it) before the new component appears in the P1 editor.

## Rules

- Do not add dependencies. The block is self-contained by design: one type-only import from `@puckeditor/core`, Tailwind v4 classes, no client JavaScript.
- Keep the files as-is unless the user asks for changes. The accent color is `indigo-*`; if the project has brand colors, offer to swap them with a find-and-replace on `indigo-`.
- Images are plain `imageUrl` + `imageAlt` text fields. If this project defines a P1 media-library field (search for `"p1-media"`), offer to switch to it.
- Don't change prop names in `defaultProps`. Content editors' saved pages depend on them.

## File: `components/puck/article-toc-block.tsx`

```tsx
import type { ComponentConfig } from "@puckeditor/core";

/**
 * Article with Contents — long-form article body split into titled sections, with a sticky
 * "On this page" list of anchor links on desktop and a collapsible one on phones. No JavaScript.
 * Register: `ArticleTocBlock: articleTocBlock` in puck.config.tsx.
 */

type Heading = "h1" | "h2" | "h3" | "h4";

export type ArticleTocProps = {
  eyebrow: string;
  heading: string;
  headingLevel: Heading;
  meta: string;
  lead: string;
  tocLabel: string;
  sections: { heading: string; body: string }[];
};

const childHeading: Record<Heading, "h2" | "h3" | "h4" | "h5"> = { h1: "h2", h2: "h3", h3: "h4", h4: "h5" };

/** Blank lines start paragraphs; a block whose every line starts with "- " becomes a bulleted list. */
function Prose({ text }: { text: string }) {
  const blocks = (text || "").split(/\n\s*\n/).map((b) => b.trim()).filter(Boolean);
  return (
    <>
      {blocks.map((block, i) => {
        const lines = block.split("\n").map((l) => l.trim()).filter(Boolean);
        if (lines.every((l) => /^[-*•]\s+/.test(l))) {
          return (
            <ul key={i} role="list" className="space-y-2 pl-1">
              {lines.map((l, j) => (
                <li key={j} className="flex gap-3">
                  <span aria-hidden="true" className="mt-3.5 h-px w-3 shrink-0 bg-indigo-600" />
                  <span>{l.replace(/^[-*•]\s+/, "")}</span>
                </li>
              ))}
            </ul>
          );
        }
        return <p key={i}>{block}</p>;
      })}
    </>
  );
}

export const articleTocBlock: ComponentConfig<ArticleTocProps> = {
  label: "Article with Contents",
  fields: {
    eyebrow: { type: "text", label: "Eyebrow", metadata: { help: "Small line above the title, like a category. Leave blank to hide it." } },
    heading: { type: "textarea", label: "Title" },
    headingLevel: {
      type: "select",
      label: "Heading level",
      options: [
        { label: "H1", value: "h1" },
        { label: "H2", value: "h2" },
        { label: "H3", value: "h3" },
        { label: "H4", value: "h4" },
      ],
      metadata: { help: "Sets the page outline for screen readers and search. The look doesn't change. Section headings use the next level down." },
    },
    meta: { type: "text", label: "Byline", metadata: { help: "Author, date or reading time, like “Updated March 2026 · 6 min read”. Leave blank to hide it." } },
    lead: { type: "textarea", label: "Lead paragraph", metadata: { help: "A larger opening paragraph. Leave blank to hide it." } },
    tocLabel: { type: "text", label: "Contents label", metadata: { help: "Title of the table of contents, like “On this page”." } },
    sections: {
      type: "array",
      label: "Sections",
      min: 1,
      max: 20,
      getItemSummary: (item) => item?.heading?.slice(0, 48) || "Section",
      defaultItemProps: { heading: "New section", body: "Write this section here." },
      arrayFields: {
        heading: { type: "text", label: "Heading", metadata: { help: "Also becomes the link in the table of contents." } },
        body: {
          type: "textarea",
          label: "Body",
          metadata: { help: "Blank lines start a new paragraph. Start each line of a block with “- ” to make a bulleted list." },
        },
      },
    },
  },
  defaultProps: {
    eyebrow: "Resident guide",
    heading: "Your guide to the 2026 property tax appeal process",
    headingLevel: "h1",
    meta: "Office of the County Assessor · Updated February 2026 · 7 min read",
    lead: "If you believe your new assessment doesn't reflect what your home would sell for, you can appeal it for free. Most residents finish the process without hiring anyone.",
    tocLabel: "On this page",
    sections: [
      {
        heading: "Who can appeal",
        body: "Any property owner, or someone with written authorization from the owner, can file an appeal for residential, commercial or agricultural property.\n\nYou don't need to show that the assessor made a mistake, only that the assessed value is higher than what the property was worth on January 1.",
      },
      {
        heading: "Key dates",
        body: "- Assessment notices mailed: April 1\n- Informal review requests accepted: April 1 – May 15\n- Formal appeal deadline: June 1\n- Board of Review hearings: June 15 – August 30\n\nAppeals postmarked or submitted online after June 1 can't be accepted, so file early if you're unsure.",
      },
      {
        heading: "What evidence helps",
        body: "The strongest evidence is recent sales of similar homes nearby. Look for three to five sales from the past eighteen months with similar size, age and condition.\n\nPhotos of needed repairs, a recent appraisal or a contractor's estimate can also support a lower value.",
      },
      {
        heading: "How to file",
        body: "File online through the assessor's portal, by mail, or in person at the County Building, Room 210. You'll receive a confirmation number and a hearing date by email or letter within three weeks.",
      },
      {
        heading: "What happens at the hearing",
        body: "Hearings take about fifteen minutes and can be held by phone or video. A three-member board reviews your evidence and the assessor's, asks a few questions, and mails a written decision within thirty days.",
      },
      {
        heading: "If you disagree with the decision",
        body: "You can appeal the board's decision to the State Tax Tribunal within 35 days of the decision letter. The tribunal's small claims division handles most residential cases without a filing fee.",
      },
    ],
  },
  render: ({ id, eyebrow, heading, headingLevel, meta, lead, tocLabel, sections }) => {
    const H = headingLevel || "h2";
    const Section = childHeading[H] ?? "h3";
    const uid = `p1-article-${id}`;
    const list = (sections ?? []).filter((s) => s?.heading || s?.body);
    const tocItems = list.map((s, i) => ({ href: `#${uid}-s${i + 1}`, label: s.heading })).filter((t) => t.label);
    const label = tocLabel || "On this page";
    const showToc = tocItems.length > 1;

    const tocList = (
      <ol role="list" className="space-y-1 border-l border-neutral-200">
        {tocItems.map((item, i) => (
          <li key={item.href}>
            <a
              href={item.href}
              className="-ml-px flex min-h-11 items-center gap-3 border-l border-transparent py-1.5 pl-4 text-sm leading-6 text-neutral-600 hover:border-indigo-600 hover:text-neutral-950 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600"
            >
              <span aria-hidden="true" className="w-5 shrink-0 text-xs text-neutral-500 tabular-nums">
                {String(i + 1).padStart(2, "0")}
              </span>
              <span>{item.label}</span>
            </a>
          </li>
        ))}
      </ol>
    );

    return (
      <section className="bg-white px-4 py-16 sm:px-6 sm:py-20 lg:px-8 lg:py-24">
        <div className="mx-auto max-w-6xl">
          <header className="max-w-3xl">
            {eyebrow ? <p className="text-sm font-semibold tracking-wide text-indigo-700 uppercase">{eyebrow}</p> : null}
            {heading ? (
              <H className={`${eyebrow ? "mt-3" : ""} text-4xl font-semibold tracking-tight text-balance text-neutral-950 sm:text-5xl`}>{heading}</H>
            ) : null}
            {meta ? <p className="mt-5 text-sm text-neutral-600">{meta}</p> : null}
          </header>

          <div className={`mt-10 grid grid-cols-1 gap-10 sm:mt-14 ${showToc ? "lg:grid-cols-12 lg:gap-16" : ""}`}>
            {showToc ? (
              <>
                <details className="group rounded-xl bg-neutral-50 ring-1 ring-neutral-950/5 lg:hidden">
                  <summary className="flex min-h-12 cursor-pointer list-none items-center justify-between gap-4 rounded-xl px-4 text-sm font-semibold text-neutral-950 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600 [&::-webkit-details-marker]:hidden">
                    <span>
                      {label}
                      <span className="ml-2 font-normal text-neutral-600">({tocItems.length} sections)</span>
                    </span>
                    <svg aria-hidden="true" viewBox="0 0 20 20" fill="currentColor" className="size-5 shrink-0 text-neutral-500 transition group-open:rotate-180">
                      <path fillRule="evenodd" d="M5.22 8.22a.75.75 0 0 1 1.06 0L10 11.94l3.72-3.72a.75.75 0 1 1 1.06 1.06l-4.25 4.25a.75.75 0 0 1-1.06 0L5.22 9.28a.75.75 0 0 1 0-1.06Z" clipRule="evenodd" />
                    </svg>
                  </summary>
                  <nav aria-label={label} className="px-4 pb-4">
                    {tocList}
                  </nav>
                </details>

                <nav aria-label={label} className="hidden lg:order-last lg:col-span-4 lg:block xl:col-span-3 xl:col-start-10">
                  <div className="sticky top-24">
                    <p className="text-xs font-semibold tracking-widest text-neutral-500 uppercase">{label}</p>
                    <div className="mt-4">{tocList}</div>
                  </div>
                </nav>
              </>
            ) : null}

            <article className={showToc ? "lg:col-span-8" : "max-w-3xl"}>
              {lead ? <p className="max-w-prose text-xl leading-9 text-pretty text-neutral-800">{lead}</p> : null}
              <div className={`${lead ? "mt-10" : ""} max-w-prose space-y-12`}>
                {list.map((s, i) => (
                  <div key={`${s.heading}-${i}`}>
                    {s.heading ? (
                      <Section
                        id={`${uid}-s${i + 1}`}
                        className="scroll-mt-24 border-t border-neutral-200 pt-8 text-2xl font-semibold tracking-tight text-balance text-neutral-950 target:border-indigo-600"
                      >
                        {s.heading}
                      </Section>
                    ) : null}
                    {s.body ? (
                      <div className={`${s.heading ? "mt-4" : ""} space-y-5 text-lg leading-8 text-pretty text-neutral-700`}>
                        <Prose text={s.body} />
                      </div>
                    ) : null}
                  </div>
                ))}
              </div>
            </article>
          </div>
        </div>
      </section>
    );
  },
};
```
