@payloadcms/plugin-nested-docs 3.54.0-internal.bdc84f3 → 3.55.0-canary.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/hooks/populateBreadcrumbsBeforeChange.d.ts +4 -0
- package/dist/hooks/populateBreadcrumbsBeforeChange.d.ts.map +1 -0
- package/dist/hooks/populateBreadcrumbsBeforeChange.js +13 -0
- package/dist/hooks/populateBreadcrumbsBeforeChange.js.map +1 -0
- package/dist/hooks/resaveChildren.d.ts +2 -2
- package/dist/hooks/resaveChildren.d.ts.map +1 -1
- package/dist/hooks/resaveChildren.js +15 -18
- package/dist/hooks/resaveChildren.js.map +1 -1
- package/dist/hooks/resaveSelfAfterCreate.d.ts +2 -2
- package/dist/hooks/resaveSelfAfterCreate.d.ts.map +1 -1
- package/dist/hooks/resaveSelfAfterCreate.js +2 -3
- package/dist/hooks/resaveSelfAfterCreate.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -4
- package/dist/index.js.map +1 -1
- package/dist/utilities/formatBreadcrumb.d.ts +15 -3
- package/dist/utilities/formatBreadcrumb.d.ts.map +1 -1
- package/dist/utilities/formatBreadcrumb.js +6 -5
- package/dist/utilities/formatBreadcrumb.js.map +1 -1
- package/dist/utilities/getParents.d.ts +2 -2
- package/dist/utilities/getParents.d.ts.map +1 -1
- package/dist/utilities/getParents.js.map +1 -1
- package/dist/utilities/populateBreadcrumbs.d.ts +14 -3
- package/dist/utilities/populateBreadcrumbs.d.ts.map +1 -1
- package/dist/utilities/populateBreadcrumbs.js +20 -19
- package/dist/utilities/populateBreadcrumbs.js.map +1 -1
- package/package.json +4 -4
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { CollectionBeforeChangeHook } from 'payload';
|
|
2
|
+
import type { NestedDocsPluginConfig } from '../types.js';
|
|
3
|
+
export declare const populateBreadcrumbsBeforeChange: (pluginConfig: NestedDocsPluginConfig) => CollectionBeforeChangeHook;
|
|
4
|
+
//# sourceMappingURL=populateBreadcrumbsBeforeChange.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"populateBreadcrumbsBeforeChange.d.ts","sourceRoot":"","sources":["../../src/hooks/populateBreadcrumbsBeforeChange.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,SAAS,CAAA;AAEzD,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAA;AAIzD,eAAO,MAAM,+BAA+B,iBAC3B,sBAAsB,KAAG,0BAWpC,CAAA"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { populateBreadcrumbs } from '../utilities/populateBreadcrumbs.js';
|
|
2
|
+
export const populateBreadcrumbsBeforeChange = (pluginConfig)=>async ({ collection, data, originalDoc, req })=>populateBreadcrumbs({
|
|
3
|
+
breadcrumbsFieldName: pluginConfig.breadcrumbsFieldSlug,
|
|
4
|
+
collection,
|
|
5
|
+
data,
|
|
6
|
+
generateLabel: pluginConfig.generateLabel,
|
|
7
|
+
generateURL: pluginConfig.generateURL,
|
|
8
|
+
originalDoc,
|
|
9
|
+
parentFieldName: pluginConfig.parentFieldSlug,
|
|
10
|
+
req
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
//# sourceMappingURL=populateBreadcrumbsBeforeChange.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/hooks/populateBreadcrumbsBeforeChange.ts"],"sourcesContent":["import type { CollectionBeforeChangeHook } from 'payload'\n\nimport type { NestedDocsPluginConfig } from '../types.js'\n\nimport { populateBreadcrumbs } from '../utilities/populateBreadcrumbs.js'\n\nexport const populateBreadcrumbsBeforeChange =\n (pluginConfig: NestedDocsPluginConfig): CollectionBeforeChangeHook =>\n async ({ collection, data, originalDoc, req }) =>\n populateBreadcrumbs({\n breadcrumbsFieldName: pluginConfig.breadcrumbsFieldSlug,\n collection,\n data,\n generateLabel: pluginConfig.generateLabel,\n generateURL: pluginConfig.generateURL,\n originalDoc,\n parentFieldName: pluginConfig.parentFieldSlug,\n req,\n })\n"],"names":["populateBreadcrumbs","populateBreadcrumbsBeforeChange","pluginConfig","collection","data","originalDoc","req","breadcrumbsFieldName","breadcrumbsFieldSlug","generateLabel","generateURL","parentFieldName","parentFieldSlug"],"mappings":"AAIA,SAASA,mBAAmB,QAAQ,sCAAqC;AAEzE,OAAO,MAAMC,kCACX,CAACC,eACD,OAAO,EAAEC,UAAU,EAAEC,IAAI,EAAEC,WAAW,EAAEC,GAAG,EAAE,GAC3CN,oBAAoB;YAClBO,sBAAsBL,aAAaM,oBAAoB;YACvDL;YACAC;YACAK,eAAeP,aAAaO,aAAa;YACzCC,aAAaR,aAAaQ,WAAW;YACrCL;YACAM,iBAAiBT,aAAaU,eAAe;YAC7CN;QACF,GAAE"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { CollectionAfterChangeHook
|
|
1
|
+
import type { CollectionAfterChangeHook } from 'payload';
|
|
2
2
|
import type { NestedDocsPluginConfig } from '../types.js';
|
|
3
|
-
export declare const resaveChildren: (pluginConfig: NestedDocsPluginConfig
|
|
3
|
+
export declare const resaveChildren: (pluginConfig: NestedDocsPluginConfig) => CollectionAfterChangeHook;
|
|
4
4
|
//# sourceMappingURL=resaveChildren.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resaveChildren.d.ts","sourceRoot":"","sources":["../../src/hooks/resaveChildren.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"resaveChildren.d.ts","sourceRoot":"","sources":["../../src/hooks/resaveChildren.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,yBAAyB,EAA+B,MAAM,SAAS,CAAA;AAIrF,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAA;AAIzD,eAAO,MAAM,cAAc,iBACV,sBAAsB,KAAG,yBAiGvC,CAAA"}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { APIError, ValidationErrorName } from 'payload';
|
|
2
2
|
import { populateBreadcrumbs } from '../utilities/populateBreadcrumbs.js';
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
3
|
+
export const resaveChildren = (pluginConfig)=>async ({ collection, doc, req })=>{
|
|
4
|
+
if (collection.versions.drafts && doc._status !== 'published') {
|
|
5
|
+
// If the parent is a draft, don't resave children
|
|
6
|
+
return;
|
|
7
|
+
}
|
|
8
|
+
const parentSlug = pluginConfig?.parentFieldSlug || 'parent';
|
|
9
9
|
const initialDraftChildren = await req.payload.find({
|
|
10
10
|
collection: collection.slug,
|
|
11
11
|
depth: 0,
|
|
@@ -49,14 +49,21 @@ const resave = async ({ collection, doc, draft, pluginConfig, req })=>{
|
|
|
49
49
|
return a._status === 'published' ? 1 : -1;
|
|
50
50
|
});
|
|
51
51
|
});
|
|
52
|
-
if (sortedChildren) {
|
|
52
|
+
if (sortedChildren.length) {
|
|
53
53
|
try {
|
|
54
54
|
for (const child of sortedChildren){
|
|
55
55
|
const isDraft = child._status !== 'published';
|
|
56
56
|
await req.payload.update({
|
|
57
57
|
id: child.id,
|
|
58
58
|
collection: collection.slug,
|
|
59
|
-
data: populateBreadcrumbs(
|
|
59
|
+
data: populateBreadcrumbs({
|
|
60
|
+
collection,
|
|
61
|
+
data: child,
|
|
62
|
+
generateLabel: pluginConfig.generateLabel,
|
|
63
|
+
generateURL: pluginConfig.generateURL,
|
|
64
|
+
parentFieldName: pluginConfig.parentFieldSlug,
|
|
65
|
+
req
|
|
66
|
+
}),
|
|
60
67
|
depth: 0,
|
|
61
68
|
draft: isDraft,
|
|
62
69
|
locale: req.locale,
|
|
@@ -71,16 +78,6 @@ const resave = async ({ collection, doc, draft, pluginConfig, req })=>{
|
|
|
71
78
|
}
|
|
72
79
|
}
|
|
73
80
|
}
|
|
74
|
-
}
|
|
75
|
-
};
|
|
76
|
-
export const resaveChildren = (pluginConfig, collection)=>async ({ doc, req })=>{
|
|
77
|
-
await resave({
|
|
78
|
-
collection,
|
|
79
|
-
doc,
|
|
80
|
-
draft: doc._status === 'published' ? false : true,
|
|
81
|
-
pluginConfig,
|
|
82
|
-
req
|
|
83
|
-
});
|
|
84
81
|
return undefined;
|
|
85
82
|
};
|
|
86
83
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/hooks/resaveChildren.ts"],"sourcesContent":["import type {
|
|
1
|
+
{"version":3,"sources":["../../src/hooks/resaveChildren.ts"],"sourcesContent":["import type { CollectionAfterChangeHook, JsonObject, ValidationError } from 'payload'\n\nimport { APIError, ValidationErrorName } from 'payload'\n\nimport type { NestedDocsPluginConfig } from '../types.js'\n\nimport { populateBreadcrumbs } from '../utilities/populateBreadcrumbs.js'\n\nexport const resaveChildren =\n (pluginConfig: NestedDocsPluginConfig): CollectionAfterChangeHook =>\n async ({ collection, doc, req }) => {\n if (collection.versions.drafts && doc._status !== 'published') {\n // If the parent is a draft, don't resave children\n return\n }\n\n const parentSlug = pluginConfig?.parentFieldSlug || 'parent'\n\n const initialDraftChildren = await req.payload.find({\n collection: collection.slug,\n depth: 0,\n draft: true,\n limit: 0,\n locale: req.locale,\n req,\n where: {\n [parentSlug]: {\n equals: doc.id,\n },\n },\n })\n\n const draftChildren = initialDraftChildren.docs.filter((child) => child._status === 'draft')\n\n const publishedChildren = await req.payload.find({\n collection: collection.slug,\n depth: 0,\n draft: false,\n limit: 0,\n locale: req.locale,\n req,\n where: {\n [parentSlug]: {\n equals: doc.id,\n },\n },\n })\n\n const childrenById = [...draftChildren, ...publishedChildren.docs].reduce<\n Record<string, JsonObject[]>\n >((acc, child) => {\n acc[child.id] = acc[child.id] || []\n acc[child.id]!.push(child)\n return acc\n }, {})\n\n const sortedChildren = Object.values(childrenById).flatMap((group: JsonObject[]) => {\n return group.sort((a, b) => {\n if (a.updatedAt !== b.updatedAt) {\n return a.updatedAt > b.updatedAt ? 1 : -1\n }\n return a._status === 'published' ? 1 : -1\n })\n })\n\n if (sortedChildren.length) {\n try {\n for (const child of sortedChildren) {\n const isDraft = child._status !== 'published'\n\n await req.payload.update({\n id: child.id,\n collection: collection.slug,\n data: populateBreadcrumbs({\n collection,\n data: child,\n generateLabel: pluginConfig.generateLabel,\n generateURL: pluginConfig.generateURL,\n parentFieldName: pluginConfig.parentFieldSlug,\n req,\n }),\n depth: 0,\n draft: isDraft,\n locale: req.locale,\n req,\n })\n }\n } catch (err: unknown) {\n req.payload.logger.error(\n `Nested Docs plugin encountered an error while re-saving a child document.`,\n )\n req.payload.logger.error(err)\n\n if (\n (err as ValidationError)?.name === ValidationErrorName &&\n (err as ValidationError)?.data?.errors?.length\n ) {\n throw new APIError(\n 'Could not publish or save changes: One or more children are invalid.',\n 400,\n )\n }\n }\n }\n\n return undefined\n }\n"],"names":["APIError","ValidationErrorName","populateBreadcrumbs","resaveChildren","pluginConfig","collection","doc","req","versions","drafts","_status","parentSlug","parentFieldSlug","initialDraftChildren","payload","find","slug","depth","draft","limit","locale","where","equals","id","draftChildren","docs","filter","child","publishedChildren","childrenById","reduce","acc","push","sortedChildren","Object","values","flatMap","group","sort","a","b","updatedAt","length","isDraft","update","data","generateLabel","generateURL","parentFieldName","err","logger","error","name","errors","undefined"],"mappings":"AAEA,SAASA,QAAQ,EAAEC,mBAAmB,QAAQ,UAAS;AAIvD,SAASC,mBAAmB,QAAQ,sCAAqC;AAEzE,OAAO,MAAMC,iBACX,CAACC,eACD,OAAO,EAAEC,UAAU,EAAEC,GAAG,EAAEC,GAAG,EAAE;QAC7B,IAAIF,WAAWG,QAAQ,CAACC,MAAM,IAAIH,IAAII,OAAO,KAAK,aAAa;YAC7D,kDAAkD;YAClD;QACF;QAEA,MAAMC,aAAaP,cAAcQ,mBAAmB;QAEpD,MAAMC,uBAAuB,MAAMN,IAAIO,OAAO,CAACC,IAAI,CAAC;YAClDV,YAAYA,WAAWW,IAAI;YAC3BC,OAAO;YACPC,OAAO;YACPC,OAAO;YACPC,QAAQb,IAAIa,MAAM;YAClBb;YACAc,OAAO;gBACL,CAACV,WAAW,EAAE;oBACZW,QAAQhB,IAAIiB,EAAE;gBAChB;YACF;QACF;QAEA,MAAMC,gBAAgBX,qBAAqBY,IAAI,CAACC,MAAM,CAAC,CAACC,QAAUA,MAAMjB,OAAO,KAAK;QAEpF,MAAMkB,oBAAoB,MAAMrB,IAAIO,OAAO,CAACC,IAAI,CAAC;YAC/CV,YAAYA,WAAWW,IAAI;YAC3BC,OAAO;YACPC,OAAO;YACPC,OAAO;YACPC,QAAQb,IAAIa,MAAM;YAClBb;YACAc,OAAO;gBACL,CAACV,WAAW,EAAE;oBACZW,QAAQhB,IAAIiB,EAAE;gBAChB;YACF;QACF;QAEA,MAAMM,eAAe;eAAIL;eAAkBI,kBAAkBH,IAAI;SAAC,CAACK,MAAM,CAEvE,CAACC,KAAKJ;YACNI,GAAG,CAACJ,MAAMJ,EAAE,CAAC,GAAGQ,GAAG,CAACJ,MAAMJ,EAAE,CAAC,IAAI,EAAE;YACnCQ,GAAG,CAACJ,MAAMJ,EAAE,CAAC,CAAES,IAAI,CAACL;YACpB,OAAOI;QACT,GAAG,CAAC;QAEJ,MAAME,iBAAiBC,OAAOC,MAAM,CAACN,cAAcO,OAAO,CAAC,CAACC;YAC1D,OAAOA,MAAMC,IAAI,CAAC,CAACC,GAAGC;gBACpB,IAAID,EAAEE,SAAS,KAAKD,EAAEC,SAAS,EAAE;oBAC/B,OAAOF,EAAEE,SAAS,GAAGD,EAAEC,SAAS,GAAG,IAAI,CAAC;gBAC1C;gBACA,OAAOF,EAAE7B,OAAO,KAAK,cAAc,IAAI,CAAC;YAC1C;QACF;QAEA,IAAIuB,eAAeS,MAAM,EAAE;YACzB,IAAI;gBACF,KAAK,MAAMf,SAASM,eAAgB;oBAClC,MAAMU,UAAUhB,MAAMjB,OAAO,KAAK;oBAElC,MAAMH,IAAIO,OAAO,CAAC8B,MAAM,CAAC;wBACvBrB,IAAII,MAAMJ,EAAE;wBACZlB,YAAYA,WAAWW,IAAI;wBAC3B6B,MAAM3C,oBAAoB;4BACxBG;4BACAwC,MAAMlB;4BACNmB,eAAe1C,aAAa0C,aAAa;4BACzCC,aAAa3C,aAAa2C,WAAW;4BACrCC,iBAAiB5C,aAAaQ,eAAe;4BAC7CL;wBACF;wBACAU,OAAO;wBACPC,OAAOyB;wBACPvB,QAAQb,IAAIa,MAAM;wBAClBb;oBACF;gBACF;YACF,EAAE,OAAO0C,KAAc;gBACrB1C,IAAIO,OAAO,CAACoC,MAAM,CAACC,KAAK,CACtB,CAAC,yEAAyE,CAAC;gBAE7E5C,IAAIO,OAAO,CAACoC,MAAM,CAACC,KAAK,CAACF;gBAEzB,IACE,AAACA,KAAyBG,SAASnD,uBAClCgD,KAAyBJ,MAAMQ,QAAQX,QACxC;oBACA,MAAM,IAAI1C,SACR,wEACA;gBAEJ;YACF;QACF;QAEA,OAAOsD;IACT,EAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { CollectionAfterChangeHook
|
|
1
|
+
import type { CollectionAfterChangeHook } from 'payload';
|
|
2
2
|
import type { NestedDocsPluginConfig } from '../types.js';
|
|
3
|
-
export declare const resaveSelfAfterCreate: (pluginConfig: NestedDocsPluginConfig
|
|
3
|
+
export declare const resaveSelfAfterCreate: (pluginConfig: NestedDocsPluginConfig) => CollectionAfterChangeHook;
|
|
4
4
|
//# sourceMappingURL=resaveSelfAfterCreate.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resaveSelfAfterCreate.d.ts","sourceRoot":"","sources":["../../src/hooks/resaveSelfAfterCreate.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,yBAAyB,EAAE,
|
|
1
|
+
{"version":3,"file":"resaveSelfAfterCreate.d.ts","sourceRoot":"","sources":["../../src/hooks/resaveSelfAfterCreate.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,SAAS,CAAA;AAExD,OAAO,KAAK,EAAc,sBAAsB,EAAE,MAAM,aAAa,CAAA;AAKrE,eAAO,MAAM,qBAAqB,iBACjB,sBAAsB,KAAG,yBAgCvC,CAAA"}
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
// This hook automatically re-saves a document after it is created
|
|
2
2
|
// so that we can build its breadcrumbs with the newly created document's ID.
|
|
3
|
-
export const resaveSelfAfterCreate = (pluginConfig
|
|
3
|
+
export const resaveSelfAfterCreate = (pluginConfig)=>async ({ collection, doc, operation, req })=>{
|
|
4
4
|
if (operation !== 'create') {
|
|
5
5
|
return undefined;
|
|
6
6
|
}
|
|
7
7
|
const { locale, payload } = req;
|
|
8
8
|
const breadcrumbSlug = pluginConfig.breadcrumbsFieldSlug || 'breadcrumbs';
|
|
9
9
|
const breadcrumbs = doc[breadcrumbSlug];
|
|
10
|
-
const updateAsDraft = typeof collection.versions === 'object' && collection.versions.drafts && doc._status !== 'published';
|
|
11
10
|
try {
|
|
12
11
|
await payload.update({
|
|
13
12
|
id: doc.id,
|
|
@@ -19,7 +18,7 @@ export const resaveSelfAfterCreate = (pluginConfig, collection)=>async ({ doc, o
|
|
|
19
18
|
})) || []
|
|
20
19
|
},
|
|
21
20
|
depth: 0,
|
|
22
|
-
draft:
|
|
21
|
+
draft: collection.versions.drafts && doc._status !== 'published',
|
|
23
22
|
locale,
|
|
24
23
|
req
|
|
25
24
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/hooks/resaveSelfAfterCreate.ts"],"sourcesContent":["import type { CollectionAfterChangeHook
|
|
1
|
+
{"version":3,"sources":["../../src/hooks/resaveSelfAfterCreate.ts"],"sourcesContent":["import type { CollectionAfterChangeHook } from 'payload'\n\nimport type { Breadcrumb, NestedDocsPluginConfig } from '../types.js'\n\n// This hook automatically re-saves a document after it is created\n// so that we can build its breadcrumbs with the newly created document's ID.\n\nexport const resaveSelfAfterCreate =\n (pluginConfig: NestedDocsPluginConfig): CollectionAfterChangeHook =>\n async ({ collection, doc, operation, req }) => {\n if (operation !== 'create') {\n return undefined\n }\n\n const { locale, payload } = req\n const breadcrumbSlug = pluginConfig.breadcrumbsFieldSlug || 'breadcrumbs'\n const breadcrumbs = doc[breadcrumbSlug] as unknown as Breadcrumb[]\n\n try {\n await payload.update({\n id: doc.id,\n collection: collection.slug,\n data: {\n [breadcrumbSlug]:\n breadcrumbs?.map((crumb, i) => ({\n ...crumb,\n doc: breadcrumbs.length === i + 1 ? doc.id : crumb.doc,\n })) || [],\n },\n depth: 0,\n draft: collection.versions.drafts && doc._status !== 'published',\n locale,\n req,\n })\n } catch (err: unknown) {\n payload.logger.error(\n `Nested Docs plugin has had an error while adding breadcrumbs during document creation.`,\n )\n payload.logger.error(err)\n }\n }\n"],"names":["resaveSelfAfterCreate","pluginConfig","collection","doc","operation","req","undefined","locale","payload","breadcrumbSlug","breadcrumbsFieldSlug","breadcrumbs","update","id","slug","data","map","crumb","i","length","depth","draft","versions","drafts","_status","err","logger","error"],"mappings":"AAIA,kEAAkE;AAClE,6EAA6E;AAE7E,OAAO,MAAMA,wBACX,CAACC,eACD,OAAO,EAAEC,UAAU,EAAEC,GAAG,EAAEC,SAAS,EAAEC,GAAG,EAAE;QACxC,IAAID,cAAc,UAAU;YAC1B,OAAOE;QACT;QAEA,MAAM,EAAEC,MAAM,EAAEC,OAAO,EAAE,GAAGH;QAC5B,MAAMI,iBAAiBR,aAAaS,oBAAoB,IAAI;QAC5D,MAAMC,cAAcR,GAAG,CAACM,eAAe;QAEvC,IAAI;YACF,MAAMD,QAAQI,MAAM,CAAC;gBACnBC,IAAIV,IAAIU,EAAE;gBACVX,YAAYA,WAAWY,IAAI;gBAC3BC,MAAM;oBACJ,CAACN,eAAe,EACdE,aAAaK,IAAI,CAACC,OAAOC,IAAO,CAAA;4BAC9B,GAAGD,KAAK;4BACRd,KAAKQ,YAAYQ,MAAM,KAAKD,IAAI,IAAIf,IAAIU,EAAE,GAAGI,MAAMd,GAAG;wBACxD,CAAA,MAAO,EAAE;gBACb;gBACAiB,OAAO;gBACPC,OAAOnB,WAAWoB,QAAQ,CAACC,MAAM,IAAIpB,IAAIqB,OAAO,KAAK;gBACrDjB;gBACAF;YACF;QACF,EAAE,OAAOoB,KAAc;YACrBjB,QAAQkB,MAAM,CAACC,KAAK,CAClB,CAAC,sFAAsF,CAAC;YAE1FnB,QAAQkB,MAAM,CAACC,KAAK,CAACF;QACvB;IACF,EAAC"}
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAA2B,MAAM,SAAS,CAAA;AAE9D,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAA;AAExD,OAAO,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAA;AAChE,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAA2B,MAAM,SAAS,CAAA;AAE9D,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAA;AAExD,OAAO,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAA;AAChE,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAA;AAKtD,OAAO,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAA;AAEtD,OAAO,EAAE,sBAAsB,EAAE,iBAAiB,EAAE,UAAU,EAAE,CAAA;AAEhE,eAAO,MAAM,gBAAgB,iBACZ,sBAAsB,KAAG,MAsDtC,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { createBreadcrumbsField } from './fields/breadcrumbs.js';
|
|
2
2
|
import { createParentField } from './fields/parent.js';
|
|
3
3
|
import { parentFilterOptions } from './fields/parentFilterOptions.js';
|
|
4
|
+
import { populateBreadcrumbsBeforeChange } from './hooks/populateBreadcrumbsBeforeChange.js';
|
|
4
5
|
import { resaveChildren } from './hooks/resaveChildren.js';
|
|
5
6
|
import { resaveSelfAfterCreate } from './hooks/resaveSelfAfterCreate.js';
|
|
6
7
|
import { getParents } from './utilities/getParents.js';
|
|
7
|
-
import { populateBreadcrumbs } from './utilities/populateBreadcrumbs.js';
|
|
8
8
|
export { createBreadcrumbsField, createParentField, getParents };
|
|
9
9
|
export const nestedDocsPlugin = (pluginConfig)=>(config)=>({
|
|
10
10
|
...config,
|
|
@@ -35,12 +35,12 @@ export const nestedDocsPlugin = (pluginConfig)=>(config)=>({
|
|
|
35
35
|
hooks: {
|
|
36
36
|
...collection.hooks || {},
|
|
37
37
|
afterChange: [
|
|
38
|
-
resaveChildren(pluginConfig
|
|
39
|
-
resaveSelfAfterCreate(pluginConfig
|
|
38
|
+
resaveChildren(pluginConfig),
|
|
39
|
+
resaveSelfAfterCreate(pluginConfig),
|
|
40
40
|
...collection?.hooks?.afterChange || []
|
|
41
41
|
],
|
|
42
42
|
beforeChange: [
|
|
43
|
-
|
|
43
|
+
populateBreadcrumbsBeforeChange(pluginConfig),
|
|
44
44
|
...collection?.hooks?.beforeChange || []
|
|
45
45
|
]
|
|
46
46
|
}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { Plugin, SingleRelationshipField } from 'payload'\n\nimport type { NestedDocsPluginConfig } from './types.js'\n\nimport { createBreadcrumbsField } from './fields/breadcrumbs.js'\nimport { createParentField } from './fields/parent.js'\nimport { parentFilterOptions } from './fields/parentFilterOptions.js'\nimport {
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { Plugin, SingleRelationshipField } from 'payload'\n\nimport type { NestedDocsPluginConfig } from './types.js'\n\nimport { createBreadcrumbsField } from './fields/breadcrumbs.js'\nimport { createParentField } from './fields/parent.js'\nimport { parentFilterOptions } from './fields/parentFilterOptions.js'\nimport { populateBreadcrumbsBeforeChange } from './hooks/populateBreadcrumbsBeforeChange.js'\nimport { resaveChildren } from './hooks/resaveChildren.js'\nimport { resaveSelfAfterCreate } from './hooks/resaveSelfAfterCreate.js'\nimport { getParents } from './utilities/getParents.js'\n\nexport { createBreadcrumbsField, createParentField, getParents }\n\nexport const nestedDocsPlugin =\n (pluginConfig: NestedDocsPluginConfig): Plugin =>\n (config) => ({\n ...config,\n collections: (config.collections || []).map((collection) => {\n if (pluginConfig.collections.indexOf(collection.slug) > -1) {\n const fields = [...(collection?.fields || [])]\n\n const existingBreadcrumbField = collection.fields.find(\n (field) =>\n 'name' in field && field.name === (pluginConfig?.breadcrumbsFieldSlug || 'breadcrumbs'),\n )\n\n const existingParentField = collection.fields.find(\n (field) => 'name' in field && field.name === (pluginConfig?.parentFieldSlug || 'parent'),\n ) as SingleRelationshipField\n\n const defaultFilterOptions = parentFilterOptions(pluginConfig?.breadcrumbsFieldSlug)\n\n if (existingParentField) {\n if (!existingParentField.filterOptions) {\n existingParentField.filterOptions = defaultFilterOptions\n }\n }\n\n if (!existingParentField && !pluginConfig.parentFieldSlug) {\n const defaultParentField = createParentField(collection.slug)\n defaultParentField.filterOptions = defaultFilterOptions\n fields.push(defaultParentField)\n }\n\n if (!existingBreadcrumbField && !pluginConfig.breadcrumbsFieldSlug) {\n fields.push(createBreadcrumbsField(collection.slug))\n }\n\n return {\n ...collection,\n fields,\n hooks: {\n ...(collection.hooks || {}),\n afterChange: [\n resaveChildren(pluginConfig),\n resaveSelfAfterCreate(pluginConfig),\n ...(collection?.hooks?.afterChange || []),\n ],\n beforeChange: [\n populateBreadcrumbsBeforeChange(pluginConfig),\n ...(collection?.hooks?.beforeChange || []),\n ],\n },\n }\n }\n\n return collection\n }),\n })\n"],"names":["createBreadcrumbsField","createParentField","parentFilterOptions","populateBreadcrumbsBeforeChange","resaveChildren","resaveSelfAfterCreate","getParents","nestedDocsPlugin","pluginConfig","config","collections","map","collection","indexOf","slug","fields","existingBreadcrumbField","find","field","name","breadcrumbsFieldSlug","existingParentField","parentFieldSlug","defaultFilterOptions","filterOptions","defaultParentField","push","hooks","afterChange","beforeChange"],"mappings":"AAIA,SAASA,sBAAsB,QAAQ,0BAAyB;AAChE,SAASC,iBAAiB,QAAQ,qBAAoB;AACtD,SAASC,mBAAmB,QAAQ,kCAAiC;AACrE,SAASC,+BAA+B,QAAQ,6CAA4C;AAC5F,SAASC,cAAc,QAAQ,4BAA2B;AAC1D,SAASC,qBAAqB,QAAQ,mCAAkC;AACxE,SAASC,UAAU,QAAQ,4BAA2B;AAEtD,SAASN,sBAAsB,EAAEC,iBAAiB,EAAEK,UAAU,GAAE;AAEhE,OAAO,MAAMC,mBACX,CAACC,eACD,CAACC,SAAY,CAAA;YACX,GAAGA,MAAM;YACTC,aAAa,AAACD,CAAAA,OAAOC,WAAW,IAAI,EAAE,AAAD,EAAGC,GAAG,CAAC,CAACC;gBAC3C,IAAIJ,aAAaE,WAAW,CAACG,OAAO,CAACD,WAAWE,IAAI,IAAI,CAAC,GAAG;oBAC1D,MAAMC,SAAS;2BAAKH,YAAYG,UAAU,EAAE;qBAAE;oBAE9C,MAAMC,0BAA0BJ,WAAWG,MAAM,CAACE,IAAI,CACpD,CAACC,QACC,UAAUA,SAASA,MAAMC,IAAI,KAAMX,CAAAA,cAAcY,wBAAwB,aAAY;oBAGzF,MAAMC,sBAAsBT,WAAWG,MAAM,CAACE,IAAI,CAChD,CAACC,QAAU,UAAUA,SAASA,MAAMC,IAAI,KAAMX,CAAAA,cAAcc,mBAAmB,QAAO;oBAGxF,MAAMC,uBAAuBrB,oBAAoBM,cAAcY;oBAE/D,IAAIC,qBAAqB;wBACvB,IAAI,CAACA,oBAAoBG,aAAa,EAAE;4BACtCH,oBAAoBG,aAAa,GAAGD;wBACtC;oBACF;oBAEA,IAAI,CAACF,uBAAuB,CAACb,aAAac,eAAe,EAAE;wBACzD,MAAMG,qBAAqBxB,kBAAkBW,WAAWE,IAAI;wBAC5DW,mBAAmBD,aAAa,GAAGD;wBACnCR,OAAOW,IAAI,CAACD;oBACd;oBAEA,IAAI,CAACT,2BAA2B,CAACR,aAAaY,oBAAoB,EAAE;wBAClEL,OAAOW,IAAI,CAAC1B,uBAAuBY,WAAWE,IAAI;oBACpD;oBAEA,OAAO;wBACL,GAAGF,UAAU;wBACbG;wBACAY,OAAO;4BACL,GAAIf,WAAWe,KAAK,IAAI,CAAC,CAAC;4BAC1BC,aAAa;gCACXxB,eAAeI;gCACfH,sBAAsBG;mCAClBI,YAAYe,OAAOC,eAAe,EAAE;6BACzC;4BACDC,cAAc;gCACZ1B,gCAAgCK;mCAC5BI,YAAYe,OAAOE,gBAAgB,EAAE;6BAC1C;wBACH;oBACF;gBACF;gBAEA,OAAOjB;YACT;QACF,CAAA,EAAE"}
|
|
@@ -1,4 +1,16 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { Breadcrumb,
|
|
3
|
-
|
|
1
|
+
import type { SanitizedCollectionConfig } from 'payload';
|
|
2
|
+
import type { Breadcrumb, GenerateLabel, GenerateURL } from '../types.js';
|
|
3
|
+
type Args = {
|
|
4
|
+
/**
|
|
5
|
+
* Existing breadcrumb, if any, to base the new breadcrumb on.
|
|
6
|
+
* This ensures that row IDs are maintained across updates, etc.
|
|
7
|
+
*/
|
|
8
|
+
breadcrumb?: Breadcrumb;
|
|
9
|
+
collection: SanitizedCollectionConfig;
|
|
10
|
+
docs: Record<string, unknown>[];
|
|
11
|
+
generateLabel?: GenerateLabel;
|
|
12
|
+
generateURL?: GenerateURL;
|
|
13
|
+
};
|
|
14
|
+
export declare const formatBreadcrumb: ({ breadcrumb, collection, docs, generateLabel, generateURL, }: Args) => Breadcrumb;
|
|
15
|
+
export {};
|
|
4
16
|
//# sourceMappingURL=formatBreadcrumb.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formatBreadcrumb.d.ts","sourceRoot":"","sources":["../../src/utilities/formatBreadcrumb.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"formatBreadcrumb.d.ts","sourceRoot":"","sources":["../../src/utilities/formatBreadcrumb.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,SAAS,CAAA;AAExD,OAAO,KAAK,EAAE,UAAU,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAEzE,KAAK,IAAI,GAAG;IACV;;;OAGG;IACH,UAAU,CAAC,EAAE,UAAU,CAAA;IACvB,UAAU,EAAE,yBAAyB,CAAA;IACrC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAA;IAC/B,aAAa,CAAC,EAAE,aAAa,CAAA;IAC7B,WAAW,CAAC,EAAE,WAAW,CAAA;CAC1B,CAAA;AAED,eAAO,MAAM,gBAAgB,kEAM1B,IAAI,KAAG,UAwBT,CAAA"}
|
|
@@ -1,17 +1,18 @@
|
|
|
1
|
-
export const formatBreadcrumb = (
|
|
1
|
+
export const formatBreadcrumb = ({ breadcrumb, collection, docs, generateLabel, generateURL })=>{
|
|
2
2
|
let url = undefined;
|
|
3
3
|
let label;
|
|
4
4
|
const lastDoc = docs[docs.length - 1];
|
|
5
|
-
if (typeof
|
|
6
|
-
url =
|
|
5
|
+
if (typeof generateURL === 'function') {
|
|
6
|
+
url = generateURL(docs, lastDoc);
|
|
7
7
|
}
|
|
8
|
-
if (typeof
|
|
9
|
-
label =
|
|
8
|
+
if (typeof generateLabel === 'function') {
|
|
9
|
+
label = generateLabel(docs, lastDoc);
|
|
10
10
|
} else {
|
|
11
11
|
const title = collection.admin?.useAsTitle ? lastDoc[collection.admin.useAsTitle] : '';
|
|
12
12
|
label = typeof title === 'string' || typeof title === 'number' ? String(title) : '';
|
|
13
13
|
}
|
|
14
14
|
return {
|
|
15
|
+
...breadcrumb || {},
|
|
15
16
|
doc: lastDoc.id,
|
|
16
17
|
label,
|
|
17
18
|
url
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utilities/formatBreadcrumb.ts"],"sourcesContent":["import type {
|
|
1
|
+
{"version":3,"sources":["../../src/utilities/formatBreadcrumb.ts"],"sourcesContent":["import type { SanitizedCollectionConfig } from 'payload'\n\nimport type { Breadcrumb, GenerateLabel, GenerateURL } from '../types.js'\n\ntype Args = {\n /**\n * Existing breadcrumb, if any, to base the new breadcrumb on.\n * This ensures that row IDs are maintained across updates, etc.\n */\n breadcrumb?: Breadcrumb\n collection: SanitizedCollectionConfig\n docs: Record<string, unknown>[]\n generateLabel?: GenerateLabel\n generateURL?: GenerateURL\n}\n\nexport const formatBreadcrumb = ({\n breadcrumb,\n collection,\n docs,\n generateLabel,\n generateURL,\n}: Args): Breadcrumb => {\n let url: string | undefined = undefined\n let label: string\n\n const lastDoc = docs[docs.length - 1]!\n\n if (typeof generateURL === 'function') {\n url = generateURL(docs, lastDoc)\n }\n\n if (typeof generateLabel === 'function') {\n label = generateLabel(docs, lastDoc)\n } else {\n const title = collection.admin?.useAsTitle ? lastDoc[collection.admin.useAsTitle] : ''\n\n label = typeof title === 'string' || typeof title === 'number' ? String(title) : ''\n }\n\n return {\n ...(breadcrumb || {}),\n doc: lastDoc.id as string,\n label,\n url,\n }\n}\n"],"names":["formatBreadcrumb","breadcrumb","collection","docs","generateLabel","generateURL","url","undefined","label","lastDoc","length","title","admin","useAsTitle","String","doc","id"],"mappings":"AAgBA,OAAO,MAAMA,mBAAmB,CAAC,EAC/BC,UAAU,EACVC,UAAU,EACVC,IAAI,EACJC,aAAa,EACbC,WAAW,EACN;IACL,IAAIC,MAA0BC;IAC9B,IAAIC;IAEJ,MAAMC,UAAUN,IAAI,CAACA,KAAKO,MAAM,GAAG,EAAE;IAErC,IAAI,OAAOL,gBAAgB,YAAY;QACrCC,MAAMD,YAAYF,MAAMM;IAC1B;IAEA,IAAI,OAAOL,kBAAkB,YAAY;QACvCI,QAAQJ,cAAcD,MAAMM;IAC9B,OAAO;QACL,MAAME,QAAQT,WAAWU,KAAK,EAAEC,aAAaJ,OAAO,CAACP,WAAWU,KAAK,CAACC,UAAU,CAAC,GAAG;QAEpFL,QAAQ,OAAOG,UAAU,YAAY,OAAOA,UAAU,WAAWG,OAAOH,SAAS;IACnF;IAEA,OAAO;QACL,GAAIV,cAAc,CAAC,CAAC;QACpBc,KAAKN,QAAQO,EAAE;QACfR;QACAF;IACF;AACF,EAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { CollectionConfig, PayloadRequest } from 'payload';
|
|
1
|
+
import type { CollectionConfig, Document, PayloadRequest } from 'payload';
|
|
2
2
|
import type { NestedDocsPluginConfig } from '../types.js';
|
|
3
|
-
export declare const getParents: (req: PayloadRequest, pluginConfig: NestedDocsPluginConfig, collection: CollectionConfig, doc: Record<string, unknown>, docs?: Array<Record<string, unknown>>) => Promise<
|
|
3
|
+
export declare const getParents: (req: PayloadRequest, pluginConfig: Pick<NestedDocsPluginConfig, "generateLabel" | "generateURL" | "parentFieldSlug">, collection: CollectionConfig, doc: Record<string, unknown>, docs?: Array<Record<string, unknown>>) => Promise<Document[]>;
|
|
4
4
|
//# sourceMappingURL=getParents.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getParents.d.ts","sourceRoot":"","sources":["../../src/utilities/getParents.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"getParents.d.ts","sourceRoot":"","sources":["../../src/utilities/getParents.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAEzE,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAA;AAEzD,eAAO,MAAM,UAAU,QAChB,cAAc,gBACL,IAAI,CAAC,sBAAsB,EAAE,eAAe,GAAG,aAAa,GAAG,iBAAiB,CAAC,cACnF,gBAAgB,OACvB,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,SACtB,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,KACnC,OAAO,CAAC,QAAQ,EAAE,CAmCpB,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utilities/getParents.ts"],"sourcesContent":["import type { CollectionConfig, PayloadRequest } from 'payload'\n\nimport type { NestedDocsPluginConfig } from '../types.js'\n\nexport const getParents = async (\n req: PayloadRequest,\n pluginConfig: NestedDocsPluginConfig
|
|
1
|
+
{"version":3,"sources":["../../src/utilities/getParents.ts"],"sourcesContent":["import type { CollectionConfig, Document, PayloadRequest } from 'payload'\n\nimport type { NestedDocsPluginConfig } from '../types.js'\n\nexport const getParents = async (\n req: PayloadRequest,\n pluginConfig: Pick<NestedDocsPluginConfig, 'generateLabel' | 'generateURL' | 'parentFieldSlug'>,\n collection: CollectionConfig,\n doc: Record<string, unknown>,\n docs: Array<Record<string, unknown>> = [],\n): Promise<Document[]> => {\n const parentSlug = pluginConfig?.parentFieldSlug || 'parent'\n const parent = doc[parentSlug]\n let retrievedParent: null | Record<string, unknown> = null\n\n if (parent) {\n // If not auto-populated, and we have an ID\n if (typeof parent === 'string' || typeof parent === 'number') {\n retrievedParent = await req.payload.findByID({\n id: parent,\n collection: collection.slug,\n depth: 0,\n disableErrors: true,\n req,\n })\n }\n\n // If auto-populated\n if (typeof parent === 'object') {\n retrievedParent = parent as Record<string, unknown>\n }\n\n if (retrievedParent) {\n if (retrievedParent[parentSlug]) {\n return getParents(req, pluginConfig, collection, retrievedParent, [\n retrievedParent,\n ...docs,\n ])\n }\n\n return [retrievedParent, ...docs]\n }\n }\n\n return docs\n}\n"],"names":["getParents","req","pluginConfig","collection","doc","docs","parentSlug","parentFieldSlug","parent","retrievedParent","payload","findByID","id","slug","depth","disableErrors"],"mappings":"AAIA,OAAO,MAAMA,aAAa,OACxBC,KACAC,cACAC,YACAC,KACAC,OAAuC,EAAE;IAEzC,MAAMC,aAAaJ,cAAcK,mBAAmB;IACpD,MAAMC,SAASJ,GAAG,CAACE,WAAW;IAC9B,IAAIG,kBAAkD;IAEtD,IAAID,QAAQ;QACV,2CAA2C;QAC3C,IAAI,OAAOA,WAAW,YAAY,OAAOA,WAAW,UAAU;YAC5DC,kBAAkB,MAAMR,IAAIS,OAAO,CAACC,QAAQ,CAAC;gBAC3CC,IAAIJ;gBACJL,YAAYA,WAAWU,IAAI;gBAC3BC,OAAO;gBACPC,eAAe;gBACfd;YACF;QACF;QAEA,oBAAoB;QACpB,IAAI,OAAOO,WAAW,UAAU;YAC9BC,kBAAkBD;QACpB;QAEA,IAAIC,iBAAiB;YACnB,IAAIA,eAAe,CAACH,WAAW,EAAE;gBAC/B,OAAON,WAAWC,KAAKC,cAAcC,YAAYM,iBAAiB;oBAChEA;uBACGJ;iBACJ;YACH;YAEA,OAAO;gBAACI;mBAAoBJ;aAAK;QACnC;IACF;IAEA,OAAOA;AACT,EAAC"}
|
|
@@ -1,4 +1,15 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
3
|
-
|
|
1
|
+
import type { Data, Document, PayloadRequest, SanitizedCollectionConfig } from 'payload';
|
|
2
|
+
import type { GenerateLabel, GenerateURL } from '../types.js';
|
|
3
|
+
type Args = {
|
|
4
|
+
breadcrumbsFieldName?: string;
|
|
5
|
+
collection: SanitizedCollectionConfig;
|
|
6
|
+
data: Data;
|
|
7
|
+
generateLabel?: GenerateLabel;
|
|
8
|
+
generateURL?: GenerateURL;
|
|
9
|
+
originalDoc?: Document;
|
|
10
|
+
parentFieldName?: string;
|
|
11
|
+
req: PayloadRequest;
|
|
12
|
+
};
|
|
13
|
+
export declare const populateBreadcrumbs: ({ breadcrumbsFieldName, collection, data, generateLabel, generateURL, originalDoc, parentFieldName, req, }: Args) => Promise<Data>;
|
|
14
|
+
export {};
|
|
4
15
|
//# sourceMappingURL=populateBreadcrumbs.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"populateBreadcrumbs.d.ts","sourceRoot":"","sources":["../../src/utilities/populateBreadcrumbs.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"populateBreadcrumbs.d.ts","sourceRoot":"","sources":["../../src/utilities/populateBreadcrumbs.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,cAAc,EAAE,yBAAyB,EAAE,MAAM,SAAS,CAAA;AAExF,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAK7D,KAAK,IAAI,GAAG;IACV,oBAAoB,CAAC,EAAE,MAAM,CAAA;IAC7B,UAAU,EAAE,yBAAyB,CAAA;IACrC,IAAI,EAAE,IAAI,CAAA;IACV,aAAa,CAAC,EAAE,aAAa,CAAA;IAC7B,WAAW,CAAC,EAAE,WAAW,CAAA;IACzB,WAAW,CAAC,EAAE,QAAQ,CAAA;IACtB,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB,GAAG,EAAE,cAAc,CAAA;CACpB,CAAA;AACD,eAAO,MAAM,mBAAmB,+GAS7B,IAAI,KAAG,OAAO,CAAC,IAAI,CAmCrB,CAAA"}
|
|
@@ -1,26 +1,27 @@
|
|
|
1
1
|
import { formatBreadcrumb } from './formatBreadcrumb.js';
|
|
2
|
-
import { getParents } from './getParents.js';
|
|
3
|
-
export const populateBreadcrumbs = async (
|
|
2
|
+
import { getParents as getAllParentDocuments } from './getParents.js';
|
|
3
|
+
export const populateBreadcrumbs = async ({ breadcrumbsFieldName = 'breadcrumbs', collection, data, generateLabel, generateURL, originalDoc, parentFieldName, req })=>{
|
|
4
4
|
const newData = data;
|
|
5
|
-
const
|
|
6
|
-
...await getParents(req, pluginConfig, collection, {
|
|
7
|
-
...originalDoc,
|
|
8
|
-
...data
|
|
9
|
-
})
|
|
10
|
-
];
|
|
11
|
-
const currentDocBreadcrumb = {
|
|
5
|
+
const currentDocument = {
|
|
12
6
|
...originalDoc,
|
|
13
|
-
...data
|
|
14
|
-
|
|
15
|
-
if (originalDoc?.id) {
|
|
16
|
-
currentDocBreadcrumb.id = originalDoc?.id;
|
|
17
|
-
}
|
|
18
|
-
breadcrumbDocs.push(currentDocBreadcrumb);
|
|
19
|
-
const breadcrumbs = breadcrumbDocs.map((_, i)=>formatBreadcrumb(pluginConfig, collection, breadcrumbDocs.slice(0, i + 1)));
|
|
20
|
-
return {
|
|
21
|
-
...newData,
|
|
22
|
-
[pluginConfig?.breadcrumbsFieldSlug || 'breadcrumbs']: breadcrumbs
|
|
7
|
+
...data,
|
|
8
|
+
id: originalDoc?.id ?? data?.id
|
|
23
9
|
};
|
|
10
|
+
const allParentDocuments = await getAllParentDocuments(req, {
|
|
11
|
+
generateLabel,
|
|
12
|
+
generateURL,
|
|
13
|
+
parentFieldSlug: parentFieldName
|
|
14
|
+
}, collection, currentDocument);
|
|
15
|
+
allParentDocuments.push(currentDocument);
|
|
16
|
+
const breadcrumbs = allParentDocuments.map((_, i)=>formatBreadcrumb({
|
|
17
|
+
breadcrumb: currentDocument[breadcrumbsFieldName]?.[i],
|
|
18
|
+
collection,
|
|
19
|
+
docs: allParentDocuments.slice(0, i + 1),
|
|
20
|
+
generateLabel,
|
|
21
|
+
generateURL
|
|
22
|
+
}));
|
|
23
|
+
newData[breadcrumbsFieldName] = breadcrumbs;
|
|
24
|
+
return newData;
|
|
24
25
|
};
|
|
25
26
|
|
|
26
27
|
//# sourceMappingURL=populateBreadcrumbs.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utilities/populateBreadcrumbs.ts"],"sourcesContent":["import type {
|
|
1
|
+
{"version":3,"sources":["../../src/utilities/populateBreadcrumbs.ts"],"sourcesContent":["import type { Data, Document, PayloadRequest, SanitizedCollectionConfig } from 'payload'\n\nimport type { GenerateLabel, GenerateURL } from '../types.js'\n\nimport { formatBreadcrumb } from './formatBreadcrumb.js'\nimport { getParents as getAllParentDocuments } from './getParents.js'\n\ntype Args = {\n breadcrumbsFieldName?: string\n collection: SanitizedCollectionConfig\n data: Data\n generateLabel?: GenerateLabel\n generateURL?: GenerateURL\n originalDoc?: Document\n parentFieldName?: string\n req: PayloadRequest\n}\nexport const populateBreadcrumbs = async ({\n breadcrumbsFieldName = 'breadcrumbs',\n collection,\n data,\n generateLabel,\n generateURL,\n originalDoc,\n parentFieldName,\n req,\n}: Args): Promise<Data> => {\n const newData = data\n\n const currentDocument = {\n ...originalDoc,\n ...data,\n id: originalDoc?.id ?? data?.id,\n }\n\n const allParentDocuments: Document[] = await getAllParentDocuments(\n req,\n {\n generateLabel,\n generateURL,\n parentFieldSlug: parentFieldName,\n },\n collection,\n currentDocument,\n )\n\n allParentDocuments.push(currentDocument)\n\n const breadcrumbs = allParentDocuments.map((_, i) =>\n formatBreadcrumb({\n breadcrumb: currentDocument[breadcrumbsFieldName]?.[i],\n collection,\n docs: allParentDocuments.slice(0, i + 1),\n generateLabel,\n generateURL,\n }),\n )\n\n newData[breadcrumbsFieldName] = breadcrumbs\n\n return newData\n}\n"],"names":["formatBreadcrumb","getParents","getAllParentDocuments","populateBreadcrumbs","breadcrumbsFieldName","collection","data","generateLabel","generateURL","originalDoc","parentFieldName","req","newData","currentDocument","id","allParentDocuments","parentFieldSlug","push","breadcrumbs","map","_","i","breadcrumb","docs","slice"],"mappings":"AAIA,SAASA,gBAAgB,QAAQ,wBAAuB;AACxD,SAASC,cAAcC,qBAAqB,QAAQ,kBAAiB;AAYrE,OAAO,MAAMC,sBAAsB,OAAO,EACxCC,uBAAuB,aAAa,EACpCC,UAAU,EACVC,IAAI,EACJC,aAAa,EACbC,WAAW,EACXC,WAAW,EACXC,eAAe,EACfC,GAAG,EACE;IACL,MAAMC,UAAUN;IAEhB,MAAMO,kBAAkB;QACtB,GAAGJ,WAAW;QACd,GAAGH,IAAI;QACPQ,IAAIL,aAAaK,MAAMR,MAAMQ;IAC/B;IAEA,MAAMC,qBAAiC,MAAMb,sBAC3CS,KACA;QACEJ;QACAC;QACAQ,iBAAiBN;IACnB,GACAL,YACAQ;IAGFE,mBAAmBE,IAAI,CAACJ;IAExB,MAAMK,cAAcH,mBAAmBI,GAAG,CAAC,CAACC,GAAGC,IAC7CrB,iBAAiB;YACfsB,YAAYT,eAAe,CAACT,qBAAqB,EAAE,CAACiB,EAAE;YACtDhB;YACAkB,MAAMR,mBAAmBS,KAAK,CAAC,GAAGH,IAAI;YACtCd;YACAC;QACF;IAGFI,OAAO,CAACR,qBAAqB,GAAGc;IAEhC,OAAON;AACT,EAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@payloadcms/plugin-nested-docs",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.55.0-canary.0",
|
|
4
4
|
"description": "The official Nested Docs plugin for Payload",
|
|
5
5
|
"homepage": "https://payloadcms.com",
|
|
6
6
|
"repository": {
|
|
@@ -37,11 +37,11 @@
|
|
|
37
37
|
"dist"
|
|
38
38
|
],
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"
|
|
41
|
-
"
|
|
40
|
+
"@payloadcms/eslint-config": "3.28.0",
|
|
41
|
+
"payload": "3.55.0-canary.0"
|
|
42
42
|
},
|
|
43
43
|
"peerDependencies": {
|
|
44
|
-
"payload": "3.
|
|
44
|
+
"payload": "3.55.0-canary.0"
|
|
45
45
|
},
|
|
46
46
|
"publishConfig": {
|
|
47
47
|
"registry": "https://registry.npmjs.org/"
|