@justanarthur/payload-www 0.1.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 +381 -0
  2. package/dist/access.d.ts +11 -0
  3. package/dist/access.js +34 -0
  4. package/dist/blocks.d.ts +24 -0
  5. package/dist/blocks.js +75 -0
  6. package/dist/collections.d.ts +200 -0
  7. package/dist/collections.js +625 -0
  8. package/dist/components.d.ts +6 -0
  9. package/dist/components.js +38 -0
  10. package/dist/config.d.ts +100 -0
  11. package/dist/config.js +914 -0
  12. package/dist/core-access.d.ts +11 -0
  13. package/dist/core-access.js +34 -0
  14. package/dist/core-blocks.d.ts +24 -0
  15. package/dist/core-blocks.js +75 -0
  16. package/dist/core-fields.d.ts +36 -0
  17. package/dist/core-fields.js +134 -0
  18. package/dist/core-utils.d.ts +16 -0
  19. package/dist/core-utils.js +59 -0
  20. package/dist/data-collections.d.ts +200 -0
  21. package/dist/data-collections.js +625 -0
  22. package/dist/data-seed.d.ts +76 -0
  23. package/dist/data-seed.js +212 -0
  24. package/dist/data-test.d.ts +30 -0
  25. package/dist/data-test.js +1018 -0
  26. package/dist/fields.d.ts +36 -0
  27. package/dist/fields.js +134 -0
  28. package/dist/globals.d.ts +48 -0
  29. package/dist/globals.js +228 -0
  30. package/dist/hooks.d.ts +108 -0
  31. package/dist/hooks.js +196 -0
  32. package/dist/imagehash.d.ts +3 -0
  33. package/dist/imagehash.js +24 -0
  34. package/dist/import-map-provider.d.ts +20 -0
  35. package/dist/import-map-provider.js +26 -0
  36. package/dist/index.d.ts +6 -0
  37. package/dist/index.js +38 -0
  38. package/dist/metadata.d.ts +122 -0
  39. package/dist/metadata.js +335 -0
  40. package/dist/pages.d.ts +323 -0
  41. package/dist/pages.js +1016 -0
  42. package/dist/render-components.d.ts +42 -0
  43. package/dist/render-components.js +144 -0
  44. package/dist/render-metadata.d.ts +122 -0
  45. package/dist/render-metadata.js +335 -0
  46. package/dist/render-pages.d.ts +574 -0
  47. package/dist/render-pages.js +1450 -0
  48. package/dist/render-utils.d.ts +158 -0
  49. package/dist/render-utils.js +341 -0
  50. package/dist/seed.d.ts +76 -0
  51. package/dist/seed.js +212 -0
  52. package/dist/server.d.ts +922 -0
  53. package/dist/server.js +2055 -0
  54. package/dist/test.d.ts +30 -0
  55. package/dist/test.js +1018 -0
  56. package/dist/translator.d.ts +2 -0
  57. package/dist/translator.js +24 -0
  58. package/dist/utils.d.ts +16 -0
  59. package/dist/utils.js +59 -0
  60. package/dist/with-www-config.d.ts +100 -0
  61. package/dist/with-www-config.js +914 -0
  62. package/package.json +246 -0
package/dist/hooks.js ADDED
@@ -0,0 +1,196 @@
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/render/_locale.ts
19
+ function prefixFor(locale, defaultLocale, mode) {
20
+ if (mode === "never")
21
+ return "";
22
+ if (mode === "as-needed" && locale === defaultLocale)
23
+ return "";
24
+ return `/${locale}`;
25
+ }
26
+ function resolveLocale(req) {
27
+ if (!req || typeof req !== "object")
28
+ return "";
29
+ const r = req;
30
+ if (typeof r.locale === "string" && r.locale.length > 0)
31
+ return r.locale;
32
+ const fallback = r.payload?.config?.localization?.defaultLocale;
33
+ if (typeof fallback === "string" && fallback.length > 0)
34
+ return fallback;
35
+ return "";
36
+ }
37
+ function allLocales(req) {
38
+ if (!req || typeof req !== "object")
39
+ return [];
40
+ const r = req;
41
+ const list = r.payload?.config?.localization?.locales;
42
+ if (!Array.isArray(list) || list.length === 0)
43
+ return [];
44
+ const out = [];
45
+ for (const entry of list) {
46
+ if (typeof entry === "string" && entry.length > 0) {
47
+ out.push(entry);
48
+ } else if (entry && typeof entry === "object" && "code" in entry) {
49
+ const code = entry.code;
50
+ if (typeof code === "string" && code.length > 0)
51
+ out.push(code);
52
+ }
53
+ }
54
+ return out;
55
+ }
56
+
57
+ // src/render/hooks/_shared.ts
58
+ var cachePromise = null;
59
+ function nextCacheImport() {
60
+ return cachePromise ??= import("next/cache");
61
+ }
62
+ function shouldSkipRevalidate(context) {
63
+ return Boolean(context?.disableRevalidate);
64
+ }
65
+ async function safeRevalidatePath(payload, path) {
66
+ try {
67
+ const { revalidatePath } = await nextCacheImport();
68
+ revalidatePath(path);
69
+ } catch (error) {
70
+ payload.logger.error(`revalidatePath("${path}") failed: ${String(error)}`);
71
+ }
72
+ }
73
+ async function safeRevalidateTag(payload, tag, profile = "max") {
74
+ try {
75
+ const { revalidateTag } = await nextCacheImport();
76
+ revalidateTag(tag, profile);
77
+ } catch (error) {
78
+ payload.logger.error(`revalidateTag("${tag}") failed: ${String(error)}`);
79
+ }
80
+ }
81
+
82
+ // src/render/hooks/revalidateCollection.ts
83
+ function createRevalidateCollectionHook(options) {
84
+ const {
85
+ collectionSlug,
86
+ urlPathPrefix = "",
87
+ sitemapTag,
88
+ localePrefix: modeOption,
89
+ defaultLocale: defaultLocaleOption,
90
+ pathMode = "url"
91
+ } = options;
92
+ const resolvedSitemapTag = sitemapTag === false ? false : sitemapTag ?? `${collectionSlug}-sitemap`;
93
+ const resolveDefaults = (req) => {
94
+ const mode = modeOption ?? "always";
95
+ const defaultLocale = defaultLocaleOption ?? req?.payload?.config?.localization?.defaultLocale ?? "";
96
+ return { mode, defaultLocale };
97
+ };
98
+ const localesToFanOut = (req) => {
99
+ const all = allLocales(req);
100
+ if (all.length > 0)
101
+ return all;
102
+ const single = resolveLocale(req);
103
+ return single ? [single] : [];
104
+ };
105
+ const collectionPath = (slug, locale, mode, defaultLocale) => {
106
+ const prefix = prefixFor(locale, defaultLocale, mode);
107
+ if (!slug)
108
+ return `${prefix}${urlPathPrefix}` || "/";
109
+ return `${prefix}${urlPathPrefix}/${slug}`;
110
+ };
111
+ const fanOutPaths = async (payload, req, slug, label) => {
112
+ const { mode, defaultLocale } = resolveDefaults(req);
113
+ const locales = localesToFanOut(req);
114
+ for (const locale of locales) {
115
+ const path = collectionPath(slug, locale, mode, defaultLocale);
116
+ payload.logger.info?.(`${label} ${path}`);
117
+ await safeRevalidatePath(payload, path);
118
+ }
119
+ };
120
+ const fireCollectionTags = async (payload, docId, req) => {
121
+ if (typeof docId === "string" || typeof docId === "number") {
122
+ await safeRevalidateTag(payload, `collection_${collectionSlug}_${docId}`);
123
+ }
124
+ if (resolvedSitemapTag !== false) {
125
+ await safeRevalidateTag(payload, resolvedSitemapTag);
126
+ }
127
+ };
128
+ const afterChange = async ({ doc, previousDoc, req }) => {
129
+ if (shouldSkipRevalidate(req.context))
130
+ return doc;
131
+ const { payload } = req;
132
+ const typed = doc;
133
+ const prev = previousDoc;
134
+ const isPublished = typed._status === "published";
135
+ const wasPublished = prev?._status === "published";
136
+ const prevSlugIsString = typeof prev?.slug === "string";
137
+ const slugChanged = prevSlugIsString && prev?.slug !== typed.slug;
138
+ if (isPublished) {
139
+ if (pathMode !== "tag-only") {
140
+ await fanOutPaths(payload, req, typed.slug, `Revalidating ${collectionSlug} at path:`);
141
+ }
142
+ await fireCollectionTags(payload, typed.id, req);
143
+ }
144
+ if (wasPublished && (!isPublished || slugChanged)) {
145
+ if (pathMode !== "tag-only") {
146
+ await fanOutPaths(payload, req, prev?.slug, `Revalidating old ${collectionSlug} at path:`);
147
+ }
148
+ await fireCollectionTags(payload, typed.id, req);
149
+ }
150
+ return doc;
151
+ };
152
+ const afterDelete = async ({ doc, req }) => {
153
+ if (shouldSkipRevalidate(req.context))
154
+ return doc ?? null;
155
+ const { payload } = req;
156
+ const typed = doc;
157
+ if (pathMode !== "tag-only") {
158
+ await fanOutPaths(payload, req, typed?.slug, `Revalidating deleted ${collectionSlug} at path:`);
159
+ }
160
+ await fireCollectionTags(payload, typed?.id, req);
161
+ return doc ?? null;
162
+ };
163
+ return { afterChange, afterDelete };
164
+ }
165
+ var createRevalidatePageHooks = (opts = {}) => createRevalidateCollectionHook({
166
+ collectionSlug: "pages",
167
+ urlPathPrefix: "",
168
+ ...opts
169
+ });
170
+
171
+ // src/render/hooks/revalidateGlobal.ts
172
+ function createRevalidateGlobalHook(slug) {
173
+ return async ({ doc, req: { payload, context, locale } }) => {
174
+ if (shouldSkipRevalidate(context))
175
+ return doc;
176
+ const tags = [`global_${slug}`, `global_${slug}_${locale}`];
177
+ payload.logger.info?.(`Revalidating global: ${tags.join(", ")}`);
178
+ for (const tag of tags) {
179
+ await safeRevalidateTag(payload, tag);
180
+ }
181
+ return doc;
182
+ };
183
+ }
184
+
185
+ // src/exports/hooks.ts
186
+ var hooks_default = {
187
+ createRevalidateCollectionHook,
188
+ createRevalidatePageHooks,
189
+ createRevalidateGlobalHook
190
+ };
191
+ export {
192
+ hooks_default as default,
193
+ createRevalidatePageHooks,
194
+ createRevalidateGlobalHook,
195
+ createRevalidateCollectionHook
196
+ };
@@ -0,0 +1,3 @@
1
+ import { imageHashPlugin } from "@justanarthur/payload-imagehash-plugin";
2
+ import { BlurhashPluginOptions } from "@justanarthur/payload-imagehash-plugin/types";
3
+ export { imageHashPlugin, imageHashPlugin as default, BlurhashPluginOptions };
@@ -0,0 +1,24 @@
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/exports/imagehash.ts
19
+ import { imageHashPlugin } from "@justanarthur/payload-imagehash-plugin";
20
+ var imagehash_default = imageHashPlugin;
21
+ export {
22
+ imageHashPlugin,
23
+ imagehash_default as default
24
+ };
@@ -0,0 +1,20 @@
1
+ import { ImportMap } from "payload";
2
+ /**
3
+ * Marker kept for backwards compatibility with hosts that
4
+ * imported `setImportMapProvider` / `getImportMap` from earlier
5
+ * versions of the lib. New code should pass the importMap directly
6
+ * to `createRootLayoutExports` and `createCollectionPageExports` —
7
+ * no global state, no module-load-time coupling.
8
+ *
9
+ * The functions are no-ops. The lib reads the importMap exclusively
10
+ * from the per-factory `importMap` option now.
11
+ *
12
+ * @deprecated pass `importMap` to the factories instead.
13
+ */
14
+ declare function setImportMapProvider(_provider: () => Promise<ImportMap> | ImportMap): void;
15
+ /**
16
+ * @deprecated pass `importMap` to the factories instead. Always
17
+ * returns `{}` now — the lib never reads global state.
18
+ */
19
+ declare function getImportMap(): Promise<ImportMap>;
20
+ export { setImportMapProvider, getImportMap };
@@ -0,0 +1,26 @@
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/exports/import-map-provider.ts
19
+ function setImportMapProvider(_provider) {}
20
+ async function getImportMap() {
21
+ return {};
22
+ }
23
+ export {
24
+ setImportMapProvider,
25
+ getImportMap
26
+ };
@@ -0,0 +1,6 @@
1
+ import { FC } from "react";
2
+ type LivePreviewListenerProps = {
3
+ serverURL?: string;
4
+ };
5
+ declare const LivePreviewListener: FC<LivePreviewListenerProps>;
6
+ export { LivePreviewListener as default, LivePreviewListenerProps, LivePreviewListener };
package/dist/index.js ADDED
@@ -0,0 +1,38 @@
1
+ "use client";
2
+
3
+ var __defProp = Object.defineProperty;
4
+ var __returnValue = (v) => v;
5
+ function __exportSetter(name, newValue) {
6
+ this[name] = __returnValue.bind(null, newValue);
7
+ }
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, {
11
+ get: all[name],
12
+ enumerable: true,
13
+ configurable: true,
14
+ set: __exportSetter.bind(all, name)
15
+ });
16
+ };
17
+ var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
18
+
19
+ // src/render/components/LivePreviewListener.tsx
20
+ import { RefreshRouteOnSave as PayloadLivePreview } from "@payloadcms/live-preview-react";
21
+ import { useRouter } from "next/navigation";
22
+ import { jsx } from "react/jsx-runtime";
23
+
24
+ var LivePreviewListener = ({ serverURL }) => {
25
+ const router = useRouter();
26
+ const url = serverURL ?? process.env.NEXT_PUBLIC_SERVER_URL ?? (typeof window !== "undefined" ? window.location.origin : "");
27
+ return /* @__PURE__ */ jsx(PayloadLivePreview, {
28
+ refresh: router.refresh,
29
+ serverURL: url
30
+ });
31
+ };
32
+
33
+ // src/exports/index.ts
34
+ var exports_default = LivePreviewListener;
35
+ export {
36
+ exports_default as default,
37
+ LivePreviewListener
38
+ };
@@ -0,0 +1,122 @@
1
+ type ArticleLdOptions = {
2
+ doc: Record<string, any>;
3
+ url: string;
4
+ locale: string;
5
+ siteUrl: string;
6
+ type?: "BlogPosting" | "Article" | "NewsArticle" | "TechArticle";
7
+ publisherName?: string;
8
+ publisherLogo?: string | null;
9
+ };
10
+ declare function buildArticleLd({ doc, url, locale, siteUrl, type, publisherName, publisherLogo }: ArticleLdOptions): Record<string, unknown>;
11
+ type BreadcrumbItem = {
12
+ label: string;
13
+ url: string;
14
+ };
15
+ declare function buildBreadcrumbsLd({ items, currentUrl }: {
16
+ items: BreadcrumbItem[];
17
+ currentUrl: string;
18
+ }): Record<string, unknown>;
19
+ declare function buildOrganizationLd({ siteUrl, name, logo, sameAs }: {
20
+ siteUrl: string;
21
+ name?: string;
22
+ logo?: string;
23
+ sameAs?: string[];
24
+ }): Record<string, unknown>;
25
+ declare function buildHreflangAlternates<L extends string>({ siteUrl, locale, urlPrefix, storedSlug, queryAllLocaleSlugs, nested, homeSlug, defaultLocale, locales, localePrefix }: {
26
+ siteUrl: string;
27
+ locale: L;
28
+ urlPrefix: string;
29
+ storedSlug: string;
30
+ queryAllLocaleSlugs: (slug: string, locale: L) => Promise<Partial<Record<L, string>> | undefined>;
31
+ nested: boolean;
32
+ homeSlug: string;
33
+ defaultLocale: L;
34
+ locales: readonly L[];
35
+ /**
36
+ * Locale prefix mode — mirrors next-intl's `localePrefix` so each
37
+ * alternate URL matches the host's actual route shape:
38
+ *
39
+ * - `'always'`: every URL is prefixed with `/{locale}/…`
40
+ * (e.g. `/en/about`, `/uk/about`). The default — preserves
41
+ * the helper's prior behavior.
42
+ * - `'as-needed'`: the default locale renders without a prefix
43
+ * (e.g. `/about`), other locales are prefixed (`/uk/about`).
44
+ * Critical: callers that emit hreflang alongside a canonical
45
+ * URL built with `as-needed` mode MUST pass this through,
46
+ * otherwise the `en` and `x-default` alternates point to URLs
47
+ * the host doesn't actually serve.
48
+ * - `'never'`: no locale prefix at all.
49
+ */
50
+ localePrefix?: "always" | "as-needed" | "never";
51
+ }): Promise<Record<string, string>>;
52
+ declare function segmentsToStoredSlug(segments: string[] | string, nested?: boolean): string;
53
+ declare function segmentsToUrlPath(segments: string[] | string, nested?: boolean): string;
54
+ declare function storedSlugToSegments(storedSlug: string, nested?: boolean): string[] | string;
55
+ declare function buildCanonicalUrl<L extends string>({ siteUrl, locale, urlPrefix, urlPath }: {
56
+ siteUrl: string;
57
+ locale: L;
58
+ urlPrefix: string;
59
+ urlPath: string;
60
+ }): string;
61
+ declare function getUrlPath(segments: string[] | string, nested: boolean, homeSlug: string): string;
62
+ import { DataFromCollectionSlug, ImportMap, SanitizedConfig } from "payload";
63
+ declare const queryDocBySlug: <S extends string>({ collectionSlug, slug, slugField, locale, draft, config }: {
64
+ collectionSlug: S;
65
+ slug: string;
66
+ slugField?: string;
67
+ locale: string;
68
+ draft?: boolean;
69
+ config: Promise<SanitizedConfig>;
70
+ }) => Promise<DataFromCollectionSlug<S> | null>;
71
+ declare const queryAllDocs: <S extends string>({ collectionSlug, slugField, locale, config }: {
72
+ collectionSlug: S;
73
+ slugField?: string;
74
+ locale: string;
75
+ config: Promise<SanitizedConfig>;
76
+ }) => Promise<DataFromCollectionSlug<S>[]>;
77
+ declare const queryAllLocaleSlugs2: <S extends string>({ collectionSlug, slug, slugField, locale, config }: {
78
+ collectionSlug: S;
79
+ slug: string;
80
+ slugField?: string;
81
+ locale: string;
82
+ config: Promise<SanitizedConfig>;
83
+ }) => Promise<Record<string, string> | undefined>;
84
+ declare function getRenderModuleExports(exportName: string, collection: {
85
+ custom?: Record<string, unknown>;
86
+ } | undefined, importMap: ImportMap): unknown;
87
+ import { SanitizedConfig as SanitizedConfig_ee8ogz } from "payload";
88
+ import { DataFromCollectionSlug as DataFromCollectionSlug_2e2bqb } from "payload";
89
+ declare const _default: {
90
+ buildArticleLd: typeof buildArticleLd;
91
+ buildBreadcrumbsLd: typeof buildBreadcrumbsLd;
92
+ buildOrganizationLd: typeof buildOrganizationLd;
93
+ buildHreflangAlternates: typeof buildHreflangAlternates;
94
+ queryDocBySlug: <S extends string>({ collectionSlug, slug, slugField, locale, draft, config }: {
95
+ collectionSlug: S;
96
+ slug: string;
97
+ slugField?: string;
98
+ locale: string;
99
+ draft?: boolean;
100
+ config: Promise<SanitizedConfig_ee8ogz>;
101
+ }) => Promise<DataFromCollectionSlug_2e2bqb<S> | null>;
102
+ queryAllDocs: <S extends string>({ collectionSlug, slugField, locale, config }: {
103
+ collectionSlug: S;
104
+ slugField?: string;
105
+ locale: string;
106
+ config: Promise<SanitizedConfig_ee8ogz>;
107
+ }) => Promise<DataFromCollectionSlug_2e2bqb<S>[]>;
108
+ queryAllLocaleSlugs2: <S extends string>({ collectionSlug, slug, slugField, locale, config }: {
109
+ collectionSlug: S;
110
+ slug: string;
111
+ slugField?: string;
112
+ locale: string;
113
+ config: Promise<SanitizedConfig_ee8ogz>;
114
+ }) => Promise<Record<string, string> | undefined>;
115
+ getUrlPath: typeof getUrlPath;
116
+ segmentsToStoredSlug: typeof segmentsToStoredSlug;
117
+ segmentsToUrlPath: typeof segmentsToUrlPath;
118
+ storedSlugToSegments: typeof storedSlugToSegments;
119
+ buildCanonicalUrl: typeof buildCanonicalUrl;
120
+ getRenderModuleExports: typeof getRenderModuleExports;
121
+ };
122
+ export { storedSlugToSegments, segmentsToUrlPath, segmentsToStoredSlug, queryDocBySlug, queryAllLocaleSlugs2 as queryAllLocaleSlugs, queryAllDocs, getUrlPath, getRenderModuleExports, _default as default, buildOrganizationLd, buildHreflangAlternates, buildCanonicalUrl, buildBreadcrumbsLd, buildArticleLd, BreadcrumbItem, ArticleLdOptions };