@quitecustard/payload 0.1.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 (77) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +169 -0
  3. package/dist/access/anyone.d.ts +10 -0
  4. package/dist/access/anyone.js +9 -0
  5. package/dist/access/role-gate.d.ts +22 -0
  6. package/dist/access/role-gate.js +21 -0
  7. package/dist/access/self-access.d.ts +30 -0
  8. package/dist/access/self-access.js +34 -0
  9. package/dist/db/delete-many-with-versions.d.ts +21 -0
  10. package/dist/db/delete-many-with-versions.js +34 -0
  11. package/dist/db/external-ref.d.ts +65 -0
  12. package/dist/db/external-ref.js +88 -0
  13. package/dist/db/orphan-cleanup.d.ts +32 -0
  14. package/dist/db/orphan-cleanup.js +64 -0
  15. package/dist/db/sessions.d.ts +46 -0
  16. package/dist/db/sessions.js +50 -0
  17. package/dist/db/sql-result.d.ts +19 -0
  18. package/dist/db/sql-result.js +41 -0
  19. package/dist/db/sync-lock.d.ts +36 -0
  20. package/dist/db/sync-lock.js +116 -0
  21. package/dist/db/transaction-db.d.ts +13 -0
  22. package/dist/db/transaction-db.js +14 -0
  23. package/dist/documents/collection-versions.d.ts +10 -0
  24. package/dist/documents/collection-versions.js +17 -0
  25. package/dist/documents/locale-record.d.ts +12 -0
  26. package/dist/documents/locale-record.js +24 -0
  27. package/dist/documents/published-where.d.ts +21 -0
  28. package/dist/documents/published-where.js +17 -0
  29. package/dist/documents/resolve-ref.d.ts +29 -0
  30. package/dist/documents/resolve-ref.js +38 -0
  31. package/dist/errors/field-errors.d.ts +11 -0
  32. package/dist/errors/field-errors.js +16 -0
  33. package/dist/errors/is-duplicate-error.d.ts +14 -0
  34. package/dist/errors/is-duplicate-error.js +22 -0
  35. package/dist/errors/public-error.d.ts +17 -0
  36. package/dist/errors/public-error.js +26 -0
  37. package/dist/fields/colour-options-field.d.ts +18 -0
  38. package/dist/fields/colour-options-field.js +44 -0
  39. package/dist/fields/colour-picker-field.d.ts +12 -0
  40. package/dist/fields/colour-picker-field.js +11 -0
  41. package/dist/fields/height-field.d.ts +12 -0
  42. package/dist/fields/height-field.js +11 -0
  43. package/dist/fields/hero-field.d.ts +16 -0
  44. package/dist/fields/hero-field.js +50 -0
  45. package/dist/fields/layout-fields.d.ts +7 -0
  46. package/dist/fields/layout-fields.js +47 -0
  47. package/dist/fields/link-field.d.ts +34 -0
  48. package/dist/fields/link-field.js +170 -0
  49. package/dist/fields/media-content-fields.d.ts +23 -0
  50. package/dist/fields/media-content-fields.js +103 -0
  51. package/dist/fields/owner-field.d.ts +19 -0
  52. package/dist/fields/owner-field.js +53 -0
  53. package/dist/fields/phone-field.d.ts +12 -0
  54. package/dist/fields/phone-field.js +11 -0
  55. package/dist/fields/seo-tab.d.ts +18 -0
  56. package/dist/fields/seo-tab.js +36 -0
  57. package/dist/fields/size-field.d.ts +8 -0
  58. package/dist/fields/size-field.js +19 -0
  59. package/dist/fields/social-url.d.ts +21 -0
  60. package/dist/fields/social-url.js +49 -0
  61. package/dist/fields/spacing-select-field.d.ts +17 -0
  62. package/dist/fields/spacing-select-field.js +36 -0
  63. package/dist/internal/component-field.d.ts +25 -0
  64. package/dist/internal/component-field.js +24 -0
  65. package/dist/operations/after-response.d.ts +24 -0
  66. package/dist/operations/after-response.js +40 -0
  67. package/dist/operations/publish-transition.d.ts +45 -0
  68. package/dist/operations/publish-transition.js +78 -0
  69. package/dist/operations/run-queued-jobs.d.ts +30 -0
  70. package/dist/operations/run-queued-jobs.js +87 -0
  71. package/dist/operations/suppress-context.d.ts +16 -0
  72. package/dist/operations/suppress-context.js +55 -0
  73. package/dist/operations/unique-slug.d.ts +12 -0
  74. package/dist/operations/unique-slug.js +23 -0
  75. package/dist/operations/unique-username.d.ts +40 -0
  76. package/dist/operations/unique-username.js +52 -0
  77. package/package.json +76 -0
@@ -0,0 +1,18 @@
1
+ import { type GroupField, type Option } from 'payload';
2
+ /**
3
+ * A colour choice that is either one of `presetOptions` or a free custom value, entered through
4
+ * `component` (see `colourPickerField`). The shared shape a "background colour" and a "border
5
+ * colour" picker both are - just with different presets.
6
+ *
7
+ * ```ts
8
+ * colourOptionsField({ component: '@/components/colour-picker/ColourPicker', presetOptions })
9
+ * ```
10
+ */
11
+ export declare const colourOptionsField: ({ component, presetOptions, name, label, overrides, }: {
12
+ /** Admin component path for the custom-colour text field. */
13
+ component: string;
14
+ presetOptions: Option[];
15
+ name?: string;
16
+ label?: string;
17
+ overrides?: Partial<GroupField>;
18
+ }) => GroupField;
@@ -0,0 +1,44 @@
1
+ import { deepMerge } from 'payload';
2
+ import { colourPickerField } from './colour-picker-field.js';
3
+ /**
4
+ * A colour choice that is either one of `presetOptions` or a free custom value, entered through
5
+ * `component` (see `colourPickerField`). The shared shape a "background colour" and a "border
6
+ * colour" picker both are - just with different presets.
7
+ *
8
+ * ```ts
9
+ * colourOptionsField({ component: '@/components/colour-picker/ColourPicker', presetOptions })
10
+ * ```
11
+ */
12
+ export const colourOptionsField = ({ component, presetOptions, name = 'clr', label = 'Colour', overrides = {}, }) => {
13
+ const base = {
14
+ type: 'group',
15
+ name,
16
+ label,
17
+ fields: [
18
+ {
19
+ name: 'hasCustom',
20
+ label: 'Custom Colour',
21
+ type: 'checkbox',
22
+ defaultValue: false,
23
+ },
24
+ {
25
+ name: 'preset',
26
+ label: 'Colour',
27
+ type: 'select',
28
+ options: presetOptions,
29
+ admin: {
30
+ condition: (_, siblingData) => !siblingData.hasCustom,
31
+ },
32
+ },
33
+ colourPickerField(component, {
34
+ name: 'custom',
35
+ label: 'Custom Colour',
36
+ required: true,
37
+ admin: {
38
+ condition: (_, siblingData) => !!siblingData.hasCustom,
39
+ },
40
+ }),
41
+ ],
42
+ };
43
+ return deepMerge(base, overrides);
44
+ };
@@ -0,0 +1,12 @@
1
+ import type { TextField } from 'payload';
2
+ import { type ComponentFieldOverrides } from '../internal/component-field.js';
3
+ /**
4
+ * A text field rendered by a custom colour-picker admin component. `component` is the path Payload
5
+ * resolves for `admin.components.Field` (e.g. `@/components/colour-picker/ColourPicker`) - this
6
+ * package ships no UI, so the consumer's own component is a required parameter, not a default.
7
+ *
8
+ * ```ts
9
+ * colourField('@/components/colour-picker/ColourPicker', { name: 'colour', label: 'Colour' })
10
+ * ```
11
+ */
12
+ export declare const colourPickerField: (component: string, overrides?: ComponentFieldOverrides<TextField>) => TextField;
@@ -0,0 +1,11 @@
1
+ import { componentField } from '../internal/component-field.js';
2
+ /**
3
+ * A text field rendered by a custom colour-picker admin component. `component` is the path Payload
4
+ * resolves for `admin.components.Field` (e.g. `@/components/colour-picker/ColourPicker`) - this
5
+ * package ships no UI, so the consumer's own component is a required parameter, not a default.
6
+ *
7
+ * ```ts
8
+ * colourField('@/components/colour-picker/ColourPicker', { name: 'colour', label: 'Colour' })
9
+ * ```
10
+ */
11
+ export const colourPickerField = (component, overrides) => componentField('text', component, { name: 'colour', label: 'Colour' }, overrides);
@@ -0,0 +1,12 @@
1
+ import type { NumberField } from 'payload';
2
+ import { type ComponentFieldOverrides } from '../internal/component-field.js';
3
+ /**
4
+ * A number field rendered by a custom height-input admin component. `component` is the path
5
+ * Payload resolves for `admin.components.Field` - this package ships no UI, so the consumer's own
6
+ * component is a required parameter, not a default.
7
+ *
8
+ * ```ts
9
+ * heightField('@/components/height-input/HeightInput')
10
+ * ```
11
+ */
12
+ export declare const heightField: (component: string, overrides?: ComponentFieldOverrides<NumberField>) => NumberField;
@@ -0,0 +1,11 @@
1
+ import { componentField } from '../internal/component-field.js';
2
+ /**
3
+ * A number field rendered by a custom height-input admin component. `component` is the path
4
+ * Payload resolves for `admin.components.Field` - this package ships no UI, so the consumer's own
5
+ * component is a required parameter, not a default.
6
+ *
7
+ * ```ts
8
+ * heightField('@/components/height-input/HeightInput')
9
+ * ```
10
+ */
11
+ export const heightField = (component, overrides) => componentField('number', component, { name: 'height', label: 'Height (%)' }, overrides);
@@ -0,0 +1,16 @@
1
+ import type { CollectionSlug, GroupField } from 'payload';
2
+ /**
3
+ * The "hero" / banner group a profile-shaped collection carries: a media-type switch, an image, a
4
+ * video and the video's poster, each conditional on the switch. One factory so the four fields and
5
+ * their conditions agree across every collection that reuses it.
6
+ *
7
+ * ```ts
8
+ * heroField({ imageCollection: 'images', videoCollection: 'videos' })
9
+ * ```
10
+ */
11
+ export declare const heroField: ({ imageCollection, videoCollection, sizingNote, }: {
12
+ imageCollection: CollectionSlug;
13
+ videoCollection: CollectionSlug;
14
+ /** Shown under the surfaces that render the banner full-width. */
15
+ sizingNote?: string;
16
+ }) => GroupField;
@@ -0,0 +1,50 @@
1
+ /**
2
+ * The "hero" / banner group a profile-shaped collection carries: a media-type switch, an image, a
3
+ * video and the video's poster, each conditional on the switch. One factory so the four fields and
4
+ * their conditions agree across every collection that reuses it.
5
+ *
6
+ * ```ts
7
+ * heroField({ imageCollection: 'images', videoCollection: 'videos' })
8
+ * ```
9
+ */
10
+ export const heroField = ({ imageCollection, videoCollection, sizingNote, }) => ({
11
+ name: 'hero',
12
+ label: 'Banner',
13
+ type: 'group',
14
+ fields: [
15
+ {
16
+ name: 'type',
17
+ label: 'Media Type',
18
+ type: 'select',
19
+ options: [
20
+ { label: 'Image', value: 'image' },
21
+ { label: 'Video', value: 'video' },
22
+ ],
23
+ },
24
+ {
25
+ name: 'image',
26
+ type: 'upload',
27
+ relationTo: imageCollection,
28
+ admin: {
29
+ condition: (_, s) => s?.type === 'image',
30
+ ...(sizingNote && { description: sizingNote }),
31
+ },
32
+ },
33
+ {
34
+ name: 'video',
35
+ type: 'upload',
36
+ relationTo: videoCollection,
37
+ admin: { condition: (_, s) => s?.type === 'video' },
38
+ },
39
+ {
40
+ name: 'poster',
41
+ label: 'Video Poster Image',
42
+ type: 'upload',
43
+ relationTo: imageCollection,
44
+ admin: {
45
+ condition: (_, s) => s?.type === 'video',
46
+ ...(sizingNote && { description: sizingNote }),
47
+ },
48
+ },
49
+ ],
50
+ });
@@ -0,0 +1,7 @@
1
+ import type { Field, SelectField } from 'payload';
2
+ /** Left/center/right text alignment select, defaulting to left. */
3
+ export declare const alignmentField: () => SelectField;
4
+ /** A plain "stretch to full width" toggle. */
5
+ export declare const fullWidthField: () => Field;
6
+ /** A scroll-reveal animation toggle plus its style (fade/rise/zoom). */
7
+ export declare const animationField: () => Field;
@@ -0,0 +1,47 @@
1
+ // Factories, not shared constants: `buildConfig` sanitises fields IN PLACE - it assigns `validate`,
2
+ // `hooks`, `access` and `admin` onto the object it was handed, and deletes `localized` where the
3
+ // parent forbids it. One exported object reused across collections is therefore one object every
4
+ // collection mutates.
5
+ /** Left/center/right text alignment select, defaulting to left. */
6
+ export const alignmentField = () => ({
7
+ name: 'alignment',
8
+ type: 'select',
9
+ defaultValue: 'left',
10
+ required: true,
11
+ options: [
12
+ { label: 'Left', value: 'left' },
13
+ { label: 'Center', value: 'center' },
14
+ { label: 'Right', value: 'right' },
15
+ ],
16
+ });
17
+ /** A plain "stretch to full width" toggle. */
18
+ export const fullWidthField = () => ({
19
+ name: 'fullWidth',
20
+ type: 'checkbox',
21
+ });
22
+ /** A scroll-reveal animation toggle plus its style (fade/rise/zoom). */
23
+ export const animationField = () => ({
24
+ type: 'row',
25
+ fields: [
26
+ {
27
+ name: 'animate',
28
+ label: 'Animation?',
29
+ type: 'checkbox',
30
+ defaultValue: false,
31
+ },
32
+ {
33
+ name: 'animation',
34
+ label: 'Animation Type',
35
+ type: 'select',
36
+ defaultValue: 'fade',
37
+ options: [
38
+ { label: 'Fade In', value: 'fade' },
39
+ { label: 'Rise In', value: 'rise' },
40
+ { label: 'Zoom In', value: 'zoom' },
41
+ ],
42
+ admin: {
43
+ condition: (_, siblingData) => !!siblingData.animate,
44
+ },
45
+ },
46
+ ],
47
+ });
@@ -0,0 +1,34 @@
1
+ import { type CollectionSlug, type Field, type GroupField, type Option } from 'payload';
2
+ /** A select option with a known string value - `Option` itself may be a bare string. */
3
+ type SelectOption = {
4
+ label: string;
5
+ value: string;
6
+ };
7
+ /**
8
+ * A polymorphic link field: internal reference, custom URL, and optionally a static route, a
9
+ * dropdown-menu reference, and phone/email - each type only appears if its collection/component is
10
+ * given, so an unwanted type is simply omitted rather than toggled off.
11
+ *
12
+ * ```ts
13
+ * linkField({ relationTo: ['pages', 'posts'], styleOptions: [{ label: 'Primary', value: 'primary' }] })
14
+ * ```
15
+ */
16
+ export declare const linkField: ({ relationTo, dropdown, staticOptions, phoneComponent, styleOptions, disableLabel, localizedLabel, overrides, maxDepth, }: {
17
+ /** Collections the "internal link" type may point to. */
18
+ relationTo: CollectionSlug[];
19
+ /** Collection slug for a "dropdown" link type (e.g. a menus collection). Omit to disable it. */
20
+ dropdown?: CollectionSlug;
21
+ /** Options for a "static link" type (named in-app routes). Omit to disable it. */
22
+ staticOptions?: Option[];
23
+ /** Admin component path for the "phone" type (see `phoneField`). Omit to disable phone/email. */
24
+ phoneComponent?: string;
25
+ /** Style select options (e.g. primary/secondary/outline). Omit to skip the style field. */
26
+ styleOptions?: SelectOption[];
27
+ /** Whether the field also carries a "Label" text input alongside the link type. */
28
+ disableLabel?: boolean;
29
+ /** Localise just the label, while the link structure itself stays shared across locales. */
30
+ localizedLabel?: boolean;
31
+ overrides?: Partial<GroupField>;
32
+ maxDepth?: number;
33
+ }) => Field;
34
+ export {};
@@ -0,0 +1,170 @@
1
+ import { deepMerge } from 'payload';
2
+ import { validateLinkUrl } from '@quitecustard/core/url/link-protocol';
3
+ import { phoneField } from './phone-field.js';
4
+ // The cast reshapes a literal this file authored, not unknown data: `Field` is a discriminated
5
+ // union, and spreading one member to override `admin` widens `admin` across every member, so the
6
+ // result no longer matches any single branch. A generic `<F extends Field>` fails the same way.
7
+ const withRowWidth = (field) => ({ ...field, admin: { ...field.admin, width: '50%' } });
8
+ /**
9
+ * A polymorphic link field: internal reference, custom URL, and optionally a static route, a
10
+ * dropdown-menu reference, and phone/email - each type only appears if its collection/component is
11
+ * given, so an unwanted type is simply omitted rather than toggled off.
12
+ *
13
+ * ```ts
14
+ * linkField({ relationTo: ['pages', 'posts'], styleOptions: [{ label: 'Primary', value: 'primary' }] })
15
+ * ```
16
+ */
17
+ export const linkField = ({ relationTo, dropdown, staticOptions, phoneComponent, styleOptions, disableLabel = false, localizedLabel = false, overrides = {}, maxDepth = 1, }) => {
18
+ const typeOptions = [
19
+ { label: 'Internal link', value: 'reference' },
20
+ { label: 'Custom URL', value: 'custom' },
21
+ ];
22
+ if (staticOptions)
23
+ typeOptions.push({ label: 'Static link', value: 'static' });
24
+ if (dropdown)
25
+ typeOptions.push({ label: 'Dropdown', value: 'dropdown' });
26
+ if (phoneComponent)
27
+ typeOptions.push({ label: 'Phone', value: 'phone' }, { label: 'Email', value: 'email' });
28
+ const noNewTabTypes = new Set([
29
+ 'email',
30
+ ...(dropdown ? ['dropdown'] : []),
31
+ ...(phoneComponent ? ['phone'] : []),
32
+ ]);
33
+ const linkTypes = [
34
+ {
35
+ name: 'reference',
36
+ label: 'Document to link to',
37
+ type: 'relationship',
38
+ relationTo,
39
+ required: true,
40
+ maxDepth,
41
+ admin: {
42
+ condition: (_, siblingData) => siblingData?.type === 'reference',
43
+ },
44
+ },
45
+ {
46
+ name: 'url',
47
+ label: 'Custom URL',
48
+ type: 'text',
49
+ required: true,
50
+ validate: (value) => !value ? 'URL required' : validateLinkUrl(value),
51
+ admin: {
52
+ condition: (_, siblingData) => siblingData?.type === 'custom',
53
+ },
54
+ },
55
+ ];
56
+ if (phoneComponent) {
57
+ linkTypes.push(phoneField(phoneComponent, {
58
+ name: 'phone',
59
+ required: true,
60
+ admin: {
61
+ condition: (_, siblingData) => siblingData?.type === 'phone',
62
+ },
63
+ }), {
64
+ name: 'email',
65
+ label: 'Email Address',
66
+ type: 'email',
67
+ required: true,
68
+ admin: {
69
+ condition: (_, siblingData) => siblingData?.type === 'email',
70
+ },
71
+ });
72
+ }
73
+ if (dropdown) {
74
+ linkTypes.push({
75
+ name: 'dropdown',
76
+ label: 'Dropdown',
77
+ type: 'relationship',
78
+ relationTo: dropdown,
79
+ required: true,
80
+ // `id` is undefined on create, and `not_in: [undefined]` compiles to `id NOT IN (NULL)`,
81
+ // which matches no row - the picker would come up empty on a new document.
82
+ filterOptions: ({ id }) => id == null ? true : { id: { not_in: [id] } },
83
+ admin: {
84
+ condition: (_, siblingData) => siblingData?.type === 'dropdown',
85
+ },
86
+ });
87
+ }
88
+ if (staticOptions) {
89
+ linkTypes.push({
90
+ name: 'static',
91
+ label: 'Static Link',
92
+ type: 'select',
93
+ options: staticOptions,
94
+ required: true,
95
+ admin: {
96
+ condition: (_, siblingData) => siblingData?.type === 'static',
97
+ },
98
+ });
99
+ }
100
+ const linkResult = {
101
+ name: 'link',
102
+ type: 'group',
103
+ admin: {
104
+ hideGutter: true,
105
+ },
106
+ fields: [
107
+ {
108
+ type: 'row',
109
+ fields: [
110
+ {
111
+ name: 'type',
112
+ type: 'radio',
113
+ required: true,
114
+ admin: {
115
+ layout: 'horizontal',
116
+ width: '50%',
117
+ },
118
+ defaultValue: 'reference',
119
+ options: typeOptions,
120
+ },
121
+ {
122
+ name: 'newTab',
123
+ type: 'checkbox',
124
+ admin: {
125
+ style: {
126
+ alignSelf: 'flex-end',
127
+ },
128
+ condition: (_, siblingData) => !noNewTabTypes.has(siblingData?.type),
129
+ width: '50%',
130
+ },
131
+ label: 'Open in new tab',
132
+ },
133
+ ],
134
+ },
135
+ ],
136
+ };
137
+ if (!disableLabel) {
138
+ linkResult.fields.push({
139
+ type: 'row',
140
+ fields: [
141
+ ...linkTypes.map(withRowWidth),
142
+ {
143
+ name: 'label',
144
+ type: 'text',
145
+ localized: localizedLabel,
146
+ admin: {
147
+ width: '50%',
148
+ },
149
+ label: 'Label',
150
+ required: true,
151
+ },
152
+ ],
153
+ });
154
+ }
155
+ else {
156
+ linkResult.fields.push(...linkTypes);
157
+ }
158
+ if (styleOptions) {
159
+ linkResult.fields.push({
160
+ name: 'style',
161
+ type: 'select',
162
+ admin: {
163
+ description: 'Choose how the link should be rendered.',
164
+ },
165
+ defaultValue: styleOptions[0]?.value,
166
+ options: styleOptions,
167
+ });
168
+ }
169
+ return deepMerge(linkResult, overrides);
170
+ };
@@ -0,0 +1,23 @@
1
+ import { type CollectionSlug, type Field, type GroupField, type RichTextField } from 'payload';
2
+ /**
3
+ * The WYSIWYG-or-media-picker field set a content block reuses: an optional rich-text body plus,
4
+ * unless `disableMedia`, an image/video/slideshow picker switch.
5
+ *
6
+ * ```ts
7
+ * mediaContentFields({ editor, imageCollection: 'images', videoCollection: 'videos' })
8
+ * ```
9
+ */
10
+ export declare const mediaContentFields: ({ editor, imageCollection, videoCollection, disableMedia, }: {
11
+ editor: RichTextField["editor"];
12
+ imageCollection: CollectionSlug;
13
+ videoCollection: CollectionSlug;
14
+ disableMedia?: boolean;
15
+ }) => Field[];
16
+ /** `mediaContentFields`, wrapped in an unlabelled group - the shape most blocks actually embed. */
17
+ export declare const mediaContentGroupField: (options: {
18
+ editor: RichTextField["editor"];
19
+ imageCollection: CollectionSlug;
20
+ videoCollection: CollectionSlug;
21
+ disableMedia?: boolean;
22
+ overrides?: Partial<GroupField>;
23
+ }) => GroupField;
@@ -0,0 +1,103 @@
1
+ import { deepMerge, } from 'payload';
2
+ const buildContentFields = (editor) => [
3
+ {
4
+ name: 'hasWysiwyg',
5
+ type: 'checkbox',
6
+ label: 'Include WYSIWYG?',
7
+ defaultValue: false,
8
+ },
9
+ {
10
+ name: 'overlay',
11
+ label: 'Apply Gradient Overlay?',
12
+ type: 'checkbox',
13
+ defaultValue: true,
14
+ admin: {
15
+ condition: (_, { hasWysiwyg } = {}) => hasWysiwyg,
16
+ },
17
+ },
18
+ {
19
+ name: 'wysiwyg',
20
+ type: 'richText',
21
+ editor,
22
+ label: false,
23
+ admin: {
24
+ condition: (_, { hasWysiwyg } = {}) => hasWysiwyg,
25
+ },
26
+ },
27
+ ];
28
+ const buildMediaPickerFields = (imageCollection, videoCollection) => [
29
+ {
30
+ name: 'type',
31
+ type: 'select',
32
+ label: 'Media Type',
33
+ defaultValue: 'image',
34
+ required: true,
35
+ options: [
36
+ { label: 'Image', value: 'image' },
37
+ { label: 'Video', value: 'video' },
38
+ { label: 'Slideshow', value: 'slideshow' },
39
+ ],
40
+ },
41
+ {
42
+ name: 'image',
43
+ type: 'upload',
44
+ admin: { condition: (_, { type } = {}) => type === 'image' },
45
+ relationTo: imageCollection,
46
+ required: true,
47
+ },
48
+ {
49
+ name: 'video',
50
+ type: 'upload',
51
+ admin: { condition: (_, { type } = {}) => type === 'video' },
52
+ relationTo: videoCollection,
53
+ required: true,
54
+ },
55
+ {
56
+ name: 'poster',
57
+ type: 'upload',
58
+ relationTo: imageCollection,
59
+ label: 'Video Poster Image',
60
+ required: true,
61
+ admin: { condition: (_, { type } = {}) => type === 'video' },
62
+ },
63
+ {
64
+ name: 'images',
65
+ label: 'Images',
66
+ type: 'array',
67
+ labels: { singular: 'Image', plural: 'Images' },
68
+ required: true,
69
+ minRows: 2,
70
+ admin: { condition: (_, { type } = {}) => type === 'slideshow' },
71
+ fields: [
72
+ {
73
+ name: 'img',
74
+ type: 'upload',
75
+ relationTo: imageCollection,
76
+ label: false,
77
+ required: true,
78
+ },
79
+ ],
80
+ },
81
+ ];
82
+ /**
83
+ * The WYSIWYG-or-media-picker field set a content block reuses: an optional rich-text body plus,
84
+ * unless `disableMedia`, an image/video/slideshow picker switch.
85
+ *
86
+ * ```ts
87
+ * mediaContentFields({ editor, imageCollection: 'images', videoCollection: 'videos' })
88
+ * ```
89
+ */
90
+ export const mediaContentFields = ({ editor, imageCollection, videoCollection, disableMedia = false, }) => [
91
+ ...buildContentFields(editor),
92
+ ...(disableMedia ? [] : buildMediaPickerFields(imageCollection, videoCollection)),
93
+ ];
94
+ /** `mediaContentFields`, wrapped in an unlabelled group - the shape most blocks actually embed. */
95
+ export const mediaContentGroupField = (options) => {
96
+ const { overrides = {}, ...fieldOptions } = options;
97
+ const base = {
98
+ type: 'group',
99
+ label: false,
100
+ fields: mediaContentFields(fieldOptions),
101
+ };
102
+ return deepMerge(base, overrides);
103
+ };
@@ -0,0 +1,19 @@
1
+ import type { Field, FieldAccess, RelationshipField } from 'payload';
2
+ /**
3
+ * A relationship field to the auth collection, auto-stamped to the creating user: forced on create,
4
+ * and refused on update by field-level access, so ownership can't be reassigned through the admin
5
+ * form OR a direct REST/GraphQL write. Pass your own `access.update` to override that.
6
+ *
7
+ * `readAccess` gates who can read the owner back (default: nobody outside admin write access, i.e.
8
+ * whatever the collection's own field defaults would apply - pass your own, e.g. a "staff" field
9
+ * check, to expose it to more than the record itself needs).
10
+ *
11
+ * ```ts
12
+ * ownerField({ relationTo: 'users' }, { readAccess: staffFieldLevel })
13
+ * ```
14
+ */
15
+ export declare const ownerField: ({ relationTo }: {
16
+ relationTo: RelationshipField["relationTo"];
17
+ }, { readAccess, ...overrides }?: Partial<Omit<RelationshipField, "type" | "relationTo">> & {
18
+ readAccess?: FieldAccess;
19
+ }) => Field;
@@ -0,0 +1,53 @@
1
+ const makeSetOwner = () => {
2
+ const setOwner = ({ req, operation, value }) => {
3
+ // `?? value` rather than `?? null`: a Local API create (a seed, a migration, an import) carries
4
+ // no user, and discarding an explicitly supplied owner there would leave the row unowned.
5
+ if (operation === 'create')
6
+ return req?.user?.id ?? value ?? null;
7
+ return value;
8
+ };
9
+ return setOwner;
10
+ };
11
+ /**
12
+ * A relationship field to the auth collection, auto-stamped to the creating user: forced on create,
13
+ * and refused on update by field-level access, so ownership can't be reassigned through the admin
14
+ * form OR a direct REST/GraphQL write. Pass your own `access.update` to override that.
15
+ *
16
+ * `readAccess` gates who can read the owner back (default: nobody outside admin write access, i.e.
17
+ * whatever the collection's own field defaults would apply - pass your own, e.g. a "staff" field
18
+ * check, to expose it to more than the record itself needs).
19
+ *
20
+ * ```ts
21
+ * ownerField({ relationTo: 'users' }, { readAccess: staffFieldLevel })
22
+ * ```
23
+ */
24
+ export const ownerField = ({ relationTo }, { readAccess, ...overrides } = {}) => {
25
+ const { admin, hooks, access, ...rest } = overrides;
26
+ return {
27
+ name: 'owner',
28
+ type: 'relationship',
29
+ relationTo,
30
+ access: {
31
+ // Field-level update access is what actually refuses a reassignment. `admin.readOnly` only
32
+ // greys the input out in the admin panel; Payload never consults it on a REST or GraphQL
33
+ // write, and the hook's update branch passes the incoming value straight through.
34
+ update: () => false,
35
+ ...(readAccess && { read: readAccess }),
36
+ ...access,
37
+ },
38
+ admin: {
39
+ position: 'sidebar',
40
+ readOnly: true,
41
+ description: 'User who created this. Set automatically.',
42
+ ...admin,
43
+ },
44
+ hooks: {
45
+ beforeChange: [makeSetOwner()],
46
+ ...hooks,
47
+ },
48
+ ...rest,
49
+ // Payload's `Field` is a discriminated union; spreading `overrides` over a literal widens it
50
+ // past any single branch, so the cast reshapes a literal this function authored rather than
51
+ // narrowing unknown data.
52
+ };
53
+ };
@@ -0,0 +1,12 @@
1
+ import type { TextField } from 'payload';
2
+ import { type ComponentFieldOverrides } from '../internal/component-field.js';
3
+ /**
4
+ * A text field rendered by a custom phone-input admin component. `component` is the path Payload
5
+ * resolves for `admin.components.Field` - this package ships no UI, so the consumer's own
6
+ * component is a required parameter, not a default.
7
+ *
8
+ * ```ts
9
+ * phoneField('@/components/phone/Phone', { name: 'phone', required: true })
10
+ * ```
11
+ */
12
+ export declare const phoneField: (component: string, overrides?: ComponentFieldOverrides<TextField>) => TextField;
@@ -0,0 +1,11 @@
1
+ import { componentField } from '../internal/component-field.js';
2
+ /**
3
+ * A text field rendered by a custom phone-input admin component. `component` is the path Payload
4
+ * resolves for `admin.components.Field` - this package ships no UI, so the consumer's own
5
+ * component is a required parameter, not a default.
6
+ *
7
+ * ```ts
8
+ * phoneField('@/components/phone/Phone', { name: 'phone', required: true })
9
+ * ```
10
+ */
11
+ export const phoneField = (component, overrides) => componentField('text', component, { name: 'phone', label: 'Phone' }, overrides);