@justanarthur/payload-www 0.3.5 → 1.2.0

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 (63) hide show
  1. package/README.md +317 -307
  2. package/dist/access.d.ts +2 -2
  3. package/dist/access.js +3 -17
  4. package/dist/blocks.d.ts +7 -12
  5. package/dist/blocks.js +24 -43
  6. package/dist/cli.js +201 -0
  7. package/dist/collections.d.ts +33 -225
  8. package/dist/collections.js +185 -639
  9. package/dist/config.d.ts +19 -105
  10. package/dist/config.js +257 -855
  11. package/dist/fields.d.ts +4 -46
  12. package/dist/fields.js +177 -53
  13. package/dist/imagehash.js +0 -15
  14. package/dist/import-map-provider.d.ts +0 -16
  15. package/dist/import-map-provider.js +0 -15
  16. package/dist/metadata.d.ts +24 -89
  17. package/dist/metadata.js +123 -255
  18. package/dist/pages.d.ts +37 -319
  19. package/dist/pages.js +349 -964
  20. package/dist/render-pages.d.ts +70 -565
  21. package/dist/render-pages.js +464 -1477
  22. package/dist/sitemap.d.ts +10 -0
  23. package/dist/sitemap.js +337 -0
  24. package/dist/translator.js +0 -15
  25. package/dist/utils.d.ts +10 -12
  26. package/dist/utils.js +18 -41
  27. package/package.json +81 -178
  28. package/dist/components.d.ts +0 -6
  29. package/dist/components.js +0 -39
  30. package/dist/core-access.d.ts +0 -11
  31. package/dist/core-access.js +0 -34
  32. package/dist/core-blocks.d.ts +0 -24
  33. package/dist/core-blocks.js +0 -79
  34. package/dist/core-fields.d.ts +0 -73
  35. package/dist/core-fields.js +0 -167
  36. package/dist/core-utils.d.ts +0 -16
  37. package/dist/core-utils.js +0 -63
  38. package/dist/data-collections.d.ts +0 -229
  39. package/dist/data-collections.js +0 -676
  40. package/dist/data-seed.d.ts +0 -76
  41. package/dist/data-seed.js +0 -212
  42. package/dist/data-test.d.ts +0 -30
  43. package/dist/data-test.js +0 -1110
  44. package/dist/globals.d.ts +0 -69
  45. package/dist/globals.js +0 -251
  46. package/dist/hooks.d.ts +0 -108
  47. package/dist/hooks.js +0 -228
  48. package/dist/index.d.ts +0 -6
  49. package/dist/index.js +0 -39
  50. package/dist/render-components.d.ts +0 -42
  51. package/dist/render-components.js +0 -154
  52. package/dist/render-metadata.d.ts +0 -122
  53. package/dist/render-metadata.js +0 -390
  54. package/dist/render-utils.d.ts +0 -166
  55. package/dist/render-utils.js +0 -398
  56. package/dist/seed.d.ts +0 -76
  57. package/dist/seed.js +0 -212
  58. package/dist/server.d.ts +0 -980
  59. package/dist/server.js +0 -2231
  60. package/dist/test.d.ts +0 -30
  61. package/dist/test.js +0 -1110
  62. package/dist/with-www-config.d.ts +0 -108
  63. package/dist/with-www-config.js +0 -1006
@@ -1,167 +0,0 @@
1
-
2
- var __defProp = Object.defineProperty;
3
- var __returnValue = (v) => v;
4
- function __exportSetter(name, newValue) {
5
- this[name] = __returnValue.bind(null, newValue);
6
- }
7
- var __export = (target, all) => {
8
- for (var name in all)
9
- __defProp(target, name, {
10
- get: all[name],
11
- enumerable: true,
12
- configurable: true,
13
- set: __exportSetter.bind(all, name)
14
- });
15
- };
16
- var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
17
-
18
- // src/config/constants.ts
19
- var PAGES_RENDER_PATH = "@justanarthur/payload-www/render-pages#PagesPage";
20
- var POSTS_RENDER_PATH = "@justanarthur/payload-www/render-pages#PostsPage";
21
- var HEADER_RENDER_PATH = "@justanarthur/payload-www/render-pages#HeaderPage";
22
- var FOOTER_RENDER_PATH = "@justanarthur/payload-www/render-pages#FooterPage";
23
- var LIVE_PREVIEW_LISTENER_PATH = "@justanarthur/payload-www/render-components#LivePreviewListener";
24
- var PAGES_SLUG = "pages";
25
- var POSTS_SLUG = "posts";
26
- var STATIC_PAGES_SLUG = "staticPages";
27
-
28
- // src/core/fields/link.ts
29
- var appearanceOptions = {
30
- default: { label: "Default", value: "default" },
31
- outline: { label: "Outline", value: "outline" }
32
- };
33
- var link = (options = {}) => {
34
- const {
35
- appearances,
36
- disableLabel = false,
37
- relationTo = [PAGES_SLUG],
38
- localized = false,
39
- overrides = {},
40
- extraFields = []
41
- } = options;
42
- const result = {
43
- name: "link",
44
- type: "group",
45
- admin: { hideGutter: true },
46
- fields: [
47
- {
48
- type: "row",
49
- fields: [
50
- {
51
- name: "type",
52
- type: "radio",
53
- admin: { layout: "horizontal", width: "50%" },
54
- defaultValue: "reference",
55
- options: [
56
- { label: "Internal link", value: "reference" },
57
- { label: "Custom URL", value: "custom" }
58
- ]
59
- },
60
- {
61
- name: "newTab",
62
- type: "checkbox",
63
- admin: { style: { alignSelf: "flex-end" }, width: "50%" },
64
- label: "Open in new tab"
65
- }
66
- ]
67
- }
68
- ]
69
- };
70
- const linkTypes = [
71
- {
72
- name: "reference",
73
- type: "relationship",
74
- admin: { condition: (_, siblingData) => siblingData?.type === "reference" },
75
- label: "Document to link to",
76
- relationTo,
77
- required: true,
78
- localized
79
- },
80
- {
81
- name: "url",
82
- type: "text",
83
- admin: { condition: (_, siblingData) => siblingData?.type === "custom" },
84
- label: "Custom URL",
85
- required: true,
86
- localized
87
- }
88
- ];
89
- if (!disableLabel) {
90
- result.fields.push({
91
- type: "row",
92
- fields: [
93
- ...linkTypes,
94
- {
95
- name: "label",
96
- type: "text",
97
- admin: { width: "50%" },
98
- label: "Label",
99
- required: true,
100
- localized
101
- }
102
- ]
103
- });
104
- } else {
105
- result.fields = [...result.fields, ...linkTypes];
106
- }
107
- if (appearances !== false) {
108
- const opts = appearances ? appearances.map((a) => appearanceOptions[a]) : [appearanceOptions.default, appearanceOptions.outline];
109
- result.fields.push({
110
- name: "appearance",
111
- type: "select",
112
- admin: { description: "Choose how the link should be rendered." },
113
- defaultValue: "default",
114
- options: opts
115
- });
116
- }
117
- if (extraFields.length) {
118
- result.fields.push(...extraFields);
119
- }
120
- return { ...result, ...overrides };
121
- };
122
-
123
- // src/core/fields/linkGroup.ts
124
- var linkGroup = (options = {}) => ({
125
- name: "links",
126
- type: "array",
127
- fields: [link(options)],
128
- admin: { initCollapsed: true }
129
- });
130
-
131
- // src/core/fields/slug.ts
132
- var FLAT_PATTERN = /^[a-z0-9-]+$/;
133
- var NESTED_PATTERN = /^[a-z0-9_-]+$/;
134
- var slugField = (options = {}) => {
135
- const { name = "slug", nested = false, localized = true } = options;
136
- const pattern = nested ? NESTED_PATTERN : FLAT_PATTERN;
137
- const invalidMessage = nested ? "Slug must be lowercase, with hyphens or the `_` nesting divider (no spaces or other special characters)" : "Slug must be lowercase, with hyphens (no spaces or special characters)";
138
- return {
139
- name,
140
- type: "text",
141
- required: true,
142
- unique: true,
143
- index: true,
144
- localized,
145
- admin: {
146
- position: "sidebar",
147
- ...nested ? { description: "Lowercase, hyphens for words. Use the `_` divider for nesting, e.g. `about_us` → `/about/us`." } : {}
148
- },
149
- validate: (value) => {
150
- if (typeof value !== "string")
151
- return "Slug must be a string";
152
- if (value !== "" && !pattern.test(value))
153
- return invalidMessage;
154
- return true;
155
- }
156
- };
157
- };
158
-
159
- // src/exports/core-fields.ts
160
- var core_fields_default = { link, linkGroup, appearanceOptions, slugField };
161
- export {
162
- slugField,
163
- linkGroup,
164
- link,
165
- core_fields_default as default,
166
- appearanceOptions
167
- };
@@ -1,16 +0,0 @@
1
- import { ImportMap } from "payload";
2
- declare function getFromImportMap(key: string, importMap: ImportMap): any;
3
- declare function generateImportName(type: "block" | "page", slug: string): string;
4
- import { ImportMap as ImportMap2 } from "payload";
5
- import { JSX as JSX_1kxb } from "react/jsx-runtime";
6
- type Element_12xgc = JSX_1kxb["Element"];
7
- declare function renderCollectionModule(collection: {
8
- slug: string;
9
- custom?: Record<string, any>;
10
- }[] | undefined, slug: string, importMap: ImportMap2, props?: Record<string, any>): Element_12xgc | null;
11
- declare const _default: {
12
- getFromImportMap: typeof getFromImportMap;
13
- generateImportName: typeof generateImportName;
14
- renderCollectionModule: typeof renderCollectionModule;
15
- };
16
- export { renderCollectionModule, getFromImportMap, generateImportName, _default as default };
@@ -1,63 +0,0 @@
1
-
2
- var __defProp = Object.defineProperty;
3
- var __returnValue = (v) => v;
4
- function __exportSetter(name, newValue) {
5
- this[name] = __returnValue.bind(null, newValue);
6
- }
7
- var __export = (target, all) => {
8
- for (var name in all)
9
- __defProp(target, name, {
10
- get: all[name],
11
- enumerable: true,
12
- configurable: true,
13
- set: __exportSetter.bind(all, name)
14
- });
15
- };
16
- var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
17
-
18
- // src/core/utils/getFromImportMap.ts
19
- function getFromImportMap(key, importMap) {
20
- return importMap[key.includes("#") ? key : key + "#default"];
21
- }
22
-
23
- // src/core/utils/generateImportName.ts
24
- function generateImportName(type, slug) {
25
- switch (type) {
26
- case "block":
27
- return `Block${slug.replace(/(^\w|-\w)/g, (m) => m.replace("-", "").toUpperCase())}#default`;
28
- case "page":
29
- return `Page${slug.replace(/(^\w|-\w)/g, (m) => m.replace("-", "").toUpperCase())}#default`;
30
- default:
31
- throw new Error(`Unknown type: ${type}`);
32
- }
33
- }
34
-
35
- // src/render/utils/renderCollectionModule.tsx
36
- import { jsx } from "react/jsx-runtime";
37
- function renderCollectionModule(collection = [], slug, importMap, props) {
38
- const renderPath = collection?.find((c) => c.slug === slug)?.custom?.path;
39
- if (!renderPath) {
40
- console.log("[WWW] render/utils:renderCollectionModule no custom.path slug=", slug);
41
- return null;
42
- }
43
- const CollectionRenderModule = getFromImportMap(renderPath, importMap);
44
- if (!CollectionRenderModule) {
45
- console.error("[WWW] render/utils:renderCollectionModule not found slug=", slug, "path=", renderPath);
46
- if (false) {}
47
- return null;
48
- }
49
- console.log("[WWW] render/utils:renderCollectionModule rendering slug=", slug, "path=", renderPath);
50
- return /* @__PURE__ */ jsx(CollectionRenderModule, {
51
- importMap,
52
- ...props
53
- });
54
- }
55
-
56
- // src/exports/core-utils.ts
57
- var core_utils_default = { getFromImportMap, generateImportName, renderCollectionModule };
58
- export {
59
- renderCollectionModule,
60
- getFromImportMap,
61
- generateImportName,
62
- core_utils_default as default
63
- };
@@ -1,229 +0,0 @@
1
- import { Block, CollectionConfig } from "payload";
2
- type LocalePrefixMode = "always" | "as-needed" | "never";
3
- type CreateRevalidateCollectionHookOptions = {
4
- /**
5
- * The collection's slug. Used in the per-collection tag fired
6
- * alongside path invalidation: `collection_<slug>_<id>`.
7
- */
8
- collectionSlug: string;
9
- /**
10
- * URL path prefix for this collection's rendered URLs. Pages use
11
- * `''` (mounted at root); Posts use `'/posts'`. Leading slash,
12
- * no trailing slash — same convention as
13
- * `createSitemapFile.urlPrefixes`.
14
- */
15
- urlPathPrefix?: string;
16
- /**
17
- * Sitemap tag the collection's revalidation hook invalidates on
18
- * every save. Defaults to `${collectionSlug}-sitemap`. Pass
19
- * `false` to opt out (collections without a sitemap handler).
20
- */
21
- sitemapTag?: string | false;
22
- /**
23
- * Locale prefix mode — mirrors next-intl's `localePrefix`.
24
- * Defaults to `'always'` (preserves legacy behavior).
25
- */
26
- localePrefix?: LocalePrefixMode;
27
- /**
28
- * Default locale for `localePrefix: 'as-needed'`. Falls back to
29
- * `req.payload.config.localization.defaultLocale` at request time
30
- * when omitted.
31
- */
32
- defaultLocale?: string;
33
- /**
34
- * Path invalidation strategy. Default: `'url'` — fans out
35
- * `revalidatePath` for every locale × every slug. Set to
36
- * `'tag-only'` for collections without a URL (e.g. `staticPages`
37
- * — addressed by a `kind` discriminator, not a slug). Tag-only
38
- * mode still fires the per-collection tag (via `sitemapTag`) and
39
- * the per-id tag (`collection_<slug>_<id>`).
40
- */
41
- pathMode?: "url" | "tag-only";
42
- };
43
- declare const HOME_PAGE_SLUG = "";
44
- declare const PAGES_SLUG = "pages";
45
- type CreatePagesCollectionOptions = {
46
- /**
47
- * Blocks the Pages collection accepts.
48
- */
49
- blocks: Block[];
50
- /**
51
- * Optional override for the collection slug. Default: `'pages'`.
52
- * Hosts that want a different slug (e.g. `'site_pages'`) pass
53
- * it here. The lib's Header / Footer `linkRelationTo` default
54
- * uses `'pages'` — combine this with a matching
55
- * `linkRelationTo` to keep nav links targeting the right
56
- * collection.
57
- */
58
- slug?: string;
59
- /**
60
- * Optional override for the `custom.path` Payload uses to resolve
61
- * the page's render module. Default: the lib's `PAGES_RENDER_PATH`
62
- * (a Server Component that calls `RenderBlocks`). Use this when
63
- * you've defined your own Server Component for the collection.
64
- */
65
- renderPath?: string;
66
- /**
67
- * Locale prefix mode for path invalidation. Defaults to `'always'`
68
- * (preserves current behavior). Set to `'as-needed'` when the host
69
- * uses next-intl `localePrefix: 'as-needed'` — otherwise the hook
70
- * invalidates paths the public routes don't use.
71
- */
72
- localePrefix?: CreateRevalidateCollectionHookOptions["localePrefix"];
73
- /**
74
- * Default locale for prefix skipping. Falls back to
75
- * `req.payload.config.localization.defaultLocale` at request time
76
- * when omitted.
77
- */
78
- defaultLocale?: CreateRevalidateCollectionHookOptions["defaultLocale"];
79
- /**
80
- * Enable nested (hierarchical) slugs. When `true`, the slug field
81
- * additionally accepts the `_` nesting divider (so `about_us`
82
- * renders at `/about/us`) and the admin description documents the
83
- * convention. Pair with `createCollectionPageExports({ nested: true })`
84
- * on the matching route. Default: `false` (flat, hyphen-only slugs).
85
- */
86
- nested?: boolean;
87
- };
88
- declare const createPagesCollection: (blocks: Block[], options?: Omit<CreatePagesCollectionOptions, "blocks">) => CollectionConfig;
89
- import { CollectionConfig as CollectionConfig2 } from "payload";
90
- declare const POSTS_SLUG = "posts";
91
- type CreatePostsCollectionOptions = {
92
- /**
93
- * Optional override for the collection slug. Default: `'posts'`.
94
- * Hosts that want a different slug (e.g. `'articles'` or `'blog'`)
95
- * pass it here. Combine with the page route's URL convention and
96
- * the lib's translator plugin's `collections` list.
97
- */
98
- slug?: string;
99
- /**
100
- * Override the `custom.path` Payload uses to resolve the post's
101
- * render module. Defaults to the lib's `POSTS_RENDER_PATH`
102
- * (the lib's `<PostsPage>` Server Component, which renders
103
- * `title` + `excerpt` + Lexical `content`). Hosts that want a
104
- * custom render pass their own Server Component's import path
105
- * here (e.g. `'@/blog/Post#default'`).
106
- */
107
- renderPath?: string;
108
- /**
109
- * Locale prefix mode for path invalidation. Defaults to `'always'`.
110
- * Set to `'as-needed'` when the host uses next-intl
111
- * `localePrefix: 'as-needed'` — otherwise the hook invalidates
112
- * paths the public routes don't use.
113
- */
114
- localePrefix?: "always" | "as-needed" | "never";
115
- /**
116
- * Default locale for prefix skipping. Falls back to
117
- * `req.payload.config.localization.defaultLocale` at request time
118
- * when omitted.
119
- */
120
- defaultLocale?: string;
121
- };
122
- /**
123
- * Build the Posts collection. Posts have a simpler shape than
124
- * Pages: `title` + `excerpt` (both localized) + a Lexical `content`
125
- * rich text field. Hosts that want blocks can either swap the
126
- * `content` field for a `blocks` field via the returned config, or
127
- * define a custom Post shape entirely.
128
- *
129
- * The Posts collection exists primarily so the lib's translator
130
- * plugin has a second localized collection to translate.
131
- */
132
- declare const createPostsCollection: (options?: CreatePostsCollectionOptions) => CollectionConfig2;
133
- import { Block as Block2, CollectionConfig as CollectionConfig3 } from "payload";
134
- declare const STATIC_PAGES_SLUG = "staticPages";
135
- type CreateStaticPagesCollectionOptions = {
136
- /**
137
- * Blocks the StaticPages collection accepts. Hosts pass the same
138
- * `blocks` they use for `createPagesCollection` (or a smaller
139
- * subset — e.g. just `pageHeroBlock` + `ctaBlock` + `featureGridBlock`).
140
- * The lib does not curate a separate block set for system pages.
141
- */
142
- blocks: Block2[];
143
- };
144
- declare const createStaticPagesCollection: (blocks: Block2[]) => CollectionConfig3;
145
- import { Field, GlobalConfig } from "payload";
146
- type CreateHeaderGlobalOptions = {
147
- /**
148
- * Optional override for the `custom.path` Payload uses to resolve
149
- * the header's render module. Default: the lib's `HEADER_RENDER_PATH`.
150
- */
151
- renderPath?: string;
152
- /**
153
- * Collection slugs the nav's link fields can reference. Required
154
- * by Payload 3.85 — empty `relationTo` arrays are rejected.
155
- * Defaults to `['pages']` (the lib's Pages collection). Pass a
156
- * different list when your host has additional linkable collections.
157
- */
158
- linkRelationTo?: string[];
159
- /**
160
- * Extra fields appended to each `navColumn` link — e.g. a
161
- * `description` text field or a `navHover` group for a mega-menu.
162
- * Lets hosts enrich the column-link schema without redefining the
163
- * whole nav.
164
- */
165
- navColumnLinkFields?: Field[];
166
- /**
167
- * Extra fields appended to each top-level `navItem` link.
168
- */
169
- navItemLinkFields?: Field[];
170
- };
171
- /**
172
- * Build the Header global. The lib's default shape: a `nav` blocks
173
- * field with two block types — `navColumn` (a titled group of links)
174
- * and `navItem` (a single link).
175
- */
176
- declare const createHeaderGlobal: (options?: CreateHeaderGlobalOptions) => GlobalConfig;
177
- import { Field as Field2, GlobalConfig as GlobalConfig2 } from "payload";
178
- type CreateFooterGlobalOptions = {
179
- /**
180
- * Optional override for the `custom.path` Payload uses to resolve
181
- * the footer's render module. Default: the lib's `FOOTER_RENDER_PATH`.
182
- */
183
- renderPath?: string;
184
- /**
185
- * Collection slugs the nav's link fields can reference. Required
186
- * by Payload 3.85 — empty `relationTo` arrays are rejected.
187
- * Defaults to `['pages']` (the lib's Pages collection). Pass a
188
- * different list when your host has additional linkable collections.
189
- */
190
- linkRelationTo?: string[];
191
- /**
192
- * Extra fields appended to each `navColumn` link — e.g. a
193
- * `description` text field. Lets hosts enrich the column-link
194
- * schema without redefining the whole nav.
195
- */
196
- navColumnLinkFields?: Field2[];
197
- /**
198
- * Extra fields appended to each top-level `navItem` link.
199
- */
200
- navItemLinkFields?: Field2[];
201
- };
202
- /**
203
- * Build the Footer global. The lib's default shape mirrors the
204
- * Header: a `nav` blocks field with `navColumn` (a titled group of
205
- * links) and `navItem` (a single link) blocks.
206
- */
207
- declare const createFooterGlobal: (options?: CreateFooterGlobalOptions) => GlobalConfig2;
208
- import { CollectionSlug, PayloadRequest } from "payload";
209
- declare function generatePreviewPath({ collection, slug }: {
210
- collection: CollectionSlug;
211
- slug: string | null | undefined;
212
- req?: PayloadRequest;
213
- }): string | null;
214
- import { Block as Block_129qi5 } from "payload";
215
- import { CollectionConfig as CollectionConfig_j7kwbk } from "payload";
216
- import { GlobalConfig as GlobalConfig_fuin17 } from "payload";
217
- declare const _default: {
218
- createPagesCollection: (blocks: Block_129qi5[], options?: Omit<CreatePagesCollectionOptions, "blocks">) => CollectionConfig_j7kwbk;
219
- createPostsCollection: (options?: CreatePostsCollectionOptions) => CollectionConfig_j7kwbk;
220
- createStaticPagesCollection: (blocks: Block_129qi5[]) => CollectionConfig_j7kwbk;
221
- createHeaderGlobal: (options?: CreateHeaderGlobalOptions) => GlobalConfig_fuin17;
222
- createFooterGlobal: (options?: CreateFooterGlobalOptions) => GlobalConfig_fuin17;
223
- generatePreviewPath: typeof generatePreviewPath;
224
- HOME_PAGE_SLUG: string;
225
- PAGES_SLUG: string;
226
- POSTS_SLUG: string;
227
- STATIC_PAGES_SLUG: string;
228
- };
229
- export { generatePreviewPath, _default as default, createStaticPagesCollection, createPostsCollection, createPagesCollection, createHeaderGlobal, createFooterGlobal, STATIC_PAGES_SLUG, POSTS_SLUG, PAGES_SLUG, HOME_PAGE_SLUG, CreateStaticPagesCollectionOptions, CreatePostsCollectionOptions, CreatePagesCollectionOptions, CreateHeaderGlobalOptions, CreateFooterGlobalOptions };