@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.
package/dist/test.js CHANGED
@@ -29,7 +29,6 @@ var authenticatedOrPublished = ({ req: { user } }) => {
29
29
  return true;
30
30
  return { _status: { equals: "published" } };
31
31
  };
32
-
33
32
  // src/render/_locale.ts
34
33
  function prefixFor(locale, defaultLocale, mode) {
35
34
  if (mode === "never")
@@ -204,26 +203,6 @@ var createPagesCollection = (blocks, options = {}) => {
204
203
  defaultLocale,
205
204
  nested = false
206
205
  } = options;
207
- const slugPattern = nested ? /^[a-z0-9_-]+$/ : /^[a-z0-9-]+$/;
208
- const slugField = {
209
- name: "slug",
210
- type: "text",
211
- required: true,
212
- unique: true,
213
- index: true,
214
- admin: {
215
- position: "sidebar",
216
- ...nested ? { description: "Lowercase, hyphens for words. Use the `_` divider for nesting, e.g. `about_us` → `/about/us`." } : {}
217
- },
218
- validate: (value) => {
219
- if (typeof value !== "string")
220
- return "Slug must be a string";
221
- if (value !== "" && !slugPattern.test(value)) {
222
- 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)";
223
- }
224
- return true;
225
- }
226
- };
227
206
  const baseFields = [
228
207
  {
229
208
  name: "title",
@@ -253,7 +232,7 @@ var createPagesCollection = (blocks, options = {}) => {
253
232
  type: "date",
254
233
  admin: { position: "sidebar" }
255
234
  },
256
- slugField
235
+ slugField({ nested })
257
236
  ];
258
237
  const { afterChange: revalidateAfterChange, afterDelete: revalidateAfterDelete } = createRevalidateCollectionHook({
259
238
  collectionSlug,
@@ -288,14 +267,6 @@ var createPostsCollection = (options = {}) => {
288
267
  localePrefix,
289
268
  defaultLocale
290
269
  } = options;
291
- const slugField = {
292
- name: "slug",
293
- type: "text",
294
- required: true,
295
- unique: true,
296
- index: true,
297
- admin: { position: "sidebar" }
298
- };
299
270
  const baseFields = [
300
271
  {
301
272
  name: "title",
@@ -320,7 +291,7 @@ var createPostsCollection = (options = {}) => {
320
291
  type: "date",
321
292
  admin: { position: "sidebar" }
322
293
  },
323
- slugField
294
+ slugField()
324
295
  ];
325
296
  const { afterChange, afterDelete } = createRevalidateCollectionHook({
326
297
  collectionSlug,
@@ -421,11 +392,11 @@ var createStaticPagesCollection = (blocks) => {
421
392
  };
422
393
 
423
394
  // src/core/fields/link.ts
424
- var appearanceOptions = {
395
+ var appearanceOptions2 = {
425
396
  default: { label: "Default", value: "default" },
426
397
  outline: { label: "Outline", value: "outline" }
427
398
  };
428
- var link = (options = {}) => {
399
+ var link2 = (options = {}) => {
429
400
  const {
430
401
  appearances,
431
402
  disableLabel = false,
@@ -500,7 +471,7 @@ var link = (options = {}) => {
500
471
  result.fields = [...result.fields, ...linkTypes];
501
472
  }
502
473
  if (appearances !== false) {
503
- const opts = appearances ? appearances.map((a) => appearanceOptions[a]) : [appearanceOptions.default, appearanceOptions.outline];
474
+ const opts = appearances ? appearances.map((a) => appearanceOptions2[a]) : [appearanceOptions2.default, appearanceOptions2.outline];
504
475
  result.fields.push({
505
476
  name: "appearance",
506
477
  type: "select",
@@ -541,12 +512,12 @@ var createHeaderGlobal = (options = {}) => {
541
512
  slug: "navColumn",
542
513
  fields: [
543
514
  { name: "title", type: "text", required: true, localized: true },
544
- { name: "links", type: "array", fields: [link({ appearances: false, localized: true, relationTo: linkRelationTo, extraFields: navColumnLinkFields })] }
515
+ { name: "links", type: "array", fields: [link2({ appearances: false, localized: true, relationTo: linkRelationTo, extraFields: navColumnLinkFields })] }
545
516
  ]
546
517
  };
547
518
  const navItemBlock = {
548
519
  slug: "navItem",
549
- fields: [link({ appearances: false, localized: true, relationTo: linkRelationTo, extraFields: navItemLinkFields })]
520
+ fields: [link2({ appearances: false, localized: true, relationTo: linkRelationTo, extraFields: navItemLinkFields })]
550
521
  };
551
522
  return {
552
523
  slug: "header",
@@ -578,12 +549,12 @@ var createFooterGlobal = (options = {}) => {
578
549
  slug: "navColumn",
579
550
  fields: [
580
551
  { name: "title", type: "text", required: true, localized: true },
581
- { name: "links", type: "array", fields: [link({ appearances: false, localized: true, relationTo: linkRelationTo, extraFields: navColumnLinkFields })] }
552
+ { name: "links", type: "array", fields: [link2({ appearances: false, localized: true, relationTo: linkRelationTo, extraFields: navColumnLinkFields })] }
582
553
  ]
583
554
  };
584
555
  const navItemBlock = {
585
556
  slug: "navItem",
586
- fields: [link({ appearances: false, localized: true, relationTo: linkRelationTo, extraFields: navItemLinkFields })]
557
+ fields: [link2({ appearances: false, localized: true, relationTo: linkRelationTo, extraFields: navItemLinkFields })]
587
558
  };
588
559
  return {
589
560
  slug: "footer",
@@ -672,7 +643,7 @@ function getFromImportMap(key, importMap) {
672
643
  var queryDocBySlug = cache(async function queryDocBySlug2({
673
644
  collectionSlug,
674
645
  slug,
675
- slugField = "slug",
646
+ slugField: slugField2 = "slug",
676
647
  locale,
677
648
  draft = false,
678
649
  config
@@ -684,14 +655,14 @@ var queryDocBySlug = cache(async function queryDocBySlug2({
684
655
  limit: 1,
685
656
  pagination: false,
686
657
  overrideAccess: draft,
687
- where: { [slugField]: { equals: slug } },
658
+ where: { [slugField2]: { equals: slug } },
688
659
  locale
689
660
  });
690
661
  return result.docs?.[0] ?? null;
691
662
  });
692
663
  var queryAllDocs = cache(async function queryAllDocs2({
693
664
  collectionSlug,
694
- slugField = "slug",
665
+ slugField: slugField2 = "slug",
695
666
  locale,
696
667
  config
697
668
  }) {
@@ -702,7 +673,7 @@ var queryAllDocs = cache(async function queryAllDocs2({
702
673
  limit: 1000,
703
674
  pagination: false,
704
675
  overrideAccess: false,
705
- select: { [slugField]: true },
676
+ select: { [slugField2]: true },
706
677
  locale
707
678
  });
708
679
  return result.docs ?? [];
@@ -710,7 +681,7 @@ var queryAllDocs = cache(async function queryAllDocs2({
710
681
  var queryAllLocaleSlugs = cache(async function queryAllLocaleSlugs2({
711
682
  collectionSlug,
712
683
  slug,
713
- slugField = "slug",
684
+ slugField: slugField2 = "slug",
714
685
  locale,
715
686
  config
716
687
  }) {
@@ -722,13 +693,25 @@ var queryAllLocaleSlugs = cache(async function queryAllLocaleSlugs2({
722
693
  pagination: false,
723
694
  overrideAccess: false,
724
695
  locale,
725
- where: { [slugField]: { equals: slug } },
726
- select: { [slugField]: true }
696
+ where: { [slugField2]: { equals: slug } },
697
+ select: { [slugField2]: true }
727
698
  });
728
699
  const doc = result.docs?.[0];
729
700
  if (!doc)
730
701
  return;
731
- const fieldValue = doc?.[slugField];
702
+ let fieldValue = doc[slugField2];
703
+ if (doc.id != null) {
704
+ const allLocales2 = await payload.findByID({
705
+ collection: collectionSlug,
706
+ id: doc.id,
707
+ locale: "all",
708
+ draft: false,
709
+ overrideAccess: false,
710
+ select: { [slugField2]: true }
711
+ }).catch(() => null);
712
+ if (allLocales2)
713
+ fieldValue = allLocales2[slugField2];
714
+ }
732
715
  if (fieldValue && typeof fieldValue === "object") {
733
716
  return fieldValue;
734
717
  }
@@ -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
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@justanarthur/payload-www",
3
3
  "description": "Reusable Payload CMS website template — config builder, collections, globals, blocks, fields, access, hooks, metadata (JSON-LD, hreflang), page renderers, and test helpers.",
4
- "version": "0.2.0",
4
+ "version": "0.3.0",
5
5
  "type": "module",
6
6
  "private": false,
7
7
  "module": "./dist/index.js",