@payloadcms/plugin-nested-docs 3.0.0-alpha.48 → 3.0.0-alpha.50
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.
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export const createBreadcrumbsField = (relationTo, overrides = {})=>({
|
|
2
2
|
name: 'breadcrumbs',
|
|
3
|
-
localized: true,
|
|
4
3
|
type: 'array',
|
|
4
|
+
localized: true,
|
|
5
5
|
...overrides || {},
|
|
6
6
|
admin: {
|
|
7
7
|
readOnly: true,
|
|
@@ -10,32 +10,32 @@ export const createBreadcrumbsField = (relationTo, overrides = {})=>({
|
|
|
10
10
|
fields: [
|
|
11
11
|
{
|
|
12
12
|
name: 'doc',
|
|
13
|
+
type: 'relationship',
|
|
13
14
|
admin: {
|
|
14
15
|
disabled: true
|
|
15
16
|
},
|
|
16
17
|
maxDepth: 0,
|
|
17
|
-
relationTo
|
|
18
|
-
type: 'relationship'
|
|
18
|
+
relationTo
|
|
19
19
|
},
|
|
20
20
|
{
|
|
21
|
+
type: 'row',
|
|
21
22
|
fields: [
|
|
22
23
|
{
|
|
23
24
|
name: 'url',
|
|
25
|
+
type: 'text',
|
|
24
26
|
admin: {
|
|
25
27
|
width: '50%'
|
|
26
28
|
},
|
|
27
|
-
label: 'URL'
|
|
28
|
-
type: 'text'
|
|
29
|
+
label: 'URL'
|
|
29
30
|
},
|
|
30
31
|
{
|
|
31
32
|
name: 'label',
|
|
33
|
+
type: 'text',
|
|
32
34
|
admin: {
|
|
33
35
|
width: '50%'
|
|
34
|
-
}
|
|
35
|
-
type: 'text'
|
|
36
|
+
}
|
|
36
37
|
}
|
|
37
|
-
]
|
|
38
|
-
type: 'row'
|
|
38
|
+
]
|
|
39
39
|
},
|
|
40
40
|
...overrides?.fields || []
|
|
41
41
|
]
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/fields/breadcrumbs.ts"],"sourcesContent":["import type { ArrayField, Field } from 'payload/types'\n\nexport const createBreadcrumbsField = (\n relationTo: string,\n overrides: Partial<ArrayField> = {},\n): Field => ({\n name: 'breadcrumbs',\n
|
|
1
|
+
{"version":3,"sources":["../../src/fields/breadcrumbs.ts"],"sourcesContent":["import type { ArrayField, Field } from 'payload/types'\n\nexport const createBreadcrumbsField = (\n relationTo: string,\n overrides: Partial<ArrayField> = {},\n): Field => ({\n name: 'breadcrumbs',\n type: 'array',\n localized: true,\n ...(overrides || {}),\n admin: {\n readOnly: true,\n ...(overrides?.admin || {}),\n },\n fields: [\n {\n name: 'doc',\n type: 'relationship',\n admin: {\n disabled: true,\n },\n maxDepth: 0,\n relationTo,\n },\n {\n type: 'row',\n fields: [\n {\n name: 'url',\n type: 'text',\n admin: {\n width: '50%',\n },\n label: 'URL',\n },\n {\n name: 'label',\n type: 'text',\n admin: {\n width: '50%',\n },\n },\n ],\n },\n ...(overrides?.fields || []),\n ],\n})\n\nexport default createBreadcrumbsField\n"],"names":["createBreadcrumbsField","relationTo","overrides","name","type","localized","admin","readOnly","fields","disabled","maxDepth","width","label"],"mappings":"AAEA,OAAO,MAAMA,yBAAyB,CACpCC,YACAC,YAAiC,CAAC,CAAC,GACxB,CAAA;QACXC,MAAM;QACNC,MAAM;QACNC,WAAW;QACX,GAAIH,aAAa,CAAC,CAAC;QACnBI,OAAO;YACLC,UAAU;YACV,GAAIL,WAAWI,SAAS,CAAC,CAAC;QAC5B;QACAE,QAAQ;YACN;gBACEL,MAAM;gBACNC,MAAM;gBACNE,OAAO;oBACLG,UAAU;gBACZ;gBACAC,UAAU;gBACVT;YACF;YACA;gBACEG,MAAM;gBACNI,QAAQ;oBACN;wBACEL,MAAM;wBACNC,MAAM;wBACNE,OAAO;4BACLK,OAAO;wBACT;wBACAC,OAAO;oBACT;oBACA;wBACET,MAAM;wBACNC,MAAM;wBACNE,OAAO;4BACLK,OAAO;wBACT;oBACF;iBACD;YACH;eACIT,WAAWM,UAAU,EAAE;SAC5B;IACH,CAAA,EAAE;AAEF,eAAeR,uBAAsB"}
|
package/dist/fields/parent.js
CHANGED
|
@@ -6,9 +6,9 @@ export const createParentField = (relationTo, overrides)=>({
|
|
|
6
6
|
},
|
|
7
7
|
// filterOptions are assigned dynamically based on the pluginConfig
|
|
8
8
|
// filterOptions: parentFilterOptions(),
|
|
9
|
+
type: 'relationship',
|
|
9
10
|
maxDepth: 1,
|
|
10
11
|
relationTo,
|
|
11
|
-
type: 'relationship',
|
|
12
12
|
...overrides || {}
|
|
13
13
|
});
|
|
14
14
|
export default createParentField;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/fields/parent.ts"],"sourcesContent":["import type { SingleRelationshipField } from 'payload/types'\n\nexport const createParentField = (\n relationTo: string,\n overrides?: Partial<\n SingleRelationshipField & {\n hasMany: false\n }\n >,\n): SingleRelationshipField => ({\n name: 'parent',\n admin: {\n position: 'sidebar',\n ...(overrides?.admin || {}),\n },\n // filterOptions are assigned dynamically based on the pluginConfig\n // filterOptions: parentFilterOptions(),\n maxDepth: 1,\n relationTo,\n
|
|
1
|
+
{"version":3,"sources":["../../src/fields/parent.ts"],"sourcesContent":["import type { SingleRelationshipField } from 'payload/types'\n\nexport const createParentField = (\n relationTo: string,\n overrides?: Partial<\n SingleRelationshipField & {\n hasMany: false\n }\n >,\n): SingleRelationshipField => ({\n name: 'parent',\n admin: {\n position: 'sidebar',\n ...(overrides?.admin || {}),\n },\n // filterOptions are assigned dynamically based on the pluginConfig\n // filterOptions: parentFilterOptions(),\n type: 'relationship',\n maxDepth: 1,\n relationTo,\n ...(overrides || {}),\n})\n\nexport default createParentField\n"],"names":["createParentField","relationTo","overrides","name","admin","position","type","maxDepth"],"mappings":"AAEA,OAAO,MAAMA,oBAAoB,CAC/BC,YACAC,YAK6B,CAAA;QAC7BC,MAAM;QACNC,OAAO;YACLC,UAAU;YACV,GAAIH,WAAWE,SAAS,CAAC,CAAC;QAC5B;QACA,mEAAmE;QACnE,wCAAwC;QACxCE,MAAM;QACNC,UAAU;QACVN;QACA,GAAIC,aAAa,CAAC,CAAC;IACrB,CAAA,EAAE;AAEF,eAAeF,kBAAiB"}
|
package/package.json
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@payloadcms/plugin-nested-docs",
|
|
3
|
-
"version": "3.0.0-alpha.
|
|
3
|
+
"version": "3.0.0-alpha.50",
|
|
4
4
|
"description": "The official Nested Docs plugin for Payload",
|
|
5
|
-
"repository":
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "https://github.com/payloadcms/payload.git",
|
|
8
|
+
"directory": "packages/plugin-nested-docs"
|
|
9
|
+
},
|
|
6
10
|
"license": "MIT",
|
|
7
11
|
"homepage": "https://payloadcms.com",
|
|
8
12
|
"author": "Payload CMS, Inc.",
|
|
@@ -11,14 +15,17 @@
|
|
|
11
15
|
"type": "module",
|
|
12
16
|
"devDependencies": {
|
|
13
17
|
"@payloadcms/eslint-config": "1.1.1",
|
|
14
|
-
"payload": "3.0.0-alpha.
|
|
18
|
+
"payload": "3.0.0-alpha.50"
|
|
15
19
|
},
|
|
16
20
|
"peerDependencies": {
|
|
17
|
-
"payload": "3.0.0-alpha.
|
|
21
|
+
"payload": "3.0.0-alpha.50"
|
|
18
22
|
},
|
|
19
|
-
"exports":
|
|
20
|
-
|
|
21
|
-
|
|
23
|
+
"exports": {
|
|
24
|
+
".": {
|
|
25
|
+
"import": "./dist/index.js",
|
|
26
|
+
"require": "./dist/index.js",
|
|
27
|
+
"types": "./dist/index.d.ts"
|
|
28
|
+
}
|
|
22
29
|
},
|
|
23
30
|
"files": [
|
|
24
31
|
"dist",
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import type { Plugin } from 'payload/config'
|
|
2
|
+
import type { SingleRelationshipField } from 'payload/types'
|
|
3
|
+
|
|
4
|
+
import type { PluginConfig } from './types.js'
|
|
5
|
+
|
|
6
|
+
import createBreadcrumbsField from './fields/breadcrumbs.js'
|
|
7
|
+
import createParentField from './fields/parent.js'
|
|
8
|
+
import parentFilterOptions from './fields/parentFilterOptions.js'
|
|
9
|
+
import resaveChildren from './hooks/resaveChildren.js'
|
|
10
|
+
import resaveSelfAfterCreate from './hooks/resaveSelfAfterCreate.js'
|
|
11
|
+
import populateBreadcrumbs from './utilities/populateBreadcrumbs.js'
|
|
12
|
+
|
|
13
|
+
const nestedDocs =
|
|
14
|
+
(pluginConfig: PluginConfig): Plugin =>
|
|
15
|
+
(config) => ({
|
|
16
|
+
...config,
|
|
17
|
+
collections: (config.collections || []).map((collection) => {
|
|
18
|
+
if (pluginConfig.collections.indexOf(collection.slug) > -1) {
|
|
19
|
+
const fields = [...(collection?.fields || [])]
|
|
20
|
+
|
|
21
|
+
const existingBreadcrumbField = collection.fields.find(
|
|
22
|
+
(field) =>
|
|
23
|
+
'name' in field && field.name === (pluginConfig?.breadcrumbsFieldSlug || 'breadcrumbs'),
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
const existingParentField = collection.fields.find(
|
|
27
|
+
(field) => 'name' in field && field.name === (pluginConfig?.parentFieldSlug || 'parent'),
|
|
28
|
+
) as SingleRelationshipField
|
|
29
|
+
|
|
30
|
+
const defaultFilterOptions = parentFilterOptions(pluginConfig?.breadcrumbsFieldSlug)
|
|
31
|
+
|
|
32
|
+
if (existingParentField) {
|
|
33
|
+
if (!existingParentField.filterOptions) {
|
|
34
|
+
existingParentField.filterOptions = defaultFilterOptions
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (!existingParentField && !pluginConfig.parentFieldSlug) {
|
|
39
|
+
const defaultParentField = createParentField(collection.slug)
|
|
40
|
+
defaultParentField.filterOptions = defaultFilterOptions
|
|
41
|
+
fields.push(defaultParentField)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (!existingBreadcrumbField && !pluginConfig.breadcrumbsFieldSlug) {
|
|
45
|
+
fields.push(createBreadcrumbsField(collection.slug))
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return {
|
|
49
|
+
...collection,
|
|
50
|
+
fields,
|
|
51
|
+
hooks: {
|
|
52
|
+
...(collection.hooks || {}),
|
|
53
|
+
afterChange: [
|
|
54
|
+
resaveChildren(pluginConfig, collection),
|
|
55
|
+
resaveSelfAfterCreate(pluginConfig, collection),
|
|
56
|
+
...(collection?.hooks?.afterChange || []),
|
|
57
|
+
],
|
|
58
|
+
beforeChange: [
|
|
59
|
+
async ({ data, originalDoc, req }) =>
|
|
60
|
+
populateBreadcrumbs(req, pluginConfig, collection, data, originalDoc),
|
|
61
|
+
...(collection?.hooks?.beforeChange || []),
|
|
62
|
+
],
|
|
63
|
+
},
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return collection
|
|
68
|
+
}),
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
export default nestedDocs
|