@justanarthur/payload-www 0.3.4 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. package/README.md +317 -307
  2. package/dist/access.d.ts +2 -2
  3. package/dist/access.js +6 -30
  4. package/dist/blocks.d.ts +0 -10
  5. package/dist/blocks.js +8 -33
  6. package/dist/collections.d.ts +33 -225
  7. package/dist/collections.js +186 -661
  8. package/dist/config.d.ts +19 -105
  9. package/dist/config.js +263 -868
  10. package/dist/fields.d.ts +4 -46
  11. package/dist/fields.js +183 -73
  12. package/dist/imagehash.js +0 -15
  13. package/dist/import-map-provider.d.ts +0 -16
  14. package/dist/import-map-provider.js +0 -15
  15. package/dist/metadata.d.ts +24 -89
  16. package/dist/metadata.js +123 -258
  17. package/dist/pages.d.ts +37 -319
  18. package/dist/pages.js +355 -973
  19. package/dist/render-pages.d.ts +69 -564
  20. package/dist/render-pages.js +476 -1502
  21. package/dist/sitemap.d.ts +10 -0
  22. package/dist/sitemap.js +324 -0
  23. package/dist/translator.js +0 -15
  24. package/dist/utils.d.ts +4 -12
  25. package/dist/utils.js +10 -56
  26. package/package.json +75 -178
  27. package/dist/components.d.ts +0 -6
  28. package/dist/components.js +0 -39
  29. package/dist/core-access.d.ts +0 -11
  30. package/dist/core-access.js +0 -44
  31. package/dist/core-blocks.d.ts +0 -24
  32. package/dist/core-blocks.js +0 -89
  33. package/dist/core-fields.d.ts +0 -73
  34. package/dist/core-fields.js +0 -181
  35. package/dist/core-utils.d.ts +0 -16
  36. package/dist/core-utils.js +0 -73
  37. package/dist/data-collections.d.ts +0 -229
  38. package/dist/data-collections.js +0 -697
  39. package/dist/data-seed.d.ts +0 -76
  40. package/dist/data-seed.js +0 -212
  41. package/dist/data-test.d.ts +0 -30
  42. package/dist/data-test.js +0 -1134
  43. package/dist/globals.d.ts +0 -69
  44. package/dist/globals.js +0 -259
  45. package/dist/hooks.d.ts +0 -108
  46. package/dist/hooks.js +0 -228
  47. package/dist/index.d.ts +0 -6
  48. package/dist/index.js +0 -39
  49. package/dist/render-components.d.ts +0 -42
  50. package/dist/render-components.js +0 -154
  51. package/dist/render-metadata.d.ts +0 -122
  52. package/dist/render-metadata.js +0 -393
  53. package/dist/render-utils.d.ts +0 -166
  54. package/dist/render-utils.js +0 -401
  55. package/dist/seed.d.ts +0 -76
  56. package/dist/seed.js +0 -212
  57. package/dist/server.d.ts +0 -980
  58. package/dist/server.js +0 -2265
  59. package/dist/test.d.ts +0 -30
  60. package/dist/test.js +0 -1134
  61. package/dist/with-www-config.d.ts +0 -108
  62. package/dist/with-www-config.js +0 -1030
package/dist/pages.d.ts CHANGED
@@ -1,336 +1,54 @@
1
1
  import { ReactElement } from "react";
2
- import { SanitizedConfig } from "payload";
3
- type PagesPageProps = {
4
- /**
5
- * The resolved page document. The host's `[slug]/page.tsx` route
6
- * handler is responsible for fetching the doc (via Payload's
7
- * `getPayload` or via the lib's `createCollectionPageExports`'s
8
- * `generateMetadata` helper). This component just renders the
9
- * visual body.
10
- */
11
- doc: Record<string, any> | null;
12
- /**
13
- * Resolved locale string (already validated upstream by the host's
14
- * `[locale]` route segment).
15
- */
16
- locale: string;
17
- /**
18
- * Block components keyed by `blockType`. The host passes the same
19
- * `importMap` it uses everywhere else; the lib's `RenderBlocks`
20
- * resolves each block against the map.
21
- */
22
- importMap: Record<string, unknown>;
2
+ import { ImportMap, SanitizedConfig } from "payload";
3
+ type RenderedWWWModule<Data = any> = {
23
4
  config: SanitizedConfig;
24
- };
25
- /**
26
- * Default visual body for the Pages collection. Renders the doc's
27
- * `blocks` field via the lib's `RenderBlocks`. Hosts can replace
28
- * this by setting a different `custom.path` on their own Pages
29
- * collection (via the lib's `createPagesCollection` factory) and
30
- * pointing it at their own Server Component.
31
- */
32
- declare function PagesPage({ doc,...props }: PagesPageProps): Promise<ReactElement>;
5
+ importMap: ImportMap;
6
+ data: Data;
7
+ } & Record<string, any>;
8
+ declare function FooterPage({ data }: RenderedWWWModule): ReactElement;
33
9
  import { ReactElement as ReactElement2 } from "react";
34
- type HeaderPageProps = {
35
- /** The resolved Header global document. `null` if the host hasn't
36
- * created a Header yet. */
37
- data: Record<string, any> | null;
38
- /**
39
- * Resolved locale string. The default header visual uses this for
40
- * per-locale labels via next-intl (if the host has it wired). The
41
- * default ships without a label dictionary — the host can override
42
- * by setting a different `custom.path` on the header global.
43
- */
44
- locale: string;
45
- };
46
- /**
47
- * Default visual for the `header` global. Renders the header's
48
- * `nav` blocks (a flat list of `navItem` and `navColumn` blocks) as
49
- * a simple `<nav>` element.
50
- *
51
- * Hosts can replace this visual by setting a different `custom.path`
52
- * on their own header global (via the lib's `createHeaderGlobal`
53
- * factory).
54
- */
55
- declare function HeaderPage({ data, locale: _locale }: HeaderPageProps): ReactElement2;
10
+ declare function HeaderPage({ data }: RenderedWWWModule): ReactElement2;
56
11
  import { ReactElement as ReactElement3 } from "react";
57
- type FooterPageProps = {
58
- /** The resolved Footer global document. `null` if the host hasn't
59
- * created a Footer yet. */
60
- data: Record<string, any> | null;
61
- locale: string;
62
- };
63
- /**
64
- * Default visual for the `footer` global. Renders the footer's
65
- * `nav` blocks (a flat list of `navItem` and `navColumn` blocks)
66
- * as a simple `<footer>` element.
67
- *
68
- * Hosts can replace this visual by setting a different `custom.path`
69
- * on their own footer global (via the lib's `createFooterGlobal`
70
- * factory).
71
- */
72
- declare function FooterPage({ data, locale: _locale }: FooterPageProps): ReactElement3;
12
+ declare function PagesPage({ data, locale,...props }: RenderedWWWModule): Promise<ReactElement3>;
73
13
  import { Metadata, MetadataRoute } from "next";
74
- import { DataFromCollectionSlug, ImportMap, SanitizedConfig as SanitizedConfig2 } from "payload";
75
- import { ReactElement as ReactElement4, ReactNode } from "react";
76
- type BreadcrumbItem = {
77
- label: string;
78
- url: string;
79
- };
80
- type PageExtendProps = {
81
- importMap: ImportMap;
82
- config: SanitizedConfig2;
83
- locale: string;
84
- };
85
- type ArticleJsonLdEntry = {
86
- type: "article";
87
- id?: string;
88
- schemaType?: "BlogPosting" | "Article" | "NewsArticle" | "TechArticle";
89
- publisherName?: string;
90
- publisherLogo?: string | null;
91
- };
92
- type WebSiteJsonLdEntry = {
93
- type: "website";
94
- id?: string;
95
- name?: string;
96
- alternateName?: string;
97
- };
98
- type OrganizationJsonLdEntry = {
99
- type: "organization";
100
- id?: string;
101
- name?: string;
102
- logo?: string;
103
- sameAs?: string[];
104
- };
105
- type BreadcrumbsJsonLdEntry = {
106
- type: "breadcrumbs";
107
- id?: string;
108
- items?: BreadcrumbItem[];
109
- buildItems?: (doc: DataFromCollectionSlug<string>, url: string) => BreadcrumbItem[];
110
- };
111
- type CustomJsonLdEntry = {
112
- type: "custom";
113
- id?: string;
114
- build: (ctx: {
115
- doc: DataFromCollectionSlug<string>;
116
- url: string;
14
+ import { ImportMap as ImportMap2, SanitizedConfig as SanitizedConfig2 } from "payload";
15
+ import { ReactNode as ReactNode2 } from "react";
16
+ type SlugShape = "single" | "catch-all";
17
+ type NextPageProps = {
18
+ params: Promise<{
117
19
  locale: string;
118
- siteUrl: string;
119
- }) => Record<string, unknown>;
120
- };
121
- type JsonLdEntry = ArticleJsonLdEntry | WebSiteJsonLdEntry | OrganizationJsonLdEntry | BreadcrumbsJsonLdEntry | CustomJsonLdEntry;
122
- type JsonLdOutput = {
123
- id: string;
124
- schema: Record<string, unknown>;
125
- };
126
- /**
127
- * Minimal next-intl routing contract the lib reads. Hosts pass
128
- * their `defineRouting({...})` result directly; the lib only needs
129
- * the shape below.
130
- *
131
- * `localePrefix` accepts either the simple string form
132
- * (`'always' | 'as-needed' | 'never'`) or next-intl's verbose
133
- * `LocalePrefixConfigVerbose` shape (`{ mode, prefixes? }`). The lib
134
- * normalizes both to a string `mode` internally.
135
- */
136
- type LocalePrefixValue = "always" | "as-needed" | "never" | {
137
- mode?: "always" | "as-needed" | "never";
138
- };
139
- type PageRouting = {
140
- locales: readonly string[];
141
- defaultLocale: string;
142
- localePrefix?: LocalePrefixValue;
143
- /** Optional human-readable labels per locale (used by the
144
- * `<LocaleSwitcher>`). Falls back to the locale code when missing.
145
- * Not part of next-intl's `defineRouting` shape — the host extends
146
- * its routing object to include it (e.g. via a type assertion). */
147
- labels?: Record<string, string>;
148
- };
149
- type MetadataOptions = {
150
- urlPrefix?: string;
151
- /** When true (default), the lib generates a `{type:'website'}` JSON-LD
152
- * entry per page. Pass an array to specify entries; pass `false` to
153
- * skip. */
154
- jsonLd?: boolean | JsonLdEntry[];
155
- changefreq?: MetadataRoute.Sitemap[number]["changeFrequency"];
156
- priority?: number;
157
- /**
158
- * Override the default `'website'` JSON-LD's `name` field. Only
159
- * relevant when `jsonLd !== false` and no `name` is set on the
160
- * auto-generated entry.
161
- */
162
- websiteName?: string;
163
- };
164
- type ShowcaseOptions = {
165
- /**
166
- * Wrap the rendered page in a two-column layout with a sidebar
167
- * that surfaces the page's metadata, JSON-LD, and a language
168
- * switcher. Hosts that want a clean render (no sidebar) leave
169
- * this `false` (the default). The demo's home page enables it
170
- * so visitors can see every artifact the lib generates in one
171
- * place.
172
- */
173
- enabled?: boolean;
174
- /** Heading shown above the metadata block. Default: `'Page metadata'`. */
175
- metadataHeading?: string;
176
- /** Heading shown above the JSON-LD block. Default: `'JSON-LD'`. */
177
- jsonLdHeading?: string;
20
+ slug?: string | string[];
21
+ }>;
178
22
  };
23
+ import { RoutingConfig as GenericRoutingConfig } from "next-intl/routing";
24
+ type RoutingConfig = GenericRoutingConfig<string[], any, any, any>;
179
25
  type CreateCollectionPageExportsArgs<S extends string = "pages"> = {
180
- config: Promise<SanitizedConfig2>;
181
- /**
182
- * Defaults to `'pages'`. The collection slug whose documents the
183
- * page route renders.
184
- */
185
26
  slug?: S;
186
- /**
187
- * The next-intl `defineRouting({...})` result from the host's
188
- * `i18n/routing.ts`. Drives locale validation, URL building,
189
- * hreflang alternates, and the language switcher.
190
- */
191
- routing: PageRouting;
192
- /**
193
- * The host's Payload importMap. The lib uses this to resolve
194
- * the collection's `custom.path` (the page renderer module) and
195
- * the live-preview listener. Pass `import { importMap } from
196
- * '@/app/(payload)/admin/importMap.js'` from the host's page
197
- * file. Default: `{}` — the page renders without a live-preview
198
- * listener and uses the lib's registered `custom.path` for the
199
- * collection renderer (which requires its key to be in the
200
- * supplied importMap).
201
- */
202
- importMap?: ImportMap;
203
- /**
204
- * Optional custom path pointing at the host's render module for
205
- * the collection. Overrides the lib's registered `custom.path`
206
- * (which defaults to `PAGES_RENDER_PATH`). Use this when you've
207
- * defined your own Server Component for the collection.
208
- */
209
- renderPath?: string;
210
- /**
211
- * Enable nested (hierarchical) slugs. When `true`, the catch-all
212
- * `[...slug]` segments are joined with the `_` divider to form the
213
- * stored slug (URL `/about/us` ⇄ stored `about_us`), URL paths and
214
- * hreflang alternates are expanded back to `/about/us`, and
215
- * `generateStaticParams` emits multi-segment params. When `false`
216
- * (the default) only the first URL segment is used — flat slugs.
217
- *
218
- * Pair with `createPagesCollection({ nested: true })` (or
219
- * `createWWWConfig({ nested: true })`) so the collection's slug
220
- * validation accepts the `_` divider.
221
- */
222
- nested?: boolean;
27
+ config: Promise<SanitizedConfig2>;
28
+ importMap: ImportMap2;
29
+ routing: RoutingConfig;
30
+ slugShape?: SlugShape;
223
31
  };
224
32
  type CreateCollectionPageExportsDeps<S extends string> = {
225
- /**
226
- * Host's `getServerSideURL()` (returns the absolute site URL).
227
- */
228
33
  getServerSideURL: () => string;
229
- /**
230
- * Host's `generateMeta({ doc, url, type, locale })` (returns Next.js
231
- * `Metadata`). The `doc` is the host's typed collection document
232
- * (e.g. `Post` for the posts collection, `Page` for pages) with
233
- * localized fields already resolved for the active locale. Read
234
- * `doc.title` directly as a string — no locale-lookup needed.
235
- */
236
- generateMeta: (args: {
237
- doc: DataFromCollectionSlug<S> | null;
238
- url: string;
239
- type: "website" | "article";
240
- locale: string;
241
- }) => Promise<Metadata>;
242
- /**
243
- * Override the metadata type passed to `generateMeta` and the
244
- * JSON-LD entry default. Defaults to `'article'` for the
245
- * `posts` collection, `'website'` everywhere else. Hosts that
246
- * want to opt out (e.g. treat a Post like a WebPage) pass
247
- * `'website'` explicitly here.
248
- */
249
- metadataType?: "website" | "article";
250
- /**
251
- * Optional showcase configuration. When `enabled: true`, the
252
- * default page renders inside a `<PageShowcase>` sidebar that
253
- * surfaces the page's metadata, JSON-LD, and a language
254
- * switcher — useful for demos and CMS previews. Default: off.
255
- */
256
- showcase?: ShowcaseOptions;
257
- /**
258
- * Optional content injected after the rendered doc body when the
259
- * page is the home route (slug = `''`). The lib calls the
260
- * function with the resolved locale and the current doc (or
261
- * `null` if no home doc exists). Hosts that want the home to
262
- * surface additional content — recent pages, recent posts,
263
- * navigation — pass a function here. The return value is
264
- * rendered as a sibling of the lib's doc body inside the page
265
- * (and inside the showcase's main column when showcase is on).
266
- */
267
- homeExtras?: (args: {
268
- locale: string;
269
- doc: DataFromCollectionSlug<S> | null;
270
- }) => ReactNode | Promise<ReactNode>;
271
- };
272
- /**
273
- * Build a Pages (or any collection) page route's exports:
274
- * `default` (the Page Server Component), `generateMetadata`,
275
- * `generateStaticParams`, and `generateSitemap`.
276
- *
277
- * Designed for a next-intl layout: the page lives at
278
- * `app/(frontend)/[locale]/[...slug]/page.tsx`. The catch-all slug
279
- * handles both the home route (slug=[]) and any other doc. The lib
280
- * reads `params.locale` and `params.slug` (string[]), validates
281
- * the locale against `routing.locales`, fetches the doc, generates
282
- * metadata + JSON-LD + hreflang alternates, and renders the
283
- * resolved output.
284
- *
285
- * The host's `next-intl/routing` config is the single source of
286
- * truth for the locale list and URL shape.
287
- *
288
- * // app/(frontend)/[locale]/[...slug]/page.tsx
289
- * import { routing } from '@/i18n/routing'
290
- * import { createCollectionPageExports } from '@justanarthur/payload-www/render-pages'
291
- *
292
- * const { default: Page, generateMetadata, generateStaticParams } =
293
- * createCollectionPageExports(
294
- * { config: configPromise, routing },
295
- * { getServerSideURL, generateMeta, showcase: { enabled: true } }
296
- * )
297
- *
298
- * { generateMetadata, generateStaticParams }
299
- * Page
300
- */
301
- declare function createCollectionPageExports<S extends string = "pages">({ slug, config: configPromise, routing, importMap: importMapArg, renderPath, nested }: CreateCollectionPageExportsArgs<S>, deps: CreateCollectionPageExportsDeps<S>, options?: MetadataOptions): {
302
- default: (props: {
303
- params: Promise<{
304
- locale?: string;
305
- slug?: string[];
306
- }>;
307
- searchParams?: Promise<Record<string, string | string[] | undefined>>;
308
- }) => Promise<ReactElement4>;
309
- generateMetadata: (props: {
310
- params: Promise<{
311
- locale?: string;
312
- slug?: string[];
313
- }>;
314
- }) => Promise<Metadata>;
315
- generateStaticParams: () => Promise<Array<{
316
- slug?: string[];
317
- locale: string;
318
- }>>;
319
- generateSitemap: () => Promise<MetadataRoute.Sitemap>;
320
- generateJsonLd: (slugSegments: string[], doc: DataFromCollectionSlug<S>, locale: string) => Promise<JsonLdOutput[]>;
321
- };
322
- declare function addCollectionsToSitemap(exports: Array<{
323
- default: () => Promise<MetadataRoute.Sitemap>;
324
- generateSitemap: () => Promise<MetadataRoute.Sitemap>;
325
- }>): {
326
- default: () => Promise<MetadataRoute.Sitemap>;
327
- generateSitemap: () => Promise<MetadataRoute.Sitemap>;
328
- };
329
- declare const _default: {
34
+ pagePathPrefix?: string;
35
+ };
36
+ declare function createCollectionPageExports<S extends string = "pages">({ slug: collectionSlug, config: configPromise, importMap, routing, slugShape }: CreateCollectionPageExportsArgs<S>, { getServerSideURL, pagePathPrefix }: CreateCollectionPageExportsDeps<S>): {
37
+ default: (props: NextPageProps) => Promise<ReactNode2>;
38
+ generateMetadata: (props: NextPageProps) => Promise<Metadata>;
39
+ generateStaticParams: (props: NextPageProps) => Promise<{
40
+ slug: string | string[];
41
+ }[]>;
42
+ generateSitemap: {
43
+ (): Promise<MetadataRoute.Sitemap>;
44
+ getServerSideURL: () => string;
45
+ pagePathPrefix: string | undefined;
46
+ };
47
+ };
48
+ declare const pages: {
330
49
  createCollectionPageExports: typeof createCollectionPageExports;
331
- addCollectionsToSitemap: typeof addCollectionsToSitemap;
332
50
  PagesPage: typeof PagesPage;
333
51
  HeaderPage: typeof HeaderPage;
334
52
  FooterPage: typeof FooterPage;
335
53
  };
336
- export { _default as default, createCollectionPageExports, addCollectionsToSitemap, PagesPage, PageExtendProps, MetadataOptions, JsonLdOutput, JsonLdEntry, HeaderPage, FooterPage, CreateCollectionPageExportsDeps, CreateCollectionPageExportsArgs };
54
+ export { pages as default, createCollectionPageExports, PagesPage, HeaderPage, FooterPage, CreateCollectionPageExportsDeps, CreateCollectionPageExportsArgs };