/** * P1 Next SDK page handler — provides page components for `/p1/[[...p1]]`. * * The editor renders from `Layout`, not `Page`: Next.js keys segment cache * nodes by their param values, so everything inside `[[...p1]]` — page AND * any layout placed there — remounts when the param changes, tearing down * the whole editor (providers, auth, Puck and its canvas iframe) on every * document switch. `Layout` must therefore be mounted at a static segment, * which persists; the editor follows the URL client-side from there (see * editor-paths.ts). * * Mount that layout in an `(editor)` route group rather than directly at * `app/p1/layout.tsx`. A layout at `/p1` wraps EVERY route under it, so * sibling routes with their own pages (e.g. /p1/settings) would render the * editor on top of themselves. Scoping the layout to the group means only * the catch-all page gets the editor; siblings placed outside the group stay * editor-free by construction. Route groups add no URL segment, so /p1 and * its subpaths are unchanged. * * The catch-all is optional, so a /p1 subpath with no sibling page of its own * is not a 404 — it opens the editor on a document of that path. * * Usage: * // app/p1/(editor)/[[...p1]]/p1-pages.tsx (shared module) * import { createP1Pages } from "@pantheon-systems/p1-next-sdk/server"; * export const pages = createP1Pages({ config, EditorClient }); * * // app/p1/(editor)/layout.tsx <- static segment scoped to the group * export default pages.Layout; * * // app/p1/(editor)/[[...p1]]/page.tsx * export default pages.Page; * export const generateMetadata = pages.generateMetadata; * export const dynamic = "force-dynamic"; * * // app/p1/settings/page.tsx <- sibling OUTSIDE the group, no editor * * The editor must be mounted at `/p1`: the client derives the edited page * from the URL via editorPagePathFromUrlPath, whose basePath defaults to * "/p1". A different mount point needs that basePath passed through in the * EditorClient implementation, or every URL falls back to the root page. */ import type { Config } from "@puckeditor/core"; import type { Metadata } from "next"; import { type P1DataConfig } from "@pantheon-systems/puck-css/server"; export type P1PagesConfig = P1DataConfig & { config: Config; /** * React component to render the editor. Rendered from the persistent * layout with no props — it derives the page path from the URL (see * editorPagePathFromUrlPath) and handles its own data loading and auth * via P1App. */ EditorClient: React.ComponentType; }; export declare function createP1Pages(opts: P1PagesConfig): { Page: () => null; Layout: ({ children }: { children: React.ReactNode; }) => Promise; generateMetadata: ({ params, }: { params: Promise<{ p1?: string[]; }>; }) => Promise; };