payload 1.0.27 → 1.0.28
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/CHANGELOG.md +18 -0
- package/dist/admin/components/elements/Status/index.js +1 -1
- package/dist/admin/components/elements/ViewDescription/types.d.ts +1 -1
- package/dist/admin/components/elements/WhereBuilder/index.js +13 -7
- package/dist/admin/components/forms/field-types/Array/index.d.ts +3 -2
- package/dist/admin/components/forms/field-types/Array/index.js +201 -6
- package/dist/admin/components/forms/field-types/Blocks/index.d.ts +3 -2
- package/dist/admin/components/forms/field-types/Blocks/index.js +213 -6
- package/dist/admin/components/forms/field-types/Collapsible/index.js +2 -2
- package/dist/admin/components/forms/field-types/Row/index.js +2 -2
- package/dist/admin/components/forms/field-types/Tabs/index.js +2 -2
- package/dist/admin/components/forms/field-types/getFieldPath.d.ts +2 -0
- package/dist/admin/components/forms/field-types/getFieldPath.js +6 -0
- package/dist/admin/components/forms/field-types/index.d.ts +23 -23
- package/dist/admin/components/utilities/RenderCustomComponent/types.d.ts +2 -2
- package/dist/admin/components/views/collections/List/Cell/field-types/Relationship/index.js +1 -1
- package/dist/auth/operations/local/forgotPassword.js +3 -6
- package/dist/auth/operations/local/login.js +6 -9
- package/dist/auth/operations/local/resetPassword.js +4 -7
- package/dist/auth/operations/local/unlock.js +4 -7
- package/dist/collections/config/types.d.ts +2 -2
- package/dist/collections/dataloader.js +16 -8
- package/dist/collections/operations/local/create.d.ts +2 -2
- package/dist/collections/operations/local/create.js +11 -13
- package/dist/collections/operations/local/find.js +6 -10
- package/dist/collections/operations/local/findByID.js +6 -10
- package/dist/collections/operations/local/findVersionByID.js +6 -9
- package/dist/config/types.d.ts +13 -13
- package/dist/fields/config/sanitize.js +3 -3
- package/dist/fields/config/schema.js +3 -3
- package/dist/fields/config/types.d.ts +9 -9
- package/dist/fields/validations.js +43 -1
- package/dist/globals/config/types.d.ts +1 -1
- package/dist/utilities/getIDType.d.ts +2 -0
- package/dist/utilities/getIDType.js +11 -0
- package/dist/utilities/isValidID.d.ts +1 -0
- package/dist/utilities/isValidID.js +16 -0
- package/docs/access-control/collections.mdx +21 -12
- package/docs/access-control/fields.mdx +5 -3
- package/docs/access-control/globals.mdx +8 -4
- package/docs/access-control/overview.mdx +1 -1
- package/docs/admin/components.mdx +29 -25
- package/docs/admin/customizing-css.mdx +2 -2
- package/docs/admin/overview.mdx +2 -2
- package/docs/admin/webpack.mdx +8 -7
- package/docs/authentication/config.mdx +14 -9
- package/docs/authentication/operations.mdx +22 -22
- package/docs/authentication/overview.mdx +8 -6
- package/docs/authentication/using-middleware.mdx +1 -1
- package/docs/configuration/collections.mdx +11 -7
- package/docs/configuration/globals.mdx +9 -5
- package/docs/configuration/localization.mdx +33 -31
- package/docs/configuration/overview.mdx +4 -7
- package/docs/email/overview.mdx +11 -7
- package/docs/fields/array.mdx +6 -5
- package/docs/fields/blocks.mdx +6 -4
- package/docs/fields/checkbox.mdx +6 -5
- package/docs/fields/code.mdx +6 -5
- package/docs/fields/collapsible.mdx +6 -5
- package/docs/fields/date.mdx +6 -5
- package/docs/fields/email.mdx +6 -5
- package/docs/fields/group.mdx +6 -5
- package/docs/fields/number.mdx +6 -5
- package/docs/fields/overview.mdx +40 -38
- package/docs/fields/point.mdx +6 -4
- package/docs/fields/radio.mdx +5 -3
- package/docs/fields/relationship.mdx +21 -21
- package/docs/fields/rich-text.mdx +9 -7
- package/docs/fields/row.mdx +5 -3
- package/docs/fields/select.mdx +4 -3
- package/docs/fields/tabs.mdx +5 -3
- package/docs/fields/text.mdx +5 -3
- package/docs/fields/textarea.mdx +5 -3
- package/docs/fields/ui.mdx +5 -3
- package/docs/fields/upload.mdx +5 -3
- package/docs/getting-started/concepts.mdx +1 -1
- package/docs/graphql/extending.mdx +1 -1
- package/docs/graphql/overview.mdx +8 -4
- package/docs/hooks/collections.mdx +62 -36
- package/docs/hooks/fields.mdx +5 -3
- package/docs/hooks/globals.mdx +25 -17
- package/docs/local-api/overview.mdx +27 -4
- package/docs/plugins/overview.mdx +3 -4
- package/docs/production/deployment.mdx +1 -1
- package/docs/queries/overview.mdx +4 -2
- package/docs/queries/pagination.mdx +1 -1
- package/docs/rest-api/overview.mdx +4 -2
- package/docs/upload/overview.mdx +35 -29
- package/docs/versions/autosave.mdx +4 -2
- package/docs/versions/drafts.mdx +8 -4
- package/docs/versions/overview.mdx +1 -1
- package/package.json +1 -1
- package/types.d.ts +21 -0
- package/dist/admin/components/forms/field-types/Array/Array.d.ts +0 -5
- package/dist/admin/components/forms/field-types/Array/Array.js +0 -201
- package/dist/admin/components/forms/field-types/Blocks/Blocks.d.ts +0 -5
- package/dist/admin/components/forms/field-types/Blocks/Blocks.js +0 -213
package/docs/fields/blocks.mdx
CHANGED
|
@@ -72,8 +72,10 @@ The Admin panel provides each block with a `blockName` field which optionally al
|
|
|
72
72
|
### Example
|
|
73
73
|
|
|
74
74
|
`collections/ExampleCollection.js`
|
|
75
|
-
```
|
|
76
|
-
|
|
75
|
+
```ts
|
|
76
|
+
import { Block, CollectionConfig } from 'payload/types';
|
|
77
|
+
|
|
78
|
+
const QuoteBlock: Block = {
|
|
77
79
|
slug: 'Quote', // required
|
|
78
80
|
imageURL: 'https://google.com/path/to/image.jpg',
|
|
79
81
|
imageAltText: 'A nice thumbnail image to show what this block looks like',
|
|
@@ -90,7 +92,7 @@ const QuoteBlock = {
|
|
|
90
92
|
]
|
|
91
93
|
};
|
|
92
94
|
|
|
93
|
-
const ExampleCollection = {
|
|
95
|
+
const ExampleCollection: CollectionConfig = {
|
|
94
96
|
slug: 'example-collection',
|
|
95
97
|
fields: [
|
|
96
98
|
{
|
|
@@ -111,7 +113,7 @@ const ExampleCollection = {
|
|
|
111
113
|
|
|
112
114
|
As you build your own Block configs, you might want to store them in separate files but retain typing accordingly. To do so, you can import and use Payload's `Block` type:
|
|
113
115
|
|
|
114
|
-
```
|
|
116
|
+
```ts
|
|
115
117
|
import type { Block } from 'payload/types';
|
|
116
118
|
|
|
117
119
|
```
|
package/docs/fields/checkbox.mdx
CHANGED
|
@@ -31,9 +31,11 @@ keywords: checkbox, fields, config, configuration, documentation, Content Manage
|
|
|
31
31
|
|
|
32
32
|
### Example
|
|
33
33
|
|
|
34
|
-
`collections/ExampleCollection.
|
|
35
|
-
```
|
|
36
|
-
{
|
|
34
|
+
`collections/ExampleCollection.ts`
|
|
35
|
+
```ts
|
|
36
|
+
import { CollectionConfig } from 'payload/types';
|
|
37
|
+
|
|
38
|
+
const ExampleCollection: CollectionConfig = {
|
|
37
39
|
slug: 'example-collection',
|
|
38
40
|
fields: [
|
|
39
41
|
{
|
|
@@ -43,6 +45,5 @@ keywords: checkbox, fields, config, configuration, documentation, Content Manage
|
|
|
43
45
|
defaultValue: false,
|
|
44
46
|
}
|
|
45
47
|
]
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
+
};
|
|
48
49
|
```
|
package/docs/fields/code.mdx
CHANGED
|
@@ -55,9 +55,11 @@ The following `prismjs` plugins are imported, enabling the `language` property t
|
|
|
55
55
|
|
|
56
56
|
### Example
|
|
57
57
|
|
|
58
|
-
`collections/ExampleCollection.
|
|
59
|
-
```
|
|
60
|
-
{
|
|
58
|
+
`collections/ExampleCollection.ts
|
|
59
|
+
```ts
|
|
60
|
+
import { CollectionConfig } from 'payload/types';
|
|
61
|
+
|
|
62
|
+
const ExampleCollection: CollectionConfig = {
|
|
61
63
|
slug: 'example-collection',
|
|
62
64
|
fields: [
|
|
63
65
|
{
|
|
@@ -69,6 +71,5 @@ The following `prismjs` plugins are imported, enabling the `language` property t
|
|
|
69
71
|
}
|
|
70
72
|
}
|
|
71
73
|
]
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
+
};
|
|
74
75
|
```
|
|
@@ -22,9 +22,11 @@ keywords: row, fields, config, configuration, documentation, Content Management
|
|
|
22
22
|
|
|
23
23
|
### Example
|
|
24
24
|
|
|
25
|
-
`collections/ExampleCollection.
|
|
26
|
-
```
|
|
27
|
-
{
|
|
25
|
+
`collections/ExampleCollection.ts`
|
|
26
|
+
```ts
|
|
27
|
+
import { CollectionConfig } from 'payload/types';
|
|
28
|
+
|
|
29
|
+
const ExampleCollection: CollectionConfig = {
|
|
28
30
|
slug: 'example-collection',
|
|
29
31
|
fields: [
|
|
30
32
|
{
|
|
@@ -39,6 +41,5 @@ keywords: row, fields, config, configuration, documentation, Content Management
|
|
|
39
41
|
],
|
|
40
42
|
}
|
|
41
43
|
]
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
+
};
|
|
44
45
|
```
|
package/docs/fields/date.mdx
CHANGED
|
@@ -55,10 +55,12 @@ Common use cases for customizing the `date` property are to restrict your field
|
|
|
55
55
|
|
|
56
56
|
### Example
|
|
57
57
|
|
|
58
|
-
`collections/ExampleCollection.
|
|
58
|
+
`collections/ExampleCollection.ts`
|
|
59
59
|
|
|
60
|
-
```
|
|
61
|
-
{
|
|
60
|
+
```ts
|
|
61
|
+
import { CollectionConfig } from 'payload/types';
|
|
62
|
+
|
|
63
|
+
const ExampleCollection: CollectionConfig = {
|
|
62
64
|
slug: 'example-collection',
|
|
63
65
|
fields: [
|
|
64
66
|
{
|
|
@@ -74,6 +76,5 @@ Common use cases for customizing the `date` property are to restrict your field
|
|
|
74
76
|
}
|
|
75
77
|
}
|
|
76
78
|
]
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
+
};
|
|
79
80
|
```
|
package/docs/fields/email.mdx
CHANGED
|
@@ -44,9 +44,11 @@ Set this property to a string that will be used for browser autocomplete.
|
|
|
44
44
|
|
|
45
45
|
### Example
|
|
46
46
|
|
|
47
|
-
`collections/ExampleCollection.
|
|
48
|
-
```
|
|
49
|
-
{
|
|
47
|
+
`collections/ExampleCollection.ts`
|
|
48
|
+
```ts
|
|
49
|
+
import { CollectionConfig } from 'payload/types';
|
|
50
|
+
|
|
51
|
+
const ExampleCollection: CollectionConfig = {
|
|
50
52
|
slug: 'example-collection',
|
|
51
53
|
fields: [
|
|
52
54
|
{
|
|
@@ -56,6 +58,5 @@ Set this property to a string that will be used for browser autocomplete.
|
|
|
56
58
|
required: true,
|
|
57
59
|
}
|
|
58
60
|
]
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
+
};
|
|
61
62
|
```
|
package/docs/fields/group.mdx
CHANGED
|
@@ -39,9 +39,11 @@ Set this property to `true` to hide this field's gutter within the admin panel.
|
|
|
39
39
|
|
|
40
40
|
### Example
|
|
41
41
|
|
|
42
|
-
`collections/ExampleCollection.
|
|
43
|
-
```
|
|
44
|
-
{
|
|
42
|
+
`collections/ExampleCollection.ts`
|
|
43
|
+
```ts
|
|
44
|
+
import { CollectionConfig } from 'payload/types';
|
|
45
|
+
|
|
46
|
+
const ExampleCollection: CollectionConfig = {
|
|
45
47
|
slug: 'example-collection',
|
|
46
48
|
fields: [
|
|
47
49
|
{
|
|
@@ -65,6 +67,5 @@ Set this property to `true` to hide this field's gutter within the admin panel.
|
|
|
65
67
|
],
|
|
66
68
|
}
|
|
67
69
|
]
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
+
};
|
|
70
71
|
```
|
package/docs/fields/number.mdx
CHANGED
|
@@ -50,9 +50,11 @@ Set this property to a string that will be used for browser autocomplete.
|
|
|
50
50
|
|
|
51
51
|
### Example
|
|
52
52
|
|
|
53
|
-
`collections/ExampleCollection.
|
|
54
|
-
```
|
|
55
|
-
{
|
|
53
|
+
`collections/ExampleCollection.ts`
|
|
54
|
+
```ts
|
|
55
|
+
import { CollectionConfig } from 'payload/types';
|
|
56
|
+
|
|
57
|
+
const ExampleCollection: CollectionConfig = {
|
|
56
58
|
slug: 'example-collection',
|
|
57
59
|
fields: [
|
|
58
60
|
{
|
|
@@ -64,6 +66,5 @@ Set this property to a string that will be used for browser autocomplete.
|
|
|
64
66
|
}
|
|
65
67
|
}
|
|
66
68
|
]
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
+
};
|
|
69
70
|
```
|
package/docs/fields/overview.mdx
CHANGED
|
@@ -16,8 +16,10 @@ Fields are defined as an array on Collections and Globals via the `fields` key.
|
|
|
16
16
|
The required `type` property on a field determines what values it can accept, how it is presented in the API, and how the field will be rendered in the admin interface.
|
|
17
17
|
|
|
18
18
|
**Simple collection with two fields:**
|
|
19
|
-
```
|
|
20
|
-
|
|
19
|
+
```ts
|
|
20
|
+
import { CollectionConfig } from 'payload/types';
|
|
21
|
+
|
|
22
|
+
const Page: CollectionConfig = {
|
|
21
23
|
slug: 'pages',
|
|
22
24
|
fields: [
|
|
23
25
|
{
|
|
@@ -29,7 +31,7 @@ const Pages = {
|
|
|
29
31
|
type: 'checkbox', // highlight-line
|
|
30
32
|
},
|
|
31
33
|
],
|
|
32
|
-
}
|
|
34
|
+
};
|
|
33
35
|
```
|
|
34
36
|
|
|
35
37
|
### Field types
|
|
@@ -80,8 +82,10 @@ There are two arguments available to custom validation functions.
|
|
|
80
82
|
| `payload` | If the `validate` function is being executed on the server, Payload will be exposed for easily running local operations. |
|
|
81
83
|
|
|
82
84
|
Example:
|
|
83
|
-
```
|
|
84
|
-
{
|
|
85
|
+
```ts
|
|
86
|
+
import { CollectionConfig } from 'payload/types';
|
|
87
|
+
|
|
88
|
+
const Orders: CollectionConfig = {
|
|
85
89
|
slug: 'orders',
|
|
86
90
|
fields: [
|
|
87
91
|
{
|
|
@@ -101,27 +105,27 @@ Example:
|
|
|
101
105
|
},
|
|
102
106
|
},
|
|
103
107
|
],
|
|
104
|
-
}
|
|
108
|
+
};
|
|
105
109
|
```
|
|
106
110
|
|
|
107
111
|
When supplying a field `validate` function, Payload will use yours in place of the default. To make use of the default field validation in your custom logic you can import, call and return the result as needed.
|
|
108
112
|
|
|
109
113
|
For example:
|
|
110
|
-
```
|
|
114
|
+
```ts
|
|
111
115
|
import { text } from 'payload/fields/validations';
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
}
|
|
116
|
+
|
|
117
|
+
const field: Field = {
|
|
118
|
+
name: 'notBad',
|
|
119
|
+
type: 'text',
|
|
120
|
+
validate: (val, args) => {
|
|
121
|
+
if (val === 'bad') {
|
|
122
|
+
return 'This cannot be "bad"';
|
|
123
|
+
}
|
|
124
|
+
// highlight-start
|
|
125
|
+
return text(val, args);
|
|
126
|
+
// highlight-end
|
|
127
|
+
},
|
|
128
|
+
};
|
|
125
129
|
```
|
|
126
130
|
|
|
127
131
|
### Customizable ID
|
|
@@ -131,7 +135,7 @@ Users are then required to provide a custom ID value when creating a record thro
|
|
|
131
135
|
Valid ID types are `number` and `text`.
|
|
132
136
|
|
|
133
137
|
Example:
|
|
134
|
-
```
|
|
138
|
+
```ts
|
|
135
139
|
{
|
|
136
140
|
fields: [
|
|
137
141
|
{
|
|
@@ -174,7 +178,7 @@ The `condition` function should return a boolean that will control if the field
|
|
|
174
178
|
|
|
175
179
|
**Example:**
|
|
176
180
|
|
|
177
|
-
```
|
|
181
|
+
```ts
|
|
178
182
|
{
|
|
179
183
|
fields: [
|
|
180
184
|
{
|
|
@@ -212,21 +216,21 @@ Functions are called with an optional argument object containing:
|
|
|
212
216
|
|
|
213
217
|
Here is an example of a defaultValue function that uses both:
|
|
214
218
|
|
|
215
|
-
```
|
|
219
|
+
```ts
|
|
216
220
|
const translation: {
|
|
217
|
-
|
|
218
|
-
|
|
221
|
+
en: 'Written by',
|
|
222
|
+
es: 'Escrito por',
|
|
219
223
|
};
|
|
220
224
|
|
|
221
225
|
const field = {
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
226
|
+
name: 'attribution',
|
|
227
|
+
type: 'text',
|
|
228
|
+
admin: {
|
|
229
|
+
// highlight-start
|
|
230
|
+
defaultValue: ({ user, locale }) => (`${translation[locale]} ${user.name}`)
|
|
231
|
+
// highlight-end
|
|
232
|
+
}
|
|
233
|
+
};
|
|
230
234
|
```
|
|
231
235
|
|
|
232
236
|
<Banner type="success">
|
|
@@ -244,7 +248,7 @@ As shown above, you can simply provide a string that will show by the field, but
|
|
|
244
248
|
|
|
245
249
|
**Function Example:**
|
|
246
250
|
|
|
247
|
-
```
|
|
251
|
+
```ts
|
|
248
252
|
{
|
|
249
253
|
fields: [
|
|
250
254
|
{
|
|
@@ -262,7 +266,7 @@ As shown above, you can simply provide a string that will show by the field, but
|
|
|
262
266
|
This example will display the number of characters allowed as the user types.
|
|
263
267
|
|
|
264
268
|
**Component Example:**
|
|
265
|
-
```
|
|
269
|
+
```ts
|
|
266
270
|
{
|
|
267
271
|
fields: [
|
|
268
272
|
{
|
|
@@ -289,10 +293,8 @@ This component will count the number of characters entered.
|
|
|
289
293
|
|
|
290
294
|
You can import the internal Payload `Field` type as well as other common field types as follows:
|
|
291
295
|
|
|
292
|
-
```
|
|
296
|
+
```ts
|
|
293
297
|
import type {
|
|
294
298
|
Field,
|
|
295
|
-
Validate,
|
|
296
|
-
Condition,
|
|
297
299
|
} from 'payload/types';
|
|
298
300
|
```
|
package/docs/fields/point.mdx
CHANGED
|
@@ -35,9 +35,11 @@ The data structure in the database matches the GeoJSON structure to represent po
|
|
|
35
35
|
|
|
36
36
|
### Example
|
|
37
37
|
|
|
38
|
-
`collections/ExampleCollection.
|
|
39
|
-
```
|
|
40
|
-
{
|
|
38
|
+
`collections/ExampleCollection.ts`
|
|
39
|
+
```ts
|
|
40
|
+
import { CollectionConfig } from 'payload/types';
|
|
41
|
+
|
|
42
|
+
const ExampleCollection: CollectionConfig = {
|
|
41
43
|
slug: 'example-collection',
|
|
42
44
|
fields: [
|
|
43
45
|
{
|
|
@@ -46,7 +48,7 @@ The data structure in the database matches the GeoJSON structure to represent po
|
|
|
46
48
|
label: 'Location',
|
|
47
49
|
},
|
|
48
50
|
]
|
|
49
|
-
}
|
|
51
|
+
};
|
|
50
52
|
```
|
|
51
53
|
|
|
52
54
|
### Querying
|
package/docs/fields/radio.mdx
CHANGED
|
@@ -45,9 +45,11 @@ The `layout` property allows for the radio group to be styled as a horizonally o
|
|
|
45
45
|
|
|
46
46
|
### Example
|
|
47
47
|
|
|
48
|
-
`collections/ExampleCollection.
|
|
49
|
-
```
|
|
50
|
-
{
|
|
48
|
+
`collections/ExampleCollection.ts`
|
|
49
|
+
```ts
|
|
50
|
+
import { CollectionConfig } from 'payload/types';
|
|
51
|
+
|
|
52
|
+
const ExampleCollection: CollectionConfig = {
|
|
51
53
|
slug: 'example-collection',
|
|
52
54
|
fields: [
|
|
53
55
|
{
|
|
@@ -69,26 +69,26 @@ The `filterOptions` property can either be a `Where` query directly, or a functi
|
|
|
69
69
|
|
|
70
70
|
**Example:**
|
|
71
71
|
|
|
72
|
-
```
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
}
|
|
72
|
+
```ts
|
|
73
|
+
const relationshipField = {
|
|
74
|
+
name: 'purchase',
|
|
75
|
+
type: 'relationship',
|
|
76
|
+
relationTo: ['products', 'services'],
|
|
77
|
+
filterOptions: ({ relationTo, siblingData }) => {
|
|
78
|
+
// returns a Where query dynamically by the type of relationship
|
|
79
|
+
if (relationTo === 'products') {
|
|
80
|
+
return {
|
|
81
|
+
'stock': { is_greater_than: siblingData.quantity }
|
|
83
82
|
}
|
|
83
|
+
}
|
|
84
84
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
}
|
|
85
|
+
if (relationTo === 'services') {
|
|
86
|
+
return {
|
|
87
|
+
'isAvailable': { equals: true }
|
|
89
88
|
}
|
|
90
|
-
}
|
|
91
|
-
}
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
};
|
|
92
92
|
```
|
|
93
93
|
|
|
94
94
|
You can learn more about writing queries [here](/docs/queries/overview).
|
|
@@ -106,7 +106,7 @@ Given the variety of options possible within the `relationship` field type, the
|
|
|
106
106
|
|
|
107
107
|
The most simple pattern of a relationship is to use `hasMany: false` with a `relationTo` that allows for only one type of collection.
|
|
108
108
|
|
|
109
|
-
```
|
|
109
|
+
```ts
|
|
110
110
|
{
|
|
111
111
|
slug: 'example-collection',
|
|
112
112
|
fields: [
|
|
@@ -137,7 +137,7 @@ When querying documents in this collection via REST API, you could query as foll
|
|
|
137
137
|
|
|
138
138
|
Also known as **dynamic references**, in this configuration, the `relationTo` field is an array of Collection slugs that tells Payload which Collections are valid to reference.
|
|
139
139
|
|
|
140
|
-
```
|
|
140
|
+
```ts
|
|
141
141
|
{
|
|
142
142
|
slug: 'example-collection',
|
|
143
143
|
fields: [
|
|
@@ -176,7 +176,7 @@ This query would return only documents that have an owner relationship to organi
|
|
|
176
176
|
|
|
177
177
|
The `hasMany` tells Payload that there may be more than one collection saved to the field.
|
|
178
178
|
|
|
179
|
-
```
|
|
179
|
+
```ts
|
|
180
180
|
{
|
|
181
181
|
slug: 'example-collection',
|
|
182
182
|
fields: [
|
|
@@ -204,7 +204,7 @@ When querying documents, the format does not change for arrays:
|
|
|
204
204
|
|
|
205
205
|
#### Has Many - Polymorphic
|
|
206
206
|
|
|
207
|
-
```
|
|
207
|
+
```ts
|
|
208
208
|
{
|
|
209
209
|
slug: 'example-collection',
|
|
210
210
|
fields: [
|
|
@@ -126,9 +126,11 @@ Custom `Leaf` objects follow a similar pattern but require you to define the `Le
|
|
|
126
126
|
|
|
127
127
|
### Example
|
|
128
128
|
|
|
129
|
-
`collections/ExampleCollection.
|
|
130
|
-
```
|
|
131
|
-
{
|
|
129
|
+
`collections/ExampleCollection.ts`
|
|
130
|
+
```ts
|
|
131
|
+
import { CollectionConfig } from 'payload/types';
|
|
132
|
+
|
|
133
|
+
const ExampleCollection: CollectionConfig = {
|
|
132
134
|
slug: 'example-collection',
|
|
133
135
|
fields: [
|
|
134
136
|
{
|
|
@@ -178,7 +180,7 @@ Custom `Leaf` objects follow a similar pattern but require you to define the `Le
|
|
|
178
180
|
}
|
|
179
181
|
}
|
|
180
182
|
]
|
|
181
|
-
}
|
|
183
|
+
};
|
|
182
184
|
```
|
|
183
185
|
|
|
184
186
|
For more examples regarding how to define your own elements and leaves, check out the example [`RichText` field](https://github.com/payloadcms/public-demo/blob/master/src/fields/hero.ts) within the Public Demo source code.
|
|
@@ -187,7 +189,7 @@ For more examples regarding how to define your own elements and leaves, check ou
|
|
|
187
189
|
|
|
188
190
|
As the Rich Text field saves its content in a JSON format, you'll need to render it as HTML yourself. Here is an example for how to generate JSX / HTML from Rich Text content:
|
|
189
191
|
|
|
190
|
-
```
|
|
192
|
+
```ts
|
|
191
193
|
import React, { Fragment } from 'react';
|
|
192
194
|
import escapeHTML from 'escape-html';
|
|
193
195
|
import { Text } from 'slate';
|
|
@@ -308,7 +310,7 @@ If you want to utilize this functionality within your own custom elements, you c
|
|
|
308
310
|
|
|
309
311
|
`customLargeBodyElement.js`:
|
|
310
312
|
|
|
311
|
-
```
|
|
313
|
+
```ts
|
|
312
314
|
import Button from './Button';
|
|
313
315
|
import Element from './Element';
|
|
314
316
|
import withLargeBody from './plugin';
|
|
@@ -338,7 +340,7 @@ The plugin itself extends Payload's built-in `shouldBreakOutOnEnter` Slate funct
|
|
|
338
340
|
|
|
339
341
|
If you are building your own custom Rich Text elements or leaves, you may benefit from importing the following types:
|
|
340
342
|
|
|
341
|
-
```
|
|
343
|
+
```ts
|
|
342
344
|
import type {
|
|
343
345
|
RichTextCustomElement,
|
|
344
346
|
RichTextCustomLeaf,
|
package/docs/fields/row.mdx
CHANGED
|
@@ -21,9 +21,11 @@ keywords: row, fields, config, configuration, documentation, Content Management
|
|
|
21
21
|
|
|
22
22
|
### Example
|
|
23
23
|
|
|
24
|
-
`collections/ExampleCollection.
|
|
25
|
-
```
|
|
26
|
-
{
|
|
24
|
+
`collections/ExampleCollection.ts`
|
|
25
|
+
```ts
|
|
26
|
+
import { CollectionConfig } from 'payload/types';
|
|
27
|
+
|
|
28
|
+
const ExampleCollection: CollectionConfig = {
|
|
27
29
|
slug: 'example-collection',
|
|
28
30
|
fields: [
|
|
29
31
|
{
|
package/docs/fields/select.mdx
CHANGED
|
@@ -57,10 +57,11 @@ Set to `true` if you'd like this field to be sortable within the Admin UI using
|
|
|
57
57
|
|
|
58
58
|
### Example
|
|
59
59
|
|
|
60
|
-
`collections/ExampleCollection.
|
|
60
|
+
`collections/ExampleCollection.ts`
|
|
61
|
+
```ts
|
|
62
|
+
import { CollectionConfig } from 'payload/types';
|
|
61
63
|
|
|
62
|
-
|
|
63
|
-
{
|
|
64
|
+
const ExampleCollection: CollectionConfig = {
|
|
64
65
|
slug: 'example-collection',
|
|
65
66
|
fields: [
|
|
66
67
|
{
|
package/docs/fields/tabs.mdx
CHANGED
|
@@ -34,9 +34,11 @@ Each tab has its own required `label` and `fields` array. You can also optionall
|
|
|
34
34
|
|
|
35
35
|
### Example
|
|
36
36
|
|
|
37
|
-
`collections/ExampleCollection.
|
|
38
|
-
```
|
|
39
|
-
{
|
|
37
|
+
`collections/ExampleCollection.ts`
|
|
38
|
+
```ts
|
|
39
|
+
import { CollectionConfig } from 'payload/types';
|
|
40
|
+
|
|
41
|
+
const ExampleCollection: CollectionConfig = {
|
|
40
42
|
slug: 'example-collection',
|
|
41
43
|
fields: [
|
|
42
44
|
{
|
package/docs/fields/text.mdx
CHANGED
|
@@ -46,9 +46,11 @@ Set this property to a string that will be used for browser autocomplete.
|
|
|
46
46
|
|
|
47
47
|
### Example
|
|
48
48
|
|
|
49
|
-
`collections/ExampleCollection.
|
|
50
|
-
```
|
|
51
|
-
{
|
|
49
|
+
`collections/ExampleCollection.ts`
|
|
50
|
+
```ts
|
|
51
|
+
import { CollectionConfig } from 'payload/types';
|
|
52
|
+
|
|
53
|
+
const ExampleCollection: CollectionConfig = {
|
|
52
54
|
slug: 'example-collection',
|
|
53
55
|
fields: [
|
|
54
56
|
{
|
package/docs/fields/textarea.mdx
CHANGED
|
@@ -46,9 +46,11 @@ Set this property to a string that will be used for browser autocomplete.
|
|
|
46
46
|
|
|
47
47
|
### Example
|
|
48
48
|
|
|
49
|
-
`collections/ExampleCollection.
|
|
50
|
-
```
|
|
51
|
-
{
|
|
49
|
+
`collections/ExampleCollection.ts`
|
|
50
|
+
```ts
|
|
51
|
+
import { CollectionConfig } from 'payload/types';
|
|
52
|
+
|
|
53
|
+
const ExampleCollection: CollectionConfig = {
|
|
52
54
|
slug: 'example-collection',
|
|
53
55
|
fields: [
|
|
54
56
|
{
|
package/docs/fields/ui.mdx
CHANGED
|
@@ -34,9 +34,11 @@ With this field, you can also inject custom `Cell` components that appear as add
|
|
|
34
34
|
|
|
35
35
|
### Example
|
|
36
36
|
|
|
37
|
-
`collections/ExampleCollection.
|
|
38
|
-
```
|
|
39
|
-
{
|
|
37
|
+
`collections/ExampleCollection.ts`
|
|
38
|
+
```ts
|
|
39
|
+
import { CollectionConfig } from 'payload/types';
|
|
40
|
+
|
|
41
|
+
const ExampleCollection: CollectionConfig = {
|
|
40
42
|
slug: 'example-collection',
|
|
41
43
|
fields: [
|
|
42
44
|
{
|
package/docs/fields/upload.mdx
CHANGED
|
@@ -46,9 +46,11 @@ keywords: upload, images media, fields, config, configuration, documentation, Co
|
|
|
46
46
|
|
|
47
47
|
### Example
|
|
48
48
|
|
|
49
|
-
`collections/ExampleCollection.
|
|
50
|
-
```
|
|
51
|
-
{
|
|
49
|
+
`collections/ExampleCollection.ts`
|
|
50
|
+
```ts
|
|
51
|
+
import { CollectionConfig } from 'payload/types';
|
|
52
|
+
|
|
53
|
+
const ExampleCollection: CollectionConfig = {
|
|
52
54
|
slug: 'example-collection',
|
|
53
55
|
fields: [
|
|
54
56
|
{
|
|
@@ -22,7 +22,7 @@ By default, the Payload config lives in the root folder of your code and is name
|
|
|
22
22
|
A Collection represents a type of content that Payload will store and can contain many documents.
|
|
23
23
|
</Banner>
|
|
24
24
|
|
|
25
|
-
Collections define the shape of your data as well as all functionalities attached to that data. They will contain or many "documents", all corresponding with the same fields and functionalities that you define.
|
|
25
|
+
Collections define the shape of your data as well as all functionalities attached to that data. They will contain one or many "documents", all corresponding with the same fields and functionalities that you define.
|
|
26
26
|
|
|
27
27
|
They can represent anything you can store in a database - for example - pages, posts, users, people, orders, categories, events, customers, transactions, and anything else your app needs.
|
|
28
28
|
|
|
@@ -33,7 +33,7 @@ Both `graphQL.queries` and `graphQL.mutations` functions should return an object
|
|
|
33
33
|
|
|
34
34
|
`payload.config.js`:
|
|
35
35
|
|
|
36
|
-
```
|
|
36
|
+
```ts
|
|
37
37
|
import { buildConfig } from 'payload/config';
|
|
38
38
|
import myCustomQueryResolver from './graphQL/resolvers/myCustomQueryResolver';
|
|
39
39
|
|