# Add the "Share Links" block to this P1 project

Add a Puck component from P1 Blocks (https://p1-blocks.prolificdigital.io/blocks/share-links) to this Pantheon Content Publisher (P1) Next.js project. Spread-the-word panel with labelled Facebook, LinkedIn, Bluesky and email share links built as plain URLs.

## Steps

1. Create `components/puck/share-links-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 { shareLinksBlock } from "./components/puck/share-links-block";`
3. Register it under `components` as `ShareLinksBlock: shareLinksBlock`.
4. Add `"ShareLinksBlock"` to the best-fitting entry in `categories` (this block's library category is "Conversion"). 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/share-links-block.tsx`

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

/**
 * Share Links — "Spread the word" with labelled share links for Facebook, LinkedIn, Bluesky
 * and email, built as plain URLs from a page link and message. No JavaScript, no trackers.
 * Register: `ShareLinksBlock: shareLinksBlock` in puck.config.tsx.
 */

type Heading = "h1" | "h2" | "h3" | "h4";
type Network = "facebook" | "linkedin" | "bluesky" | "email";

export type ShareLinksProps = {
  heading: string;
  headingLevel: Heading;
  body: string;
  pageUrl: string;
  message: string;
  emailSubject: string;
  networks: { network: Network }[];
  showPreview: boolean;
};

const enc = encodeURIComponent;

const networkMeta: Record<Network, { label: string; path: string; external: boolean }> = {
  facebook: {
    label: "Facebook",
    external: true,
    path: "M24 12.073C24 5.405 18.627 0 12 0S0 5.405 0 12.073C0 18.1 4.388 23.094 10.125 24v-8.437H7.078v-3.49h3.047V9.413c0-3.026 1.792-4.697 4.533-4.697 1.312 0 2.686.236 2.686.236v2.97h-1.513c-1.491 0-1.956.93-1.956 1.886v2.265h3.328l-.532 3.49h-2.796V24C19.612 23.094 24 18.1 24 12.073Z",
  },
  linkedin: {
    label: "LinkedIn",
    external: true,
    path: "M20.447 20.452h-3.554v-5.569c0-1.328-.027-3.037-1.852-3.037-1.853 0-2.136 1.445-2.136 2.939v5.667H9.351V9h3.414v1.561h.046c.477-.9 1.637-1.85 3.37-1.85 3.601 0 4.267 2.37 4.267 5.455v6.286ZM5.337 7.433a2.062 2.062 0 1 1 0-4.125 2.062 2.062 0 0 1 0 4.125ZM7.119 20.452H3.555V9h3.564v11.452ZM22.225 0H1.771C.792 0 0 .774 0 1.729v20.542C0 23.227.792 24 1.771 24h20.451C23.2 24 24 23.227 24 22.271V1.729C24 .774 23.2 0 22.222 0h.003Z",
  },
  bluesky: {
    label: "Bluesky",
    external: true,
    path: "M5.202 2.857C7.954 4.922 10.913 9.11 12 11.358c1.087-2.247 4.046-6.436 6.798-8.501C20.783 1.366 24 .213 24 3.883c0 .732-.42 6.156-.667 7.037-.856 3.061-3.978 3.842-6.755 3.37 4.854.826 6.089 3.562 3.422 6.299-5.065 5.196-7.28-1.304-7.847-2.97-.104-.305-.152-.448-.153-.327 0-.121-.05.022-.153.327-.568 1.666-2.782 8.166-7.847 2.97-2.667-2.737-1.432-5.473 3.422-6.3-2.777.473-5.899-.308-6.755-3.369C.42 10.04 0 4.615 0 3.883c0-3.67 3.217-2.517 5.202-1.026Z",
  },
  email: {
    label: "Email",
    external: false,
    path: "M1.5 8.67v8.58a3 3 0 0 0 3 3h15a3 3 0 0 0 3-3V8.67l-8.928 5.493a3 3 0 0 1-3.144 0L1.5 8.67ZM22.5 6.908V6.75a3 3 0 0 0-3-3h-15a3 3 0 0 0-3 3v.158l9.714 5.978a1.5 1.5 0 0 0 1.572 0L22.5 6.908Z",
  },
};

function shareHref(network: Network, url: string, message: string, subject: string) {
  const text = [message, url].filter(Boolean).join(" ");
  switch (network) {
    case "facebook":
      return url ? `https://www.facebook.com/sharer/sharer.php?u=${enc(url)}` : "";
    case "linkedin":
      return url ? `https://www.linkedin.com/sharing/share-offsite/?url=${enc(url)}` : "";
    case "bluesky":
      return text ? `https://bsky.app/intent/compose?text=${enc(text)}` : "";
    case "email":
      return text ? `mailto:?subject=${enc(subject || message || "Thought you'd want to see this")}&body=${enc([message, url].filter(Boolean).join("\n\n"))}` : "";
  }
}

const displayUrl = (url: string) => url.replace(/^https?:\/\//, "").replace(/\/$/, "");

export const shareLinksBlock: ComponentConfig<ShareLinksProps> = {
  label: "Share Links",
  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." },
    },
    body: { type: "textarea", label: "Body" },
    pageUrl: {
      type: "text",
      label: "Page URL to share",
      metadata: { help: "The full address, starting with https://. Without JavaScript the block can't detect the current page, so paste it here. Facebook and LinkedIn are hidden until it's set." },
    },
    message: { type: "textarea", label: "Suggested message", metadata: { help: "Pre-filled for Bluesky and email. Facebook and LinkedIn only accept the link; they pull the title and image from the page itself." } },
    emailSubject: { type: "text", label: "Email subject", metadata: { help: "Leave blank to use the message." } },
    networks: {
      type: "array",
      label: "Share options",
      min: 1,
      max: 4,
      getItemSummary: (item) => (item?.network ? networkMeta[item.network as Network]?.label : "") || "Network",
      defaultItemProps: { network: "email" },
      arrayFields: {
        network: {
          type: "select",
          label: "Network",
          options: [
            { label: "Facebook", value: "facebook" },
            { label: "LinkedIn", value: "linkedin" },
            { label: "Bluesky", value: "bluesky" },
            { label: "Email", value: "email" },
          ],
        },
      },
      metadata: { help: "Add, remove or reorder. Copy-link isn't offered because it needs JavaScript." },
    },
    showPreview: {
      type: "radio",
      label: "Show message preview",
      options: [
        { label: "Yes", value: true },
        { label: "No", value: false },
      ],
      metadata: { help: "Shows people what they're about to share." },
    },
  },
  defaultProps: {
    heading: "Spread the word",
    headingLevel: "h2",
    body: "Most people find our free tax clinic through a friend. One share could put a refund back in a neighbor's pocket.",
    pageUrl: "https://example.org/free-tax-help",
    message: "Free tax prep is back at the library this spring. Trained volunteers file your return at no cost, by appointment or walk-in.",
    emailSubject: "Free tax help at the library",
    networks: [{ network: "facebook" }, { network: "linkedin" }, { network: "bluesky" }, { network: "email" }],
    showPreview: true,
  },
  render: ({ heading, headingLevel, body, pageUrl, message, emailSubject, networks, showPreview }) => {
    const H = headingLevel || "h2";
    const url = (pageUrl || "").trim();
    const msg = (message || "").trim();
    const seen = new Set<string>();
    const links = (networks ?? [])
      .map((n) => n?.network)
      .filter((n): n is Network => Boolean(n && networkMeta[n]) && !seen.has(n) && Boolean(seen.add(n)))
      .map((n) => ({ network: n, ...networkMeta[n], href: shareHref(n, url, msg, emailSubject) }))
      .filter((l) => l.href);
    const preview = showPreview !== false && (msg || url);
    if (!heading && !body && !links.length) return <></>;

    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 grid grid-cols-1 items-center gap-10 lg:gap-16 ${preview ? "max-w-5xl lg:grid-cols-2" : "max-w-2xl"}`}>
          <div>
            {heading ? <H className="text-3xl font-semibold tracking-tight text-balance text-neutral-950 sm:text-4xl">{heading}</H> : null}
            {body ? <p className="mt-4 text-lg leading-8 text-pretty text-neutral-600">{body}</p> : null}
            {links.length ? (
              <ul role="list" className="mt-8 grid grid-cols-1 gap-3 sm:grid-cols-2">
                {links.map((l) => (
                  <li key={l.network}>
                    <a
                      href={l.href}
                      {...(l.external ? { target: "_blank", rel: "noopener noreferrer" } : {})}
                      className="group flex min-h-12 items-center gap-3 rounded-xl bg-white px-4 py-3 text-base font-semibold text-neutral-950 ring-1 ring-neutral-200 transition ring-inset hover:bg-neutral-50 hover:ring-neutral-300 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600"
                    >
                      <svg aria-hidden="true" viewBox="0 0 24 24" fill="currentColor" className="size-5 shrink-0 text-neutral-700 transition group-hover:text-indigo-600">
                        <path d={l.path} />
                      </svg>
                      <span className="min-w-0 flex-1">
                        {l.network === "email" ? "Send by email" : `Share on ${l.label}`}
                        {l.external ? <span className="sr-only"> (opens in a new tab)</span> : null}
                      </span>
                      <svg aria-hidden="true" viewBox="0 0 20 20" fill="currentColor" className="size-4 shrink-0 text-neutral-400 transition group-hover:translate-x-0.5 group-hover:text-neutral-600">
                        {l.external ? (
                          <path fillRule="evenodd" d="M5.22 14.78a.75.75 0 0 0 1.06 0l7.22-7.22v5.69a.75.75 0 0 0 1.5 0v-7.5a.75.75 0 0 0-.75-.75h-7.5a.75.75 0 0 0 0 1.5h5.69l-7.22 7.22a.75.75 0 0 0 0 1.06Z" clipRule="evenodd" />
                        ) : (
                          <path fillRule="evenodd" d="M3 10a.75.75 0 0 1 .75-.75h10.64l-3.22-3.22a.75.75 0 1 1 1.06-1.06l4.5 4.5a.75.75 0 0 1 0 1.06l-4.5 4.5a.75.75 0 1 1-1.06-1.06l3.22-3.22H3.75A.75.75 0 0 1 3 10Z" clipRule="evenodd" />
                        )}
                      </svg>
                    </a>
                  </li>
                ))}
              </ul>
            ) : null}
          </div>

          {preview ? (
            <figure className="relative">
              <div aria-hidden="true" className="absolute inset-0 translate-x-2 translate-y-2 rounded-2xl bg-indigo-100 sm:translate-x-3 sm:translate-y-3" />
              <div className="relative rounded-2xl bg-white p-6 shadow-sm ring-1 ring-neutral-200 sm:p-8">
                <figcaption className="flex items-center gap-2 text-xs font-semibold tracking-wide text-neutral-600 uppercase">
                  <svg aria-hidden="true" viewBox="0 0 20 20" fill="currentColor" className="size-4 text-indigo-600">
                    <path d="M13 4.5a2.5 2.5 0 1 1 .702 1.737L6.97 9.604a2.518 2.518 0 0 1 0 .792l6.733 3.367a2.5 2.5 0 1 1-.671 1.341l-6.733-3.367a2.5 2.5 0 1 1 0-3.475l6.733-3.366A2.52 2.52 0 0 1 13 4.5Z" />
                  </svg>
                  What you&rsquo;ll share
                </figcaption>
                {msg ? <blockquote className="mt-4 text-lg leading-8 text-pretty text-neutral-900">{msg}</blockquote> : null}
                {url ? (
                  <p className={`flex items-center gap-2 text-sm font-medium break-all text-indigo-700 ${msg ? "mt-5 border-t border-neutral-200 pt-5" : "mt-4"}`}>
                    <svg aria-hidden="true" viewBox="0 0 20 20" fill="currentColor" className="size-4 shrink-0">
                      <path d="M12.232 4.232a2.5 2.5 0 0 1 3.536 3.536l-1.225 1.224a.75.75 0 0 0 1.061 1.06l1.224-1.224a4 4 0 0 0-5.656-5.656l-3 3a4 4 0 0 0 .225 5.865.75.75 0 0 0 .977-1.138 2.5 2.5 0 0 1-.142-3.667l3-3Z" />
                      <path d="M11.603 7.963a.75.75 0 0 0-.977 1.138 2.5 2.5 0 0 1 .142 3.667l-3 3a2.5 2.5 0 0 1-3.536-3.536l1.225-1.224a.75.75 0 0 0-1.061-1.06l-1.224 1.224a4 4 0 1 0 5.656 5.656l3-3a4 4 0 0 0-.225-5.865Z" />
                    </svg>
                    {displayUrl(url)}
                  </p>
                ) : null}
              </div>
            </figure>
          ) : null}
        </div>
      </section>
    );
  },
};
```
