# Add the "Glossary" block to this P1 project

Add a Puck component from P1 Blocks (https://p1-blocks.prolificdigital.io/blocks/glossary) to this Pantheon Content Publisher (P1) Next.js project. Terms sorted A–Z and grouped by letter, with jump links, cross-references and definition-list markup.

## Steps

1. Create `components/puck/glossary-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 { glossaryBlock } from "./components/puck/glossary-block";`
3. Register it under `components` as `GlossaryBlock: glossaryBlock`.
4. Add `"GlossaryBlock"` 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/glossary-block.tsx`

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

/**
 * Glossary — terms sorted A–Z and grouped by first letter, with a sticky letter bar of jump
 * links and real <dl> markup. Terms can be entered in any order; the block sorts them.
 * Register: `GlossaryBlock: glossaryBlock` in puck.config.tsx.
 */

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

export type GlossaryProps = {
  heading: string;
  headingLevel: Heading;
  intro: string;
  terms: { term: string; aka: string; definition: string; seeAlso: string }[];
};

const childHeading: Record<Heading, "h2" | "h3" | "h4" | "h5"> = { h1: "h2", h2: "h3", h3: "h4", h4: "h5" };
const ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".split("");

const letterOf = (term: string) => {
  const first = term
    .trim()
    .normalize("NFD")
    .replace(/[̀-ͯ]/g, "")
    .charAt(0)
    .toUpperCase();
  return /[A-Z]/.test(first) ? first : "#";
};

export const glossaryBlock: ComponentConfig<GlossaryProps> = {
  label: "Glossary",
  fields: {
    heading: { type: "text", label: "Heading" },
    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. Letter headings use the next level down." },
    },
    intro: { type: "textarea", label: "Intro" },
    terms: {
      type: "array",
      label: "Terms",
      min: 1,
      max: 200,
      getItemSummary: (item) => item?.term?.slice(0, 48) || "Term",
      defaultItemProps: { term: "New term", aka: "", definition: "A plain-language definition.", seeAlso: "" },
      arrayFields: {
        term: { type: "text", label: "Term" },
        aka: { type: "text", label: "Also called", metadata: { help: "Abbreviation or other name, like “CIP”. Leave blank to hide it." } },
        definition: { type: "textarea", label: "Definition", metadata: { help: "Blank lines start a new paragraph." } },
        seeAlso: { type: "text", label: "See also", metadata: { help: "Related terms, separated by commas. Ones that match a term in this glossary become links." } },
      },
      metadata: { help: "Add terms in any order. They're sorted alphabetically on the page." },
    },
  },
  defaultProps: {
    heading: "Budget glossary",
    headingLevel: "h2",
    intro: "Public budgets come with their own vocabulary. Here is what the terms in our annual budget and council agendas mean, in plain language.",
    terms: [
      { term: "Appropriation", aka: "", definition: "Money the City Council legally authorizes a department to spend for a specific purpose during the fiscal year.", seeAlso: "Operating budget, Encumbrance" },
      { term: "Bond", aka: "", definition: "A loan the city takes out by selling debt to investors, repaid with interest over time. Bonds usually pay for long-lived projects like bridges, libraries and water lines.", seeAlso: "Capital Improvement Plan, Debt service" },
      { term: "Capital Improvement Plan", aka: "CIP", definition: "A five-year schedule of major construction and equipment purchases, updated every year, showing what each project costs and how it will be paid for.", seeAlso: "Bond" },
      { term: "Debt service", aka: "", definition: "The yearly principal and interest payments on money the city has borrowed.", seeAlso: "Bond" },
      { term: "Encumbrance", aka: "", definition: "Money set aside for a purchase that has been ordered but not yet paid for, so it can't be spent twice.", seeAlso: "Appropriation" },
      { term: "Enterprise fund", aka: "", definition: "A fund for a service that pays for itself through user fees, such as water, sewer or golf courses, kept separate from tax-supported services.", seeAlso: "General Fund" },
      { term: "Fiscal year", aka: "FY", definition: "The city's twelve-month budget year, which runs July 1 through June 30. FY2027 begins July 1, 2026.", seeAlso: "" },
      { term: "Fund balance", aka: "", definition: "What remains in a fund after expenses are subtracted from revenues; the city's savings. Council policy keeps at least 15% of General Fund spending in reserve.", seeAlso: "General Fund" },
      { term: "General Fund", aka: "", definition: "The city's main operating fund, paid for mostly by property and sales taxes, that supports police, fire, parks, libraries and street maintenance.", seeAlso: "Enterprise fund, Fund balance" },
      { term: "Millage rate", aka: "Mill levy", definition: "The property tax rate. One mill equals $1 of tax for every $1,000 of a property's taxable value.", seeAlso: "" },
      { term: "Operating budget", aka: "", definition: "The plan for day-to-day spending on salaries, supplies, utilities and services, as opposed to one-time construction.", seeAlso: "Capital Improvement Plan" },
      { term: "Tax increment financing", aka: "TIF", definition: "A tool that sets aside future growth in property tax revenue within a defined district to pay for public improvements in that same district.", seeAlso: "" },
    ],
  },
  render: ({ id, heading, headingLevel, intro, terms }) => {
    const H = headingLevel || "h2";
    const Letter = childHeading[H] ?? "h3";
    const uid = `p1-glossary-${id}`;
    const list = (terms ?? [])
      .filter((t) => t?.term?.trim())
      .sort((a, b) => a.term.trim().localeCompare(b.term.trim(), undefined, { sensitivity: "base" }))
      .map((t, i) => ({ ...t, anchor: `${uid}-t${i}` }));

    const termId = new Map<string, string>();
    for (const t of list) if (!termId.has(t.term.trim().toLowerCase())) termId.set(t.term.trim().toLowerCase(), t.anchor);

    const groups: { key: string; items: typeof list }[] = [];
    for (const t of list) {
      const key = letterOf(t.term);
      const last = groups[groups.length - 1];
      if (last && last.key === key) last.items.push(t);
      else groups.push({ key, items: [t] });
    }
    // Non-letter terms ("#") sort first in localeCompare; keep that, and give the rail a "#" stop if needed.
    const present = new Set(groups.map((g) => g.key));
    const rail = present.has("#") ? ["#", ...ALPHABET] : ALPHABET;
    const slug = (k: string) => (k === "#" ? "num" : k.toLowerCase());

    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-5xl">
          {heading || intro ? (
            <div className="max-w-2xl">
              {heading ? <H className="text-3xl font-semibold tracking-tight text-balance text-neutral-950 sm:text-4xl">{heading}</H> : null}
              {intro ? <p className="mt-4 text-lg leading-8 text-pretty text-neutral-600">{intro}</p> : null}
            </div>
          ) : null}

          {groups.length > 0 ? (
            <>
              <nav
                id={`${uid}-letters`}
                aria-label={heading ? `${heading}: jump to letter` : "Jump to letter"}
                className={`${heading || intro ? "mt-10" : ""} -mx-4 sm:sticky sm:top-0 sm:z-10 scroll-mt-4 border-y border-neutral-200 bg-white/95 px-4 py-2 backdrop-blur sm:mx-0 sm:rounded-xl sm:border sm:px-2`}
              >
                <ul role="list" className="flex flex-wrap justify-start gap-0.5">
                  {rail.map((letter) =>
                    present.has(letter) ? (
                      <li key={letter}>
                        <a
                          href={`#${uid}-${slug(letter)}`}
                          className="grid size-11 place-items-center rounded-lg text-sm font-semibold text-neutral-900 hover:bg-indigo-50 hover:text-indigo-700 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600"
                        >
                          {letter === "#" ? (
                            <>
                              <span aria-hidden="true">#</span>
                              <span className="sr-only">Numbers and symbols</span>
                            </>
                          ) : (
                            letter
                          )}
                        </a>
                      </li>
                    ) : (
                      <li key={letter} aria-hidden="true" className="grid size-11 place-items-center text-sm text-neutral-300 select-none">
                        {letter}
                      </li>
                    ),
                  )}
                </ul>
              </nav>

              <div className="mt-4 divide-y divide-neutral-200">
                {groups.map((group) => (
                  <section key={group.key} aria-labelledby={`${uid}-${slug(group.key)}`} className="grid grid-cols-1 gap-4 py-10 sm:grid-cols-12 sm:gap-8">
                    <div className="sm:col-span-2">
                      <Letter
                        id={`${uid}-${slug(group.key)}`}
                        className="scroll-mt-28 text-5xl font-light tracking-tight text-indigo-700 sm:text-6xl"
                      >
                        {group.key === "#" ? (
                          <>
                            <span aria-hidden="true">#</span>
                            <span className="sr-only">Numbers and symbols</span>
                          </>
                        ) : (
                          group.key
                        )}
                      </Letter>
                    </div>
                    <dl className="space-y-8 sm:col-span-10">
                      {group.items.map((t) => {
                        const related = (t.seeAlso || "").split(",").map((s) => s.trim()).filter(Boolean);
                        const paragraphs = (t.definition || "").split(/\n\s*\n/).map((p) => p.trim()).filter(Boolean);
                        return (
                          <div key={t.anchor} id={t.anchor} className="scroll-mt-28">
                            <dt className="flex flex-wrap items-baseline gap-x-3 gap-y-1">
                              <dfn className="text-lg font-semibold text-neutral-950 not-italic">{t.term}</dfn>
                              {t.aka ? <span className="rounded-md bg-neutral-100 px-2 py-0.5 text-xs font-medium text-neutral-700">{t.aka}</span> : null}
                            </dt>
                            {paragraphs.map((p, j) => (
                              <dd key={j} className="mt-2 max-w-prose text-base leading-7 text-pretty text-neutral-600">
                                {p}
                              </dd>
                            ))}
                            {related.length > 0 ? (
                              <dd className="mt-3 text-sm leading-6 text-neutral-600">
                                <span className="font-medium text-neutral-800">See also: </span>
                                {related.map((r, k) => {
                                  const target = termId.get(r.toLowerCase());
                                  return (
                                    <span key={r}>
                                      {k > 0 ? ", " : null}
                                      {target ? (
                                        <a
                                          href={`#${target}`}
                                          className="rounded-sm font-medium text-indigo-700 underline decoration-indigo-300 underline-offset-4 hover:decoration-indigo-700 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600"
                                        >
                                          {r}
                                        </a>
                                      ) : (
                                        r
                                      )}
                                    </span>
                                  );
                                })}
                              </dd>
                            ) : null}
                          </div>
                        );
                      })}
                    </dl>
                    <p className="sm:col-span-10 sm:col-start-3">
                      <a
                        href={`#${uid}-letters`}
                        className="inline-flex min-h-11 items-center gap-1.5 rounded-sm text-sm font-medium text-neutral-600 hover:text-neutral-950 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600"
                      >
                        <svg aria-hidden="true" viewBox="0 0 16 16" fill="currentColor" className="size-4">
                          <path fillRule="evenodd" d="M8 14a.75.75 0 0 1-.75-.75V4.56L4.03 7.78a.75.75 0 0 1-1.06-1.06l4.5-4.5a.75.75 0 0 1 1.06 0l4.5 4.5a.75.75 0 0 1-1.06 1.06L8.75 4.56v8.69A.75.75 0 0 1 8 14Z" clipRule="evenodd" />
                        </svg>
                        Back to letters
                      </a>
                    </p>
                  </section>
                ))}
              </div>
            </>
          ) : null}
        </div>
      </section>
    );
  },
};
```
