@justanarthur/payload-www 0.2.0 → 0.3.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.
@@ -23,7 +23,6 @@ var authenticatedOrPublished = ({ req: { user } }) => {
23
23
  return true;
24
24
  return { _status: { equals: "published" } };
25
25
  };
26
-
27
26
  // src/render/_locale.ts
28
27
  function prefixFor(locale, defaultLocale, mode) {
29
28
  if (mode === "never")
@@ -198,26 +197,6 @@ var createPagesCollection = (blocks, options = {}) => {
198
197
  defaultLocale,
199
198
  nested = false
200
199
  } = options;
201
- const slugPattern = nested ? /^[a-z0-9_-]+$/ : /^[a-z0-9-]+$/;
202
- const slugField = {
203
- name: "slug",
204
- type: "text",
205
- required: true,
206
- unique: true,
207
- index: true,
208
- admin: {
209
- position: "sidebar",
210
- ...nested ? { description: "Lowercase, hyphens for words. Use the `_` divider for nesting, e.g. `about_us` → `/about/us`." } : {}
211
- },
212
- validate: (value) => {
213
- if (typeof value !== "string")
214
- return "Slug must be a string";
215
- if (value !== "" && !slugPattern.test(value)) {
216
- return 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)";
217
- }
218
- return true;
219
- }
220
- };
221
200
  const baseFields = [
222
201
  {
223
202
  name: "title",
@@ -247,7 +226,7 @@ var createPagesCollection = (blocks, options = {}) => {
247
226
  type: "date",
248
227
  admin: { position: "sidebar" }
249
228
  },
250
- slugField
229
+ slugField({ nested })
251
230
  ];
252
231
  const { afterChange: revalidateAfterChange, afterDelete: revalidateAfterDelete } = createRevalidateCollectionHook({
253
232
  collectionSlug,
@@ -282,14 +261,6 @@ var createPostsCollection = (options = {}) => {
282
261
  localePrefix,
283
262
  defaultLocale
284
263
  } = options;
285
- const slugField = {
286
- name: "slug",
287
- type: "text",
288
- required: true,
289
- unique: true,
290
- index: true,
291
- admin: { position: "sidebar" }
292
- };
293
264
  const baseFields = [
294
265
  {
295
266
  name: "title",
@@ -314,7 +285,7 @@ var createPostsCollection = (options = {}) => {
314
285
  type: "date",
315
286
  admin: { position: "sidebar" }
316
287
  },
317
- slugField
288
+ slugField()
318
289
  ];
319
290
  const { afterChange, afterDelete } = createRevalidateCollectionHook({
320
291
  collectionSlug,
@@ -415,11 +386,11 @@ var createStaticPagesCollection = (blocks) => {
415
386
  };
416
387
 
417
388
  // src/core/fields/link.ts
418
- var appearanceOptions = {
389
+ var appearanceOptions2 = {
419
390
  default: { label: "Default", value: "default" },
420
391
  outline: { label: "Outline", value: "outline" }
421
392
  };
422
- var link = (options = {}) => {
393
+ var link2 = (options = {}) => {
423
394
  const {
424
395
  appearances,
425
396
  disableLabel = false,
@@ -494,7 +465,7 @@ var link = (options = {}) => {
494
465
  result.fields = [...result.fields, ...linkTypes];
495
466
  }
496
467
  if (appearances !== false) {
497
- const opts = appearances ? appearances.map((a) => appearanceOptions[a]) : [appearanceOptions.default, appearanceOptions.outline];
468
+ const opts = appearances ? appearances.map((a) => appearanceOptions2[a]) : [appearanceOptions2.default, appearanceOptions2.outline];
498
469
  result.fields.push({
499
470
  name: "appearance",
500
471
  type: "select",
@@ -535,12 +506,12 @@ var createHeaderGlobal = (options = {}) => {
535
506
  slug: "navColumn",
536
507
  fields: [
537
508
  { name: "title", type: "text", required: true, localized: true },
538
- { name: "links", type: "array", fields: [link({ appearances: false, localized: true, relationTo: linkRelationTo, extraFields: navColumnLinkFields })] }
509
+ { name: "links", type: "array", fields: [link2({ appearances: false, localized: true, relationTo: linkRelationTo, extraFields: navColumnLinkFields })] }
539
510
  ]
540
511
  };
541
512
  const navItemBlock = {
542
513
  slug: "navItem",
543
- fields: [link({ appearances: false, localized: true, relationTo: linkRelationTo, extraFields: navItemLinkFields })]
514
+ fields: [link2({ appearances: false, localized: true, relationTo: linkRelationTo, extraFields: navItemLinkFields })]
544
515
  };
545
516
  return {
546
517
  slug: "header",
@@ -572,12 +543,12 @@ var createFooterGlobal = (options = {}) => {
572
543
  slug: "navColumn",
573
544
  fields: [
574
545
  { name: "title", type: "text", required: true, localized: true },
575
- { name: "links", type: "array", fields: [link({ appearances: false, localized: true, relationTo: linkRelationTo, extraFields: navColumnLinkFields })] }
546
+ { name: "links", type: "array", fields: [link2({ appearances: false, localized: true, relationTo: linkRelationTo, extraFields: navColumnLinkFields })] }
576
547
  ]
577
548
  };
578
549
  const navItemBlock = {
579
550
  slug: "navItem",
580
- fields: [link({ appearances: false, localized: true, relationTo: linkRelationTo, extraFields: navItemLinkFields })]
551
+ fields: [link2({ appearances: false, localized: true, relationTo: linkRelationTo, extraFields: navItemLinkFields })]
581
552
  };
582
553
  return {
583
554
  slug: "footer",
package/dist/config.js CHANGED
@@ -23,7 +23,6 @@ var authenticatedOrPublished = ({ req: { user } }) => {
23
23
  return true;
24
24
  return { _status: { equals: "published" } };
25
25
  };
26
-
27
26
  // src/render/_locale.ts
28
27
  function prefixFor(locale, defaultLocale, mode) {
29
28
  if (mode === "never")
@@ -198,26 +197,6 @@ var createPagesCollection = (blocks, options = {}) => {
198
197
  defaultLocale,
199
198
  nested = false
200
199
  } = options;
201
- const slugPattern = nested ? /^[a-z0-9_-]+$/ : /^[a-z0-9-]+$/;
202
- const slugField = {
203
- name: "slug",
204
- type: "text",
205
- required: true,
206
- unique: true,
207
- index: true,
208
- admin: {
209
- position: "sidebar",
210
- ...nested ? { description: "Lowercase, hyphens for words. Use the `_` divider for nesting, e.g. `about_us` → `/about/us`." } : {}
211
- },
212
- validate: (value) => {
213
- if (typeof value !== "string")
214
- return "Slug must be a string";
215
- if (value !== "" && !slugPattern.test(value)) {
216
- return 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)";
217
- }
218
- return true;
219
- }
220
- };
221
200
  const baseFields = [
222
201
  {
223
202
  name: "title",
@@ -247,7 +226,7 @@ var createPagesCollection = (blocks, options = {}) => {
247
226
  type: "date",
248
227
  admin: { position: "sidebar" }
249
228
  },
250
- slugField
229
+ slugField({ nested })
251
230
  ];
252
231
  const { afterChange: revalidateAfterChange, afterDelete: revalidateAfterDelete } = createRevalidateCollectionHook({
253
232
  collectionSlug,
@@ -282,14 +261,6 @@ var createPostsCollection = (options = {}) => {
282
261
  localePrefix,
283
262
  defaultLocale
284
263
  } = options;
285
- const slugField = {
286
- name: "slug",
287
- type: "text",
288
- required: true,
289
- unique: true,
290
- index: true,
291
- admin: { position: "sidebar" }
292
- };
293
264
  const baseFields = [
294
265
  {
295
266
  name: "title",
@@ -314,7 +285,7 @@ var createPostsCollection = (options = {}) => {
314
285
  type: "date",
315
286
  admin: { position: "sidebar" }
316
287
  },
317
- slugField
288
+ slugField()
318
289
  ];
319
290
  const { afterChange, afterDelete } = createRevalidateCollectionHook({
320
291
  collectionSlug,
@@ -415,11 +386,11 @@ var createStaticPagesCollection = (blocks) => {
415
386
  };
416
387
 
417
388
  // src/core/fields/link.ts
418
- var appearanceOptions = {
389
+ var appearanceOptions2 = {
419
390
  default: { label: "Default", value: "default" },
420
391
  outline: { label: "Outline", value: "outline" }
421
392
  };
422
- var link = (options = {}) => {
393
+ var link2 = (options = {}) => {
423
394
  const {
424
395
  appearances,
425
396
  disableLabel = false,
@@ -494,7 +465,7 @@ var link = (options = {}) => {
494
465
  result.fields = [...result.fields, ...linkTypes];
495
466
  }
496
467
  if (appearances !== false) {
497
- const opts = appearances ? appearances.map((a) => appearanceOptions[a]) : [appearanceOptions.default, appearanceOptions.outline];
468
+ const opts = appearances ? appearances.map((a) => appearanceOptions2[a]) : [appearanceOptions2.default, appearanceOptions2.outline];
498
469
  result.fields.push({
499
470
  name: "appearance",
500
471
  type: "select",
@@ -535,12 +506,12 @@ var createHeaderGlobal = (options = {}) => {
535
506
  slug: "navColumn",
536
507
  fields: [
537
508
  { name: "title", type: "text", required: true, localized: true },
538
- { name: "links", type: "array", fields: [link({ appearances: false, localized: true, relationTo: linkRelationTo, extraFields: navColumnLinkFields })] }
509
+ { name: "links", type: "array", fields: [link2({ appearances: false, localized: true, relationTo: linkRelationTo, extraFields: navColumnLinkFields })] }
539
510
  ]
540
511
  };
541
512
  const navItemBlock = {
542
513
  slug: "navItem",
543
- fields: [link({ appearances: false, localized: true, relationTo: linkRelationTo, extraFields: navItemLinkFields })]
514
+ fields: [link2({ appearances: false, localized: true, relationTo: linkRelationTo, extraFields: navItemLinkFields })]
544
515
  };
545
516
  return {
546
517
  slug: "header",
@@ -572,12 +543,12 @@ var createFooterGlobal = (options = {}) => {
572
543
  slug: "navColumn",
573
544
  fields: [
574
545
  { name: "title", type: "text", required: true, localized: true },
575
- { name: "links", type: "array", fields: [link({ appearances: false, localized: true, relationTo: linkRelationTo, extraFields: navColumnLinkFields })] }
546
+ { name: "links", type: "array", fields: [link2({ appearances: false, localized: true, relationTo: linkRelationTo, extraFields: navColumnLinkFields })] }
576
547
  ]
577
548
  };
578
549
  const navItemBlock = {
579
550
  slug: "navItem",
580
- fields: [link({ appearances: false, localized: true, relationTo: linkRelationTo, extraFields: navItemLinkFields })]
551
+ fields: [link2({ appearances: false, localized: true, relationTo: linkRelationTo, extraFields: navItemLinkFields })]
581
552
  };
582
553
  return {
583
554
  slug: "footer",
@@ -666,7 +637,7 @@ function getFromImportMap(key, importMap) {
666
637
  var queryDocBySlug = cache(async function queryDocBySlug2({
667
638
  collectionSlug,
668
639
  slug,
669
- slugField = "slug",
640
+ slugField: slugField2 = "slug",
670
641
  locale,
671
642
  draft = false,
672
643
  config
@@ -678,14 +649,14 @@ var queryDocBySlug = cache(async function queryDocBySlug2({
678
649
  limit: 1,
679
650
  pagination: false,
680
651
  overrideAccess: draft,
681
- where: { [slugField]: { equals: slug } },
652
+ where: { [slugField2]: { equals: slug } },
682
653
  locale
683
654
  });
684
655
  return result.docs?.[0] ?? null;
685
656
  });
686
657
  var queryAllDocs = cache(async function queryAllDocs2({
687
658
  collectionSlug,
688
- slugField = "slug",
659
+ slugField: slugField2 = "slug",
689
660
  locale,
690
661
  config
691
662
  }) {
@@ -696,7 +667,7 @@ var queryAllDocs = cache(async function queryAllDocs2({
696
667
  limit: 1000,
697
668
  pagination: false,
698
669
  overrideAccess: false,
699
- select: { [slugField]: true },
670
+ select: { [slugField2]: true },
700
671
  locale
701
672
  });
702
673
  return result.docs ?? [];
@@ -704,7 +675,7 @@ var queryAllDocs = cache(async function queryAllDocs2({
704
675
  var queryAllLocaleSlugs = cache(async function queryAllLocaleSlugs2({
705
676
  collectionSlug,
706
677
  slug,
707
- slugField = "slug",
678
+ slugField: slugField2 = "slug",
708
679
  locale,
709
680
  config
710
681
  }) {
@@ -716,13 +687,25 @@ var queryAllLocaleSlugs = cache(async function queryAllLocaleSlugs2({
716
687
  pagination: false,
717
688
  overrideAccess: false,
718
689
  locale,
719
- where: { [slugField]: { equals: slug } },
720
- select: { [slugField]: true }
690
+ where: { [slugField2]: { equals: slug } },
691
+ select: { [slugField2]: true }
721
692
  });
722
693
  const doc = result.docs?.[0];
723
694
  if (!doc)
724
695
  return;
725
- const fieldValue = doc?.[slugField];
696
+ let fieldValue = doc[slugField2];
697
+ if (doc.id != null) {
698
+ const allLocales2 = await payload.findByID({
699
+ collection: collectionSlug,
700
+ id: doc.id,
701
+ locale: "all",
702
+ draft: false,
703
+ overrideAccess: false,
704
+ select: { [slugField2]: true }
705
+ }).catch(() => null);
706
+ if (allLocales2)
707
+ fieldValue = allLocales2[slugField2];
708
+ }
726
709
  if (fieldValue && typeof fieldValue === "object") {
727
710
  return fieldValue;
728
711
  }
@@ -32,6 +32,34 @@ type LinkOptions = {
32
32
  declare const link: (options?: LinkOptions) => Field;
33
33
  import { Field as Field2 } from "payload";
34
34
  declare const linkGroup: (options?: LinkOptions) => Field2;
35
+ import { Field as Field3 } from "payload";
36
+ type SlugFieldOptions = {
37
+ /** Field name. Default: `'slug'`. */
38
+ name?: string;
39
+ /**
40
+ * Allow the `_` nesting divider in the slug so `about_us` renders at
41
+ * `/about/us`. Relaxes validation and documents the convention in the
42
+ * admin UI. Pair with `createCollectionPageExports({ nested: true })`.
43
+ * Default: `false`.
44
+ */
45
+ nested?: boolean;
46
+ /**
47
+ * Localize the slug — one slug per locale (`/about` in `en`, `/o-nas`
48
+ * in `sk`), stored in the collection's `_locales` table. This is the
49
+ * default: the lib's collections are multilingual, so per-locale slugs
50
+ * power localized URLs and hreflang alternates. Pass `false` for a
51
+ * single shared slug.
52
+ */
53
+ localized?: boolean;
54
+ };
55
+ /**
56
+ * The slug field shared by the lib's Pages / Posts collections: a
57
+ * required, unique, indexed, sidebar text field, localized by default.
58
+ *
59
+ * The empty string is reserved for the home page (rendered at
60
+ * `/${locale}`), so validation only rejects non-empty malformed values.
61
+ */
62
+ declare const slugField: (options?: SlugFieldOptions) => Field3;
35
63
  import { Field as Field_14espm } from "payload";
36
64
  declare const _default: {
37
65
  link: (options?: LinkOptions) => Field_14espm;
@@ -40,5 +68,6 @@ declare const _default: {
40
68
  label: string;
41
69
  value: string;
42
70
  }>;
71
+ slugField: (options?: SlugFieldOptions) => Field_14espm;
43
72
  };
44
- export { linkGroup, link, _default as default, appearanceOptions, LinkOptions, LinkAppearances };
73
+ export { slugField, linkGroup, link, _default as default, appearanceOptions, SlugFieldOptions, LinkOptions, LinkAppearances };
@@ -128,9 +128,38 @@ var linkGroup = (options = {}) => ({
128
128
  admin: { initCollapsed: true }
129
129
  });
130
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
+
131
159
  // src/exports/core-fields.ts
132
- var core_fields_default = { link, linkGroup, appearanceOptions };
160
+ var core_fields_default = { link, linkGroup, appearanceOptions, slugField };
133
161
  export {
162
+ slugField,
134
163
  linkGroup,
135
164
  link,
136
165
  core_fields_default as default,
@@ -23,7 +23,6 @@ var authenticatedOrPublished = ({ req: { user } }) => {
23
23
  return true;
24
24
  return { _status: { equals: "published" } };
25
25
  };
26
-
27
26
  // src/render/_locale.ts
28
27
  function prefixFor(locale, defaultLocale, mode) {
29
28
  if (mode === "never")
@@ -198,26 +197,6 @@ var createPagesCollection = (blocks, options = {}) => {
198
197
  defaultLocale,
199
198
  nested = false
200
199
  } = options;
201
- const slugPattern = nested ? /^[a-z0-9_-]+$/ : /^[a-z0-9-]+$/;
202
- const slugField = {
203
- name: "slug",
204
- type: "text",
205
- required: true,
206
- unique: true,
207
- index: true,
208
- admin: {
209
- position: "sidebar",
210
- ...nested ? { description: "Lowercase, hyphens for words. Use the `_` divider for nesting, e.g. `about_us` → `/about/us`." } : {}
211
- },
212
- validate: (value) => {
213
- if (typeof value !== "string")
214
- return "Slug must be a string";
215
- if (value !== "" && !slugPattern.test(value)) {
216
- return 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)";
217
- }
218
- return true;
219
- }
220
- };
221
200
  const baseFields = [
222
201
  {
223
202
  name: "title",
@@ -247,7 +226,7 @@ var createPagesCollection = (blocks, options = {}) => {
247
226
  type: "date",
248
227
  admin: { position: "sidebar" }
249
228
  },
250
- slugField
229
+ slugField({ nested })
251
230
  ];
252
231
  const { afterChange: revalidateAfterChange, afterDelete: revalidateAfterDelete } = createRevalidateCollectionHook({
253
232
  collectionSlug,
@@ -282,14 +261,6 @@ var createPostsCollection = (options = {}) => {
282
261
  localePrefix,
283
262
  defaultLocale
284
263
  } = options;
285
- const slugField = {
286
- name: "slug",
287
- type: "text",
288
- required: true,
289
- unique: true,
290
- index: true,
291
- admin: { position: "sidebar" }
292
- };
293
264
  const baseFields = [
294
265
  {
295
266
  name: "title",
@@ -314,7 +285,7 @@ var createPostsCollection = (options = {}) => {
314
285
  type: "date",
315
286
  admin: { position: "sidebar" }
316
287
  },
317
- slugField
288
+ slugField()
318
289
  ];
319
290
  const { afterChange, afterDelete } = createRevalidateCollectionHook({
320
291
  collectionSlug,
@@ -415,11 +386,11 @@ var createStaticPagesCollection = (blocks) => {
415
386
  };
416
387
 
417
388
  // src/core/fields/link.ts
418
- var appearanceOptions = {
389
+ var appearanceOptions2 = {
419
390
  default: { label: "Default", value: "default" },
420
391
  outline: { label: "Outline", value: "outline" }
421
392
  };
422
- var link = (options = {}) => {
393
+ var link2 = (options = {}) => {
423
394
  const {
424
395
  appearances,
425
396
  disableLabel = false,
@@ -494,7 +465,7 @@ var link = (options = {}) => {
494
465
  result.fields = [...result.fields, ...linkTypes];
495
466
  }
496
467
  if (appearances !== false) {
497
- const opts = appearances ? appearances.map((a) => appearanceOptions[a]) : [appearanceOptions.default, appearanceOptions.outline];
468
+ const opts = appearances ? appearances.map((a) => appearanceOptions2[a]) : [appearanceOptions2.default, appearanceOptions2.outline];
498
469
  result.fields.push({
499
470
  name: "appearance",
500
471
  type: "select",
@@ -535,12 +506,12 @@ var createHeaderGlobal = (options = {}) => {
535
506
  slug: "navColumn",
536
507
  fields: [
537
508
  { name: "title", type: "text", required: true, localized: true },
538
- { name: "links", type: "array", fields: [link({ appearances: false, localized: true, relationTo: linkRelationTo, extraFields: navColumnLinkFields })] }
509
+ { name: "links", type: "array", fields: [link2({ appearances: false, localized: true, relationTo: linkRelationTo, extraFields: navColumnLinkFields })] }
539
510
  ]
540
511
  };
541
512
  const navItemBlock = {
542
513
  slug: "navItem",
543
- fields: [link({ appearances: false, localized: true, relationTo: linkRelationTo, extraFields: navItemLinkFields })]
514
+ fields: [link2({ appearances: false, localized: true, relationTo: linkRelationTo, extraFields: navItemLinkFields })]
544
515
  };
545
516
  return {
546
517
  slug: "header",
@@ -572,12 +543,12 @@ var createFooterGlobal = (options = {}) => {
572
543
  slug: "navColumn",
573
544
  fields: [
574
545
  { name: "title", type: "text", required: true, localized: true },
575
- { name: "links", type: "array", fields: [link({ appearances: false, localized: true, relationTo: linkRelationTo, extraFields: navColumnLinkFields })] }
546
+ { name: "links", type: "array", fields: [link2({ appearances: false, localized: true, relationTo: linkRelationTo, extraFields: navColumnLinkFields })] }
576
547
  ]
577
548
  };
578
549
  const navItemBlock = {
579
550
  slug: "navItem",
580
- fields: [link({ appearances: false, localized: true, relationTo: linkRelationTo, extraFields: navItemLinkFields })]
551
+ fields: [link2({ appearances: false, localized: true, relationTo: linkRelationTo, extraFields: navItemLinkFields })]
581
552
  };
582
553
  return {
583
554
  slug: "footer",