@payloadcms/plugin-nested-docs 3.0.0-canary.f6e77b8 → 3.0.0-canary.fb04843

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 (34) hide show
  1. package/dist/exports/types.js.map +1 -1
  2. package/dist/fields/breadcrumbs.d.ts +1 -1
  3. package/dist/fields/breadcrumbs.d.ts.map +1 -1
  4. package/dist/fields/breadcrumbs.js.map +1 -1
  5. package/dist/fields/parent.d.ts +3 -3
  6. package/dist/fields/parent.d.ts.map +1 -1
  7. package/dist/fields/parent.js.map +1 -1
  8. package/dist/fields/parentFilterOptions.d.ts +1 -1
  9. package/dist/fields/parentFilterOptions.d.ts.map +1 -1
  10. package/dist/fields/parentFilterOptions.js.map +1 -1
  11. package/dist/hooks/resaveChildren.d.ts +1 -1
  12. package/dist/hooks/resaveChildren.d.ts.map +1 -1
  13. package/dist/hooks/resaveChildren.js +8 -1
  14. package/dist/hooks/resaveChildren.js.map +1 -1
  15. package/dist/hooks/resaveSelfAfterCreate.d.ts +1 -1
  16. package/dist/hooks/resaveSelfAfterCreate.d.ts.map +1 -1
  17. package/dist/hooks/resaveSelfAfterCreate.js.map +1 -1
  18. package/dist/index.d.ts +3 -2
  19. package/dist/index.d.ts.map +1 -1
  20. package/dist/index.js +2 -1
  21. package/dist/index.js.map +1 -1
  22. package/dist/types.js.map +1 -1
  23. package/dist/utilities/formatBreadcrumb.d.ts +1 -1
  24. package/dist/utilities/formatBreadcrumb.d.ts.map +1 -1
  25. package/dist/utilities/formatBreadcrumb.js.map +1 -1
  26. package/dist/utilities/getParents.d.ts +1 -1
  27. package/dist/utilities/getParents.d.ts.map +1 -1
  28. package/dist/utilities/getParents.js.map +1 -1
  29. package/dist/utilities/populateBreadcrumbs.d.ts +1 -1
  30. package/dist/utilities/populateBreadcrumbs.d.ts.map +1 -1
  31. package/dist/utilities/populateBreadcrumbs.js +1 -2
  32. package/dist/utilities/populateBreadcrumbs.js.map +1 -1
  33. package/license.md +22 -0
  34. package/package.json +22 -13
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/exports/types.ts"],"sourcesContent":["export type { Breadcrumb, GenerateLabel, GenerateURL, NestedDocsPluginConfig } from '../types.js'\n"],"names":[],"rangeMappings":"","mappings":"AAAA,WAAiG"}
1
+ {"version":3,"sources":["../../src/exports/types.ts"],"sourcesContent":["export type { Breadcrumb, GenerateLabel, GenerateURL, NestedDocsPluginConfig } from '../types.js'\n"],"names":[],"mappings":"AAAA,WAAiG"}
@@ -1,3 +1,3 @@
1
- import type { ArrayField, Field } from 'payload/types';
1
+ import type { ArrayField, Field } from 'payload';
2
2
  export declare const createBreadcrumbsField: (relationTo: string, overrides?: Partial<ArrayField>) => Field;
3
3
  //# sourceMappingURL=breadcrumbs.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"breadcrumbs.d.ts","sourceRoot":"","sources":["../../src/fields/breadcrumbs.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,eAAe,CAAA;AAEtD,eAAO,MAAM,sBAAsB,eACrB,MAAM,cACP,QAAQ,UAAU,CAAC,KAC7B,KAyCD,CAAA"}
1
+ {"version":3,"file":"breadcrumbs.d.ts","sourceRoot":"","sources":["../../src/fields/breadcrumbs.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAEhD,eAAO,MAAM,sBAAsB,eACrB,MAAM,cACP,OAAO,CAAC,UAAU,CAAC,KAC7B,KAyCD,CAAA"}
@@ -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 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"],"names":["createBreadcrumbsField","relationTo","overrides","name","type","localized","admin","readOnly","fields","disabled","maxDepth","width","label"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","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"}
1
+ {"version":3,"sources":["../../src/fields/breadcrumbs.ts"],"sourcesContent":["import type { ArrayField, Field } from 'payload'\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"],"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"}
@@ -1,5 +1,5 @@
1
- import type { SingleRelationshipField } from 'payload/types';
2
- export declare const createParentField: (relationTo: string, overrides?: Partial<SingleRelationshipField & {
1
+ import type { SingleRelationshipField } from 'payload';
2
+ export declare const createParentField: (relationTo: string, overrides?: Partial<{
3
3
  hasMany: false;
4
- }>) => SingleRelationshipField;
4
+ } & SingleRelationshipField>) => SingleRelationshipField;
5
5
  //# sourceMappingURL=parent.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"parent.d.ts","sourceRoot":"","sources":["../../src/fields/parent.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAA;AAE5D,eAAO,MAAM,iBAAiB,eAChB,MAAM,cACN,QACV,uBAAuB,GAAG;IACxB,OAAO,EAAE,KAAK,CAAA;CACf,CACF,KACA,uBAYD,CAAA"}
1
+ {"version":3,"file":"parent.d.ts","sourceRoot":"","sources":["../../src/fields/parent.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,SAAS,CAAA;AAEtD,eAAO,MAAM,iBAAiB,eAChB,MAAM,cACN,OAAO,CACjB;IACE,OAAO,EAAE,KAAK,CAAA;CACf,GAAG,uBAAuB,CAC5B,KACA,uBAYD,CAAA"}
@@ -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 type: 'relationship',\n maxDepth: 1,\n relationTo,\n ...(overrides || {}),\n})\n"],"names":["createParentField","relationTo","overrides","name","admin","position","type","maxDepth"],"rangeMappings":";;;;;;;;;;;;","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"}
1
+ {"version":3,"sources":["../../src/fields/parent.ts"],"sourcesContent":["import type { SingleRelationshipField } from 'payload'\n\nexport const createParentField = (\n relationTo: string,\n overrides?: Partial<\n {\n hasMany: false\n } & SingleRelationshipField\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"],"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"}
@@ -1,3 +1,3 @@
1
- import type { FilterOptions } from 'payload/types';
1
+ import type { FilterOptions } from 'payload';
2
2
  export declare const parentFilterOptions: (breadcrumbsFieldSlug?: string) => FilterOptions;
3
3
  //# sourceMappingURL=parentFilterOptions.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"parentFilterOptions.d.ts","sourceRoot":"","sources":["../../src/fields/parentFilterOptions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAElD,eAAO,MAAM,mBAAmB,EAAE,CAAC,oBAAoB,CAAC,EAAE,MAAM,KAAK,aAWlE,CAAA"}
1
+ {"version":3,"file":"parentFilterOptions.d.ts","sourceRoot":"","sources":["../../src/fields/parentFilterOptions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAE5C,eAAO,MAAM,mBAAmB,EAAE,CAAC,oBAAoB,CAAC,EAAE,MAAM,KAAK,aAWlE,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/fields/parentFilterOptions.ts"],"sourcesContent":["import type { FilterOptions } from 'payload/types'\n\nexport const parentFilterOptions: (breadcrumbsFieldSlug?: string) => FilterOptions =\n (breadcrumbsFieldSlug = 'breadcrumbs') =>\n ({ id }) => {\n if (id) {\n return {\n id: { not_equals: id },\n [`${breadcrumbsFieldSlug}.doc`]: { not_in: [id] },\n }\n }\n\n return null\n }\n"],"names":["parentFilterOptions","breadcrumbsFieldSlug","id","not_equals","not_in"],"rangeMappings":";;;;;;;;;;;;;;","mappings":"AAEA,OAAO,MAAMA,sBACX,CAACC,uBAAuB,aAAa,GACrC,CAAC,EAAEC,EAAE,EAAE;QACL,IAAIA,IAAI;YACN,OAAO;gBACLA,IAAI;oBAAEC,YAAYD;gBAAG;gBACrB,CAAC,CAAC,EAAED,qBAAqB,IAAI,CAAC,CAAC,EAAE;oBAAEG,QAAQ;wBAACF;qBAAG;gBAAC;YAClD;QACF;QAEA,OAAO;IACT,EAAC"}
1
+ {"version":3,"sources":["../../src/fields/parentFilterOptions.ts"],"sourcesContent":["import type { FilterOptions } from 'payload'\n\nexport const parentFilterOptions: (breadcrumbsFieldSlug?: string) => FilterOptions =\n (breadcrumbsFieldSlug = 'breadcrumbs') =>\n ({ id }) => {\n if (id) {\n return {\n id: { not_equals: id },\n [`${breadcrumbsFieldSlug}.doc`]: { not_in: [id] },\n }\n }\n\n return null\n }\n"],"names":["parentFilterOptions","breadcrumbsFieldSlug","id","not_equals","not_in"],"mappings":"AAEA,OAAO,MAAMA,sBACX,CAACC,uBAAuB,aAAa,GACrC,CAAC,EAAEC,EAAE,EAAE;QACL,IAAIA,IAAI;YACN,OAAO;gBACLA,IAAI;oBAAEC,YAAYD;gBAAG;gBACrB,CAAC,CAAC,EAAED,qBAAqB,IAAI,CAAC,CAAC,EAAE;oBAAEG,QAAQ;wBAACF;qBAAG;gBAAC;YAClD;QACF;QAEA,OAAO;IACT,EAAC"}
@@ -1,4 +1,4 @@
1
- import type { CollectionAfterChangeHook, CollectionConfig } from 'payload/types';
1
+ import type { CollectionAfterChangeHook, CollectionConfig } from 'payload';
2
2
  import type { NestedDocsPluginConfig } from '../types.js';
3
3
  export declare const resaveChildren: (pluginConfig: NestedDocsPluginConfig, collection: CollectionConfig) => 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,EACV,yBAAyB,EACzB,gBAAgB,EAEjB,MAAM,eAAe,CAAA;AAEtB,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAA;AAiEzD,eAAO,MAAM,cAAc,iBACV,sBAAsB,cAAc,gBAAgB,KAAG,yBAqBrE,CAAA"}
1
+ {"version":3,"file":"resaveChildren.d.ts","sourceRoot":"","sources":["../../src/hooks/resaveChildren.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,yBAAyB,EACzB,gBAAgB,EAIjB,MAAM,SAAS,CAAA;AAIhB,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAA;AA8EzD,eAAO,MAAM,cAAc,iBACV,sBAAsB,cAAc,gBAAgB,KAAG,yBAqBrE,CAAA"}
@@ -1,3 +1,4 @@
1
+ import { APIError } from 'payload';
1
2
  import { populateBreadcrumbs } from '../utilities/populateBreadcrumbs.js';
2
3
  const resave = async ({ collection, doc, draft, pluginConfig, req })=>{
3
4
  const parentSlug = pluginConfig?.parentFieldSlug || 'parent';
@@ -19,7 +20,9 @@ const resave = async ({ collection, doc, draft, pluginConfig, req })=>{
19
20
  await children.docs.reduce(async (priorSave, child)=>{
20
21
  await priorSave;
21
22
  const childIsPublished = typeof collection.versions === 'object' && collection.versions.drafts && child._status === 'published';
22
- if (!parentDocIsPublished && childIsPublished) return;
23
+ if (!parentDocIsPublished && childIsPublished) {
24
+ return;
25
+ }
23
26
  await req.payload.update({
24
27
  id: child.id,
25
28
  collection: collection.slug,
@@ -36,6 +39,10 @@ const resave = async ({ collection, doc, draft, pluginConfig, req })=>{
36
39
  } catch (err) {
37
40
  req.payload.logger.error(`Nested Docs plugin has had an error while re-saving a child document${draft ? ' as draft' : ' as published'}.`);
38
41
  req.payload.logger.error(err);
42
+ // Use type assertion until we can use instanceof reliably with our Error types
43
+ if (err?.name === 'ValidationError' && err?.data?.errors?.length) {
44
+ throw new APIError('Could not publish or save changes: One or more children are invalid.', 400);
45
+ }
39
46
  }
40
47
  };
41
48
  export const resaveChildren = (pluginConfig, collection)=>async ({ doc, req })=>{
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/hooks/resaveChildren.ts"],"sourcesContent":["import type {\n CollectionAfterChangeHook,\n CollectionConfig,\n PayloadRequestWithData,\n} from 'payload/types'\n\nimport type { NestedDocsPluginConfig } from '../types.js'\n\nimport { populateBreadcrumbs } from '../utilities/populateBreadcrumbs.js'\n\ntype ResaveArgs = {\n collection: CollectionConfig\n doc: Record<string, unknown>\n draft: boolean\n pluginConfig: NestedDocsPluginConfig\n req: PayloadRequestWithData\n}\n\nconst resave = async ({ collection, doc, draft, pluginConfig, req }: ResaveArgs) => {\n const parentSlug = pluginConfig?.parentFieldSlug || 'parent'\n const parentDocIsPublished = doc._status === 'published'\n\n const children = await req.payload.find({\n collection: collection.slug,\n depth: 0,\n draft,\n locale: req.locale,\n req,\n where: {\n [parentSlug]: {\n equals: doc.id,\n },\n },\n })\n\n const breadcrumbSlug = pluginConfig.breadcrumbsFieldSlug || 'breadcrumbs'\n\n try {\n await children.docs.reduce(async (priorSave, child) => {\n await priorSave\n\n const childIsPublished =\n typeof collection.versions === 'object' &&\n collection.versions.drafts &&\n child._status === 'published'\n\n if (!parentDocIsPublished && childIsPublished) return\n\n await req.payload.update({\n id: child.id,\n collection: collection.slug,\n data: {\n ...child,\n [breadcrumbSlug]: await populateBreadcrumbs(req, pluginConfig, collection, child),\n },\n depth: 0,\n draft: !childIsPublished,\n locale: req.locale,\n req,\n })\n }, Promise.resolve())\n } catch (err: unknown) {\n req.payload.logger.error(\n `Nested Docs plugin has had an error while re-saving a child document${\n draft ? ' as draft' : ' as published'\n }.`,\n )\n req.payload.logger.error(err)\n }\n}\n\nexport const resaveChildren =\n (pluginConfig: NestedDocsPluginConfig, collection: CollectionConfig): CollectionAfterChangeHook =>\n async ({ doc, req }) => {\n await resave({\n collection,\n doc,\n draft: true,\n pluginConfig,\n req,\n })\n\n if (doc._status === 'published') {\n await resave({\n collection,\n doc,\n draft: false,\n pluginConfig,\n req,\n })\n }\n\n return undefined\n }\n"],"names":["populateBreadcrumbs","resave","collection","doc","draft","pluginConfig","req","parentSlug","parentFieldSlug","parentDocIsPublished","_status","children","payload","find","slug","depth","locale","where","equals","id","breadcrumbSlug","breadcrumbsFieldSlug","docs","reduce","priorSave","child","childIsPublished","versions","drafts","update","data","Promise","resolve","err","logger","error","resaveChildren","undefined"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAQA,SAASA,mBAAmB,QAAQ,sCAAqC;AAUzE,MAAMC,SAAS,OAAO,EAAEC,UAAU,EAAEC,GAAG,EAAEC,KAAK,EAAEC,YAAY,EAAEC,GAAG,EAAc;IAC7E,MAAMC,aAAaF,cAAcG,mBAAmB;IACpD,MAAMC,uBAAuBN,IAAIO,OAAO,KAAK;IAE7C,MAAMC,WAAW,MAAML,IAAIM,OAAO,CAACC,IAAI,CAAC;QACtCX,YAAYA,WAAWY,IAAI;QAC3BC,OAAO;QACPX;QACAY,QAAQV,IAAIU,MAAM;QAClBV;QACAW,OAAO;YACL,CAACV,WAAW,EAAE;gBACZW,QAAQf,IAAIgB,EAAE;YAChB;QACF;IACF;IAEA,MAAMC,iBAAiBf,aAAagB,oBAAoB,IAAI;IAE5D,IAAI;QACF,MAAMV,SAASW,IAAI,CAACC,MAAM,CAAC,OAAOC,WAAWC;YAC3C,MAAMD;YAEN,MAAME,mBACJ,OAAOxB,WAAWyB,QAAQ,KAAK,YAC/BzB,WAAWyB,QAAQ,CAACC,MAAM,IAC1BH,MAAMf,OAAO,KAAK;YAEpB,IAAI,CAACD,wBAAwBiB,kBAAkB;YAE/C,MAAMpB,IAAIM,OAAO,CAACiB,MAAM,CAAC;gBACvBV,IAAIM,MAAMN,EAAE;gBACZjB,YAAYA,WAAWY,IAAI;gBAC3BgB,MAAM;oBACJ,GAAGL,KAAK;oBACR,CAACL,eAAe,EAAE,MAAMpB,oBAAoBM,KAAKD,cAAcH,YAAYuB;gBAC7E;gBACAV,OAAO;gBACPX,OAAO,CAACsB;gBACRV,QAAQV,IAAIU,MAAM;gBAClBV;YACF;QACF,GAAGyB,QAAQC,OAAO;IACpB,EAAE,OAAOC,KAAc;QACrB3B,IAAIM,OAAO,CAACsB,MAAM,CAACC,KAAK,CACtB,CAAC,oEAAoE,EACnE/B,QAAQ,cAAc,gBACvB,CAAC,CAAC;QAELE,IAAIM,OAAO,CAACsB,MAAM,CAACC,KAAK,CAACF;IAC3B;AACF;AAEA,OAAO,MAAMG,iBACX,CAAC/B,cAAsCH,aACvC,OAAO,EAAEC,GAAG,EAAEG,GAAG,EAAE;QACjB,MAAML,OAAO;YACXC;YACAC;YACAC,OAAO;YACPC;YACAC;QACF;QAEA,IAAIH,IAAIO,OAAO,KAAK,aAAa;YAC/B,MAAMT,OAAO;gBACXC;gBACAC;gBACAC,OAAO;gBACPC;gBACAC;YACF;QACF;QAEA,OAAO+B;IACT,EAAC"}
1
+ {"version":3,"sources":["../../src/hooks/resaveChildren.ts"],"sourcesContent":["import type {\n CollectionAfterChangeHook,\n CollectionConfig,\n JsonObject,\n PayloadRequest,\n ValidationError,\n} from 'payload'\n\nimport { APIError } from 'payload'\n\nimport type { NestedDocsPluginConfig } from '../types.js'\n\nimport { populateBreadcrumbs } from '../utilities/populateBreadcrumbs.js'\n\ntype ResaveArgs = {\n collection: CollectionConfig\n doc: JsonObject\n draft: boolean\n pluginConfig: NestedDocsPluginConfig\n req: PayloadRequest\n}\n\nconst resave = async ({ collection, doc, draft, pluginConfig, req }: ResaveArgs) => {\n const parentSlug = pluginConfig?.parentFieldSlug || 'parent'\n const parentDocIsPublished = doc._status === 'published'\n\n const children = await req.payload.find({\n collection: collection.slug,\n depth: 0,\n draft,\n locale: req.locale,\n req,\n where: {\n [parentSlug]: {\n equals: doc.id,\n },\n },\n })\n\n const breadcrumbSlug = pluginConfig.breadcrumbsFieldSlug || 'breadcrumbs'\n\n try {\n await children.docs.reduce(async (priorSave, child) => {\n await priorSave\n\n const childIsPublished =\n typeof collection.versions === 'object' &&\n collection.versions.drafts &&\n child._status === 'published'\n\n if (!parentDocIsPublished && childIsPublished) {\n return\n }\n\n await req.payload.update({\n id: child.id,\n collection: collection.slug,\n data: {\n ...child,\n [breadcrumbSlug]: await populateBreadcrumbs(req, pluginConfig, collection, child),\n },\n depth: 0,\n draft: !childIsPublished,\n locale: req.locale,\n req,\n })\n }, Promise.resolve())\n } catch (err: unknown) {\n req.payload.logger.error(\n `Nested Docs plugin has had an error while re-saving a child document${\n draft ? ' as draft' : ' as published'\n }.`,\n )\n req.payload.logger.error(err)\n\n // Use type assertion until we can use instanceof reliably with our Error types\n if (\n (err as ValidationError)?.name === 'ValidationError' &&\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\nexport const resaveChildren =\n (pluginConfig: NestedDocsPluginConfig, collection: CollectionConfig): CollectionAfterChangeHook =>\n async ({ doc, req }) => {\n await resave({\n collection,\n doc,\n draft: true,\n pluginConfig,\n req,\n })\n\n if (doc._status === 'published') {\n await resave({\n collection,\n doc,\n draft: false,\n pluginConfig,\n req,\n })\n }\n\n return undefined\n }\n"],"names":["APIError","populateBreadcrumbs","resave","collection","doc","draft","pluginConfig","req","parentSlug","parentFieldSlug","parentDocIsPublished","_status","children","payload","find","slug","depth","locale","where","equals","id","breadcrumbSlug","breadcrumbsFieldSlug","docs","reduce","priorSave","child","childIsPublished","versions","drafts","update","data","Promise","resolve","err","logger","error","name","errors","length","resaveChildren","undefined"],"mappings":"AAQA,SAASA,QAAQ,QAAQ,UAAS;AAIlC,SAASC,mBAAmB,QAAQ,sCAAqC;AAUzE,MAAMC,SAAS,OAAO,EAAEC,UAAU,EAAEC,GAAG,EAAEC,KAAK,EAAEC,YAAY,EAAEC,GAAG,EAAc;IAC7E,MAAMC,aAAaF,cAAcG,mBAAmB;IACpD,MAAMC,uBAAuBN,IAAIO,OAAO,KAAK;IAE7C,MAAMC,WAAW,MAAML,IAAIM,OAAO,CAACC,IAAI,CAAC;QACtCX,YAAYA,WAAWY,IAAI;QAC3BC,OAAO;QACPX;QACAY,QAAQV,IAAIU,MAAM;QAClBV;QACAW,OAAO;YACL,CAACV,WAAW,EAAE;gBACZW,QAAQf,IAAIgB,EAAE;YAChB;QACF;IACF;IAEA,MAAMC,iBAAiBf,aAAagB,oBAAoB,IAAI;IAE5D,IAAI;QACF,MAAMV,SAASW,IAAI,CAACC,MAAM,CAAC,OAAOC,WAAWC;YAC3C,MAAMD;YAEN,MAAME,mBACJ,OAAOxB,WAAWyB,QAAQ,KAAK,YAC/BzB,WAAWyB,QAAQ,CAACC,MAAM,IAC1BH,MAAMf,OAAO,KAAK;YAEpB,IAAI,CAACD,wBAAwBiB,kBAAkB;gBAC7C;YACF;YAEA,MAAMpB,IAAIM,OAAO,CAACiB,MAAM,CAAC;gBACvBV,IAAIM,MAAMN,EAAE;gBACZjB,YAAYA,WAAWY,IAAI;gBAC3BgB,MAAM;oBACJ,GAAGL,KAAK;oBACR,CAACL,eAAe,EAAE,MAAMpB,oBAAoBM,KAAKD,cAAcH,YAAYuB;gBAC7E;gBACAV,OAAO;gBACPX,OAAO,CAACsB;gBACRV,QAAQV,IAAIU,MAAM;gBAClBV;YACF;QACF,GAAGyB,QAAQC,OAAO;IACpB,EAAE,OAAOC,KAAc;QACrB3B,IAAIM,OAAO,CAACsB,MAAM,CAACC,KAAK,CACtB,CAAC,oEAAoE,EACnE/B,QAAQ,cAAc,gBACvB,CAAC,CAAC;QAELE,IAAIM,OAAO,CAACsB,MAAM,CAACC,KAAK,CAACF;QAEzB,+EAA+E;QAC/E,IACE,AAACA,KAAyBG,SAAS,qBAClCH,KAAyBH,MAAMO,QAAQC,QACxC;YACA,MAAM,IAAIvC,SACR,wEACA;QAEJ;IACF;AACF;AAEA,OAAO,MAAMwC,iBACX,CAAClC,cAAsCH,aACvC,OAAO,EAAEC,GAAG,EAAEG,GAAG,EAAE;QACjB,MAAML,OAAO;YACXC;YACAC;YACAC,OAAO;YACPC;YACAC;QACF;QAEA,IAAIH,IAAIO,OAAO,KAAK,aAAa;YAC/B,MAAMT,OAAO;gBACXC;gBACAC;gBACAC,OAAO;gBACPC;gBACAC;YACF;QACF;QAEA,OAAOkC;IACT,EAAC"}
@@ -1,4 +1,4 @@
1
- import type { CollectionAfterChangeHook, CollectionConfig } from 'payload/types';
1
+ import type { CollectionAfterChangeHook, CollectionConfig } from 'payload';
2
2
  import type { NestedDocsPluginConfig } from '../types.js';
3
3
  export declare const resaveSelfAfterCreate: (pluginConfig: NestedDocsPluginConfig, collection: CollectionConfig) => 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,gBAAgB,EAAE,MAAM,eAAe,CAAA;AAEhF,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAA;AAKzD,eAAO,MAAM,qBAAqB,iBACjB,sBAAsB,cAAc,gBAAgB,KAAG,yBA6CrE,CAAA"}
1
+ {"version":3,"file":"resaveSelfAfterCreate.d.ts","sourceRoot":"","sources":["../../src/hooks/resaveSelfAfterCreate.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,yBAAyB,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAE1E,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAA;AAKzD,eAAO,MAAM,qBAAqB,iBACjB,sBAAsB,cAAc,gBAAgB,KAAG,yBA6CrE,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/hooks/resaveSelfAfterCreate.ts"],"sourcesContent":["import type { CollectionAfterChangeHook, CollectionConfig } from 'payload/types'\n\nimport type { 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, collection: CollectionConfig): CollectionAfterChangeHook =>\n async ({ doc, operation, req }) => {\n const { locale, payload } = req\n const breadcrumbSlug = pluginConfig.breadcrumbsFieldSlug || 'breadcrumbs'\n const breadcrumbs = doc[breadcrumbSlug]\n\n if (operation === 'create') {\n const originalDocWithDepth0 = await payload.findByID({\n id: doc.id,\n collection: collection.slug,\n depth: 0,\n req,\n })\n\n const updateAsDraft =\n typeof collection.versions === 'object' &&\n collection.versions.drafts &&\n doc._status !== 'published'\n\n try {\n await payload.update({\n id: doc.id,\n collection: collection.slug,\n data: {\n ...originalDocWithDepth0,\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: updateAsDraft,\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\n return undefined\n }\n"],"names":["resaveSelfAfterCreate","pluginConfig","collection","doc","operation","req","locale","payload","breadcrumbSlug","breadcrumbsFieldSlug","breadcrumbs","originalDocWithDepth0","findByID","id","slug","depth","updateAsDraft","versions","drafts","_status","update","data","map","crumb","i","length","draft","err","logger","error","undefined"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAIA,kEAAkE;AAClE,6EAA6E;AAE7E,OAAO,MAAMA,wBACX,CAACC,cAAsCC,aACvC,OAAO,EAAEC,GAAG,EAAEC,SAAS,EAAEC,GAAG,EAAE;QAC5B,MAAM,EAAEC,MAAM,EAAEC,OAAO,EAAE,GAAGF;QAC5B,MAAMG,iBAAiBP,aAAaQ,oBAAoB,IAAI;QAC5D,MAAMC,cAAcP,GAAG,CAACK,eAAe;QAEvC,IAAIJ,cAAc,UAAU;YAC1B,MAAMO,wBAAwB,MAAMJ,QAAQK,QAAQ,CAAC;gBACnDC,IAAIV,IAAIU,EAAE;gBACVX,YAAYA,WAAWY,IAAI;gBAC3BC,OAAO;gBACPV;YACF;YAEA,MAAMW,gBACJ,OAAOd,WAAWe,QAAQ,KAAK,YAC/Bf,WAAWe,QAAQ,CAACC,MAAM,IAC1Bf,IAAIgB,OAAO,KAAK;YAElB,IAAI;gBACF,MAAMZ,QAAQa,MAAM,CAAC;oBACnBP,IAAIV,IAAIU,EAAE;oBACVX,YAAYA,WAAWY,IAAI;oBAC3BO,MAAM;wBACJ,GAAGV,qBAAqB;wBACxB,CAACH,eAAe,EACdE,aAAaY,IAAI,CAACC,OAAOC,IAAO,CAAA;gCAC9B,GAAGD,KAAK;gCACRpB,KAAKO,YAAYe,MAAM,KAAKD,IAAI,IAAIrB,IAAIU,EAAE,GAAGU,MAAMpB,GAAG;4BACxD,CAAA,MAAO,EAAE;oBACb;oBACAY,OAAO;oBACPW,OAAOV;oBACPV;oBACAD;gBACF;YACF,EAAE,OAAOsB,KAAc;gBACrBpB,QAAQqB,MAAM,CAACC,KAAK,CAClB,CAAC,sFAAsF,CAAC;gBAE1FtB,QAAQqB,MAAM,CAACC,KAAK,CAACF;YACvB;QACF;QAEA,OAAOG;IACT,EAAC"}
1
+ {"version":3,"sources":["../../src/hooks/resaveSelfAfterCreate.ts"],"sourcesContent":["import type { CollectionAfterChangeHook, CollectionConfig } from 'payload'\n\nimport type { 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, collection: CollectionConfig): CollectionAfterChangeHook =>\n async ({ doc, operation, req }) => {\n const { locale, payload } = req\n const breadcrumbSlug = pluginConfig.breadcrumbsFieldSlug || 'breadcrumbs'\n const breadcrumbs = doc[breadcrumbSlug]\n\n if (operation === 'create') {\n const originalDocWithDepth0 = await payload.findByID({\n id: doc.id,\n collection: collection.slug,\n depth: 0,\n req,\n })\n\n const updateAsDraft =\n typeof collection.versions === 'object' &&\n collection.versions.drafts &&\n doc._status !== 'published'\n\n try {\n await payload.update({\n id: doc.id,\n collection: collection.slug,\n data: {\n ...originalDocWithDepth0,\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: updateAsDraft,\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\n return undefined\n }\n"],"names":["resaveSelfAfterCreate","pluginConfig","collection","doc","operation","req","locale","payload","breadcrumbSlug","breadcrumbsFieldSlug","breadcrumbs","originalDocWithDepth0","findByID","id","slug","depth","updateAsDraft","versions","drafts","_status","update","data","map","crumb","i","length","draft","err","logger","error","undefined"],"mappings":"AAIA,kEAAkE;AAClE,6EAA6E;AAE7E,OAAO,MAAMA,wBACX,CAACC,cAAsCC,aACvC,OAAO,EAAEC,GAAG,EAAEC,SAAS,EAAEC,GAAG,EAAE;QAC5B,MAAM,EAAEC,MAAM,EAAEC,OAAO,EAAE,GAAGF;QAC5B,MAAMG,iBAAiBP,aAAaQ,oBAAoB,IAAI;QAC5D,MAAMC,cAAcP,GAAG,CAACK,eAAe;QAEvC,IAAIJ,cAAc,UAAU;YAC1B,MAAMO,wBAAwB,MAAMJ,QAAQK,QAAQ,CAAC;gBACnDC,IAAIV,IAAIU,EAAE;gBACVX,YAAYA,WAAWY,IAAI;gBAC3BC,OAAO;gBACPV;YACF;YAEA,MAAMW,gBACJ,OAAOd,WAAWe,QAAQ,KAAK,YAC/Bf,WAAWe,QAAQ,CAACC,MAAM,IAC1Bf,IAAIgB,OAAO,KAAK;YAElB,IAAI;gBACF,MAAMZ,QAAQa,MAAM,CAAC;oBACnBP,IAAIV,IAAIU,EAAE;oBACVX,YAAYA,WAAWY,IAAI;oBAC3BO,MAAM;wBACJ,GAAGV,qBAAqB;wBACxB,CAACH,eAAe,EACdE,aAAaY,IAAI,CAACC,OAAOC,IAAO,CAAA;gCAC9B,GAAGD,KAAK;gCACRpB,KAAKO,YAAYe,MAAM,KAAKD,IAAI,IAAIrB,IAAIU,EAAE,GAAGU,MAAMpB,GAAG;4BACxD,CAAA,MAAO,EAAE;oBACb;oBACAY,OAAO;oBACPW,OAAOV;oBACPV;oBACAD;gBACF;YACF,EAAE,OAAOsB,KAAc;gBACrBpB,QAAQqB,MAAM,CAACC,KAAK,CAClB,CAAC,sFAAsF,CAAC;gBAE1FtB,QAAQqB,MAAM,CAACC,KAAK,CAACF;YACvB;QACF;QAEA,OAAOG;IACT,EAAC"}
package/dist/index.d.ts CHANGED
@@ -1,7 +1,8 @@
1
- import type { Plugin } from 'payload/config';
1
+ import type { Plugin } from 'payload';
2
2
  import type { NestedDocsPluginConfig } from './types.js';
3
3
  import { createBreadcrumbsField } from './fields/breadcrumbs.js';
4
4
  import { createParentField } from './fields/parent.js';
5
- export { createBreadcrumbsField, createParentField };
5
+ import { getParents } from './utilities/getParents.js';
6
+ export { createBreadcrumbsField, createParentField, getParents };
6
7
  export declare const nestedDocsPlugin: (pluginConfig: NestedDocsPluginConfig) => Plugin;
7
8
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AAG5C,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAA;AAExD,OAAO,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAA;AAChE,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAA;AAMtD,OAAO,EAAE,sBAAsB,EAAE,iBAAiB,EAAE,CAAA;AAEpD,eAAO,MAAM,gBAAgB,iBACZ,sBAAsB,KAAG,MAuDtC,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;AAItD,OAAO,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAA;AAGtD,OAAO,EAAE,sBAAsB,EAAE,iBAAiB,EAAE,UAAU,EAAE,CAAA;AAEhE,eAAO,MAAM,gBAAgB,iBACZ,sBAAsB,KAAG,MAuDtC,CAAA"}
package/dist/index.js CHANGED
@@ -3,8 +3,9 @@ import { createParentField } from './fields/parent.js';
3
3
  import { parentFilterOptions } from './fields/parentFilterOptions.js';
4
4
  import { resaveChildren } from './hooks/resaveChildren.js';
5
5
  import { resaveSelfAfterCreate } from './hooks/resaveSelfAfterCreate.js';
6
+ import { getParents } from './utilities/getParents.js';
6
7
  import { populateBreadcrumbs } from './utilities/populateBreadcrumbs.js';
7
- export { createBreadcrumbsField, createParentField };
8
+ export { createBreadcrumbsField, createParentField, getParents };
8
9
  export const nestedDocsPlugin = (pluginConfig)=>(config)=>({
9
10
  ...config,
10
11
  collections: (config.collections || []).map((collection)=>{
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { Plugin } from 'payload/config'\nimport type { SingleRelationshipField } from 'payload/types'\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 { resaveChildren } from './hooks/resaveChildren.js'\nimport { resaveSelfAfterCreate } from './hooks/resaveSelfAfterCreate.js'\nimport { populateBreadcrumbs } from './utilities/populateBreadcrumbs.js'\n\nexport { createBreadcrumbsField, createParentField }\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, collection),\n resaveSelfAfterCreate(pluginConfig, collection),\n ...(collection?.hooks?.afterChange || []),\n ],\n beforeChange: [\n async ({ data, originalDoc, req }) =>\n populateBreadcrumbs(req, pluginConfig, collection, data, originalDoc),\n ...(collection?.hooks?.beforeChange || []),\n ],\n },\n }\n }\n\n return collection\n }),\n })\n"],"names":["createBreadcrumbsField","createParentField","parentFilterOptions","resaveChildren","resaveSelfAfterCreate","populateBreadcrumbs","nestedDocsPlugin","pluginConfig","config","collections","map","collection","indexOf","slug","fields","existingBreadcrumbField","find","field","name","breadcrumbsFieldSlug","existingParentField","parentFieldSlug","defaultFilterOptions","filterOptions","defaultParentField","push","hooks","afterChange","beforeChange","data","originalDoc","req"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAKA,SAASA,sBAAsB,QAAQ,0BAAyB;AAChE,SAASC,iBAAiB,QAAQ,qBAAoB;AACtD,SAASC,mBAAmB,QAAQ,kCAAiC;AACrE,SAASC,cAAc,QAAQ,4BAA2B;AAC1D,SAASC,qBAAqB,QAAQ,mCAAkC;AACxE,SAASC,mBAAmB,QAAQ,qCAAoC;AAExE,SAASL,sBAAsB,EAAEC,iBAAiB,GAAE;AAEpD,OAAO,MAAMK,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,uBAAuBpB,oBAAoBK,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,qBAAqBvB,kBAAkBU,WAAWE,IAAI;wBAC5DW,mBAAmBD,aAAa,GAAGD;wBACnCR,OAAOW,IAAI,CAACD;oBACd;oBAEA,IAAI,CAACT,2BAA2B,CAACR,aAAaY,oBAAoB,EAAE;wBAClEL,OAAOW,IAAI,CAACzB,uBAAuBW,WAAWE,IAAI;oBACpD;oBAEA,OAAO;wBACL,GAAGF,UAAU;wBACbG;wBACAY,OAAO;4BACL,GAAIf,WAAWe,KAAK,IAAI,CAAC,CAAC;4BAC1BC,aAAa;gCACXxB,eAAeI,cAAcI;gCAC7BP,sBAAsBG,cAAcI;mCAChCA,YAAYe,OAAOC,eAAe,EAAE;6BACzC;4BACDC,cAAc;gCACZ,OAAO,EAAEC,IAAI,EAAEC,WAAW,EAAEC,GAAG,EAAE,GAC/B1B,oBAAoB0B,KAAKxB,cAAcI,YAAYkB,MAAMC;mCACvDnB,YAAYe,OAAOE,gBAAgB,EAAE;6BAC1C;wBACH;oBACF;gBACF;gBAEA,OAAOjB;YACT;QACF,CAAA,EAAE"}
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 { resaveChildren } from './hooks/resaveChildren.js'\nimport { resaveSelfAfterCreate } from './hooks/resaveSelfAfterCreate.js'\nimport { getParents } from './utilities/getParents.js'\nimport { populateBreadcrumbs } from './utilities/populateBreadcrumbs.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, collection),\n resaveSelfAfterCreate(pluginConfig, collection),\n ...(collection?.hooks?.afterChange || []),\n ],\n beforeChange: [\n async ({ data, originalDoc, req }) =>\n populateBreadcrumbs(req, pluginConfig, collection, data, originalDoc),\n ...(collection?.hooks?.beforeChange || []),\n ],\n },\n }\n }\n\n return collection\n }),\n })\n"],"names":["createBreadcrumbsField","createParentField","parentFilterOptions","resaveChildren","resaveSelfAfterCreate","getParents","populateBreadcrumbs","nestedDocsPlugin","pluginConfig","config","collections","map","collection","indexOf","slug","fields","existingBreadcrumbField","find","field","name","breadcrumbsFieldSlug","existingParentField","parentFieldSlug","defaultFilterOptions","filterOptions","defaultParentField","push","hooks","afterChange","beforeChange","data","originalDoc","req"],"mappings":"AAIA,SAASA,sBAAsB,QAAQ,0BAAyB;AAChE,SAASC,iBAAiB,QAAQ,qBAAoB;AACtD,SAASC,mBAAmB,QAAQ,kCAAiC;AACrE,SAASC,cAAc,QAAQ,4BAA2B;AAC1D,SAASC,qBAAqB,QAAQ,mCAAkC;AACxE,SAASC,UAAU,QAAQ,4BAA2B;AACtD,SAASC,mBAAmB,QAAQ,qCAAoC;AAExE,SAASN,sBAAsB,EAAEC,iBAAiB,EAAEI,UAAU,GAAE;AAEhE,OAAO,MAAME,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;gCACXzB,eAAeK,cAAcI;gCAC7BR,sBAAsBI,cAAcI;mCAChCA,YAAYe,OAAOC,eAAe,EAAE;6BACzC;4BACDC,cAAc;gCACZ,OAAO,EAAEC,IAAI,EAAEC,WAAW,EAAEC,GAAG,EAAE,GAC/B1B,oBAAoB0B,KAAKxB,cAAcI,YAAYkB,MAAMC;mCACvDnB,YAAYe,OAAOE,gBAAgB,EAAE;6BAC1C;wBACH;oBACF;gBACF;gBAEA,OAAOjB;YACT;QACF,CAAA,EAAE"}
package/dist/types.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/types.ts"],"sourcesContent":["export type Breadcrumb = {\n doc: string\n label: string\n url?: string\n}\n\nexport type GenerateURL = (\n docs: Array<Record<string, unknown>>,\n currentDoc: Record<string, unknown>,\n) => string\n\nexport type GenerateLabel = (\n docs: Array<Record<string, unknown>>,\n currentDoc: Record<string, unknown>,\n) => string\n\nexport type NestedDocsPluginConfig = {\n /**\n * Should be supplied if using an alternative field name for the 'breadcrumbs' field in collections\n */\n breadcrumbsFieldSlug?: string\n /**\n * The slugs of the collections this plugin should extend. If you need different configs for different collections, this plugin can be added to your config more than once having different collections.\n */\n collections: string[]\n generateLabel?: GenerateLabel\n generateURL?: GenerateURL\n /**\n * Should be supplied if using an alternative field name for the 'parent' field in collections\n */\n parentFieldSlug?: string\n}\n"],"names":[],"rangeMappings":"","mappings":"AAgBA,WAeC"}
1
+ {"version":3,"sources":["../src/types.ts"],"sourcesContent":["export type Breadcrumb = {\n doc: string\n label: string\n url?: string\n}\n\nexport type GenerateURL = (\n docs: Array<Record<string, unknown>>,\n currentDoc: Record<string, unknown>,\n) => string\n\nexport type GenerateLabel = (\n docs: Array<Record<string, unknown>>,\n currentDoc: Record<string, unknown>,\n) => string\n\nexport type NestedDocsPluginConfig = {\n /**\n * Should be supplied if using an alternative field name for the 'breadcrumbs' field in collections\n */\n breadcrumbsFieldSlug?: string\n /**\n * The slugs of the collections this plugin should extend. If you need different configs for different collections, this plugin can be added to your config more than once having different collections.\n */\n collections: string[]\n generateLabel?: GenerateLabel\n generateURL?: GenerateURL\n /**\n * Should be supplied if using an alternative field name for the 'parent' field in collections\n */\n parentFieldSlug?: string\n}\n"],"names":[],"mappings":"AAgBA,WAeC"}
@@ -1,4 +1,4 @@
1
- import type { CollectionConfig } from 'payload/types';
1
+ import type { CollectionConfig } from 'payload';
2
2
  import type { Breadcrumb, NestedDocsPluginConfig } from '../types.js';
3
3
  export declare const formatBreadcrumb: (pluginConfig: NestedDocsPluginConfig, collection: CollectionConfig, docs: Array<Record<string, unknown>>) => Breadcrumb;
4
4
  //# 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,gBAAgB,EAAE,MAAM,eAAe,CAAA;AAErD,OAAO,KAAK,EAAE,UAAU,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAA;AAErE,eAAO,MAAM,gBAAgB,iBACb,sBAAsB,cACxB,gBAAgB,QACtB,MAAM,OAAO,MAAM,EAAE,OAAO,CAAC,CAAC,KACnC,UAsBF,CAAA"}
1
+ {"version":3,"file":"formatBreadcrumb.d.ts","sourceRoot":"","sources":["../../src/utilities/formatBreadcrumb.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAE/C,OAAO,KAAK,EAAE,UAAU,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAA;AAErE,eAAO,MAAM,gBAAgB,iBACb,sBAAsB,cACxB,gBAAgB,QACtB,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,KACnC,UAsBF,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utilities/formatBreadcrumb.ts"],"sourcesContent":["import type { CollectionConfig } from 'payload/types'\n\nimport type { Breadcrumb, NestedDocsPluginConfig } from '../types.js'\n\nexport const formatBreadcrumb = (\n pluginConfig: NestedDocsPluginConfig,\n collection: CollectionConfig,\n docs: Array<Record<string, unknown>>,\n): Breadcrumb => {\n let url: string | undefined = undefined\n let label: string\n\n const lastDoc = docs[docs.length - 1]\n\n if (typeof pluginConfig?.generateURL === 'function') {\n url = pluginConfig.generateURL(docs, lastDoc)\n }\n\n if (typeof pluginConfig?.generateLabel === 'function') {\n label = pluginConfig.generateLabel(docs, lastDoc)\n } else {\n const useAsTitle = collection?.admin?.useAsTitle || 'id'\n label = lastDoc[useAsTitle] as string\n }\n\n return {\n doc: lastDoc.id as string,\n label,\n url,\n }\n}\n"],"names":["formatBreadcrumb","pluginConfig","collection","docs","url","undefined","label","lastDoc","length","generateURL","generateLabel","useAsTitle","admin","doc","id"],"rangeMappings":";;;;;;;;;;;;;;;;;;","mappings":"AAIA,OAAO,MAAMA,mBAAmB,CAC9BC,cACAC,YACAC;IAEA,IAAIC,MAA0BC;IAC9B,IAAIC;IAEJ,MAAMC,UAAUJ,IAAI,CAACA,KAAKK,MAAM,GAAG,EAAE;IAErC,IAAI,OAAOP,cAAcQ,gBAAgB,YAAY;QACnDL,MAAMH,aAAaQ,WAAW,CAACN,MAAMI;IACvC;IAEA,IAAI,OAAON,cAAcS,kBAAkB,YAAY;QACrDJ,QAAQL,aAAaS,aAAa,CAACP,MAAMI;IAC3C,OAAO;QACL,MAAMI,aAAaT,YAAYU,OAAOD,cAAc;QACpDL,QAAQC,OAAO,CAACI,WAAW;IAC7B;IAEA,OAAO;QACLE,KAAKN,QAAQO,EAAE;QACfR;QACAF;IACF;AACF,EAAC"}
1
+ {"version":3,"sources":["../../src/utilities/formatBreadcrumb.ts"],"sourcesContent":["import type { CollectionConfig } from 'payload'\n\nimport type { Breadcrumb, NestedDocsPluginConfig } from '../types.js'\n\nexport const formatBreadcrumb = (\n pluginConfig: NestedDocsPluginConfig,\n collection: CollectionConfig,\n docs: Array<Record<string, unknown>>,\n): Breadcrumb => {\n let url: string | undefined = undefined\n let label: string\n\n const lastDoc = docs[docs.length - 1]\n\n if (typeof pluginConfig?.generateURL === 'function') {\n url = pluginConfig.generateURL(docs, lastDoc)\n }\n\n if (typeof pluginConfig?.generateLabel === 'function') {\n label = pluginConfig.generateLabel(docs, lastDoc)\n } else {\n const useAsTitle = collection?.admin?.useAsTitle || 'id'\n label = lastDoc[useAsTitle] as string\n }\n\n return {\n doc: lastDoc.id as string,\n label,\n url,\n }\n}\n"],"names":["formatBreadcrumb","pluginConfig","collection","docs","url","undefined","label","lastDoc","length","generateURL","generateLabel","useAsTitle","admin","doc","id"],"mappings":"AAIA,OAAO,MAAMA,mBAAmB,CAC9BC,cACAC,YACAC;IAEA,IAAIC,MAA0BC;IAC9B,IAAIC;IAEJ,MAAMC,UAAUJ,IAAI,CAACA,KAAKK,MAAM,GAAG,EAAE;IAErC,IAAI,OAAOP,cAAcQ,gBAAgB,YAAY;QACnDL,MAAMH,aAAaQ,WAAW,CAACN,MAAMI;IACvC;IAEA,IAAI,OAAON,cAAcS,kBAAkB,YAAY;QACrDJ,QAAQL,aAAaS,aAAa,CAACP,MAAMI;IAC3C,OAAO;QACL,MAAMI,aAAaT,YAAYU,OAAOD,cAAc;QACpDL,QAAQC,OAAO,CAACI,WAAW;IAC7B;IAEA,OAAO;QACLE,KAAKN,QAAQO,EAAE;QACfR;QACAF;IACF;AACF,EAAC"}
@@ -1,4 +1,4 @@
1
- import type { CollectionConfig } from 'payload/types';
1
+ import type { CollectionConfig } from 'payload';
2
2
  import type { NestedDocsPluginConfig } from '../types.js';
3
3
  export declare const getParents: (req: any, pluginConfig: NestedDocsPluginConfig, collection: CollectionConfig, doc: Record<string, unknown>, docs?: Array<Record<string, unknown>>) => Promise<Array<Record<string, unknown>>>;
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,MAAM,eAAe,CAAA;AAErD,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAA;AAEzD,eAAO,MAAM,UAAU,QAChB,GAAG,gBACM,sBAAsB,cACxB,gBAAgB,OACvB,OAAO,MAAM,EAAE,OAAO,CAAC,SACtB,MAAM,OAAO,MAAM,EAAE,OAAO,CAAC,CAAC,KACnC,QAAQ,MAAM,OAAO,MAAM,EAAE,OAAO,CAAC,CAAC,CAmCxC,CAAA"}
1
+ {"version":3,"file":"getParents.d.ts","sourceRoot":"","sources":["../../src/utilities/getParents.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAE/C,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAA;AAEzD,eAAO,MAAM,UAAU,QAChB,GAAG,gBACM,sBAAsB,cACxB,gBAAgB,OACvB,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,SACtB,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,KACnC,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAmCxC,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utilities/getParents.ts"],"sourcesContent":["import type { CollectionConfig } from 'payload/types'\n\nimport type { NestedDocsPluginConfig } from '../types.js'\n\nexport const getParents = async (\n req: any,\n pluginConfig: NestedDocsPluginConfig,\n collection: CollectionConfig,\n doc: Record<string, unknown>,\n docs: Array<Record<string, unknown>> = [],\n): Promise<Array<Record<string, unknown>>> => {\n const parentSlug = pluginConfig?.parentFieldSlug || 'parent'\n const parent = doc[parentSlug]\n let retrievedParent\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\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"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","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;IAEJ,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
+ {"version":3,"sources":["../../src/utilities/getParents.ts"],"sourcesContent":["import type { CollectionConfig } from 'payload'\n\nimport type { NestedDocsPluginConfig } from '../types.js'\n\nexport const getParents = async (\n req: any,\n pluginConfig: NestedDocsPluginConfig,\n collection: CollectionConfig,\n doc: Record<string, unknown>,\n docs: Array<Record<string, unknown>> = [],\n): Promise<Array<Record<string, unknown>>> => {\n const parentSlug = pluginConfig?.parentFieldSlug || 'parent'\n const parent = doc[parentSlug]\n let retrievedParent\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\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;IAEJ,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,4 @@
1
- import type { CollectionConfig } from 'payload/types';
1
+ import type { CollectionConfig } from 'payload';
2
2
  import type { NestedDocsPluginConfig } from '../types.js';
3
3
  export declare const populateBreadcrumbs: (req: any, pluginConfig: NestedDocsPluginConfig, collection: CollectionConfig, data: any, originalDoc?: any) => Promise<any>;
4
4
  //# 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,gBAAgB,EAAE,MAAM,eAAe,CAAA;AAErD,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAA;AAKzD,eAAO,MAAM,mBAAmB,QACzB,GAAG,gBACM,sBAAsB,cACxB,gBAAgB,QACtB,GAAG,gBACK,GAAG,KAChB,QAAQ,GAAG,CA4Bb,CAAA"}
1
+ {"version":3,"file":"populateBreadcrumbs.d.ts","sourceRoot":"","sources":["../../src/utilities/populateBreadcrumbs.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAE/C,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAA;AAKzD,eAAO,MAAM,mBAAmB,QACzB,GAAG,gBACM,sBAAsB,cACxB,gBAAgB,QACtB,GAAG,gBACK,GAAG,KAChB,OAAO,CAAC,GAAG,CA4Bb,CAAA"}
@@ -16,8 +16,7 @@ export const populateBreadcrumbs = async (req, pluginConfig, collection, data, o
16
16
  currentDocBreadcrumb.id = originalDoc?.id;
17
17
  }
18
18
  breadcrumbDocs.push(currentDocBreadcrumb);
19
- const breadcrumbs = breadcrumbDocs.map((_, i)=>formatBreadcrumb(pluginConfig, collection, breadcrumbDocs.slice(0, i + 1))) // eslint-disable-line function-paren-newline
20
- ;
19
+ const breadcrumbs = breadcrumbDocs.map((_, i)=>formatBreadcrumb(pluginConfig, collection, breadcrumbDocs.slice(0, i + 1)));
21
20
  return {
22
21
  ...newData,
23
22
  [pluginConfig?.breadcrumbsFieldSlug || 'breadcrumbs']: breadcrumbs
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utilities/populateBreadcrumbs.ts"],"sourcesContent":["import type { CollectionConfig } from 'payload/types'\n\nimport type { NestedDocsPluginConfig } from '../types.js'\n\nimport { formatBreadcrumb } from './formatBreadcrumb.js'\nimport { getParents } from './getParents.js'\n\nexport const populateBreadcrumbs = async (\n req: any,\n pluginConfig: NestedDocsPluginConfig,\n collection: CollectionConfig,\n data: any,\n originalDoc?: any,\n): Promise<any> => {\n const newData = data\n const breadcrumbDocs = [\n ...(await getParents(req, pluginConfig, collection, {\n ...originalDoc,\n ...data,\n })),\n ]\n\n const currentDocBreadcrumb = {\n ...originalDoc,\n ...data,\n }\n\n if (originalDoc?.id) {\n currentDocBreadcrumb.id = originalDoc?.id\n }\n\n breadcrumbDocs.push(currentDocBreadcrumb)\n\n const breadcrumbs = breadcrumbDocs.map((_, i) =>\n formatBreadcrumb(pluginConfig, collection, breadcrumbDocs.slice(0, i + 1)),\n ) // eslint-disable-line function-paren-newline\n\n return {\n ...newData,\n [pluginConfig?.breadcrumbsFieldSlug || 'breadcrumbs']: breadcrumbs,\n }\n}\n"],"names":["formatBreadcrumb","getParents","populateBreadcrumbs","req","pluginConfig","collection","data","originalDoc","newData","breadcrumbDocs","currentDocBreadcrumb","id","push","breadcrumbs","map","_","i","slice","breadcrumbsFieldSlug"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAIA,SAASA,gBAAgB,QAAQ,wBAAuB;AACxD,SAASC,UAAU,QAAQ,kBAAiB;AAE5C,OAAO,MAAMC,sBAAsB,OACjCC,KACAC,cACAC,YACAC,MACAC;IAEA,MAAMC,UAAUF;IAChB,MAAMG,iBAAiB;WACjB,MAAMR,WAAWE,KAAKC,cAAcC,YAAY;YAClD,GAAGE,WAAW;YACd,GAAGD,IAAI;QACT;KACD;IAED,MAAMI,uBAAuB;QAC3B,GAAGH,WAAW;QACd,GAAGD,IAAI;IACT;IAEA,IAAIC,aAAaI,IAAI;QACnBD,qBAAqBC,EAAE,GAAGJ,aAAaI;IACzC;IAEAF,eAAeG,IAAI,CAACF;IAEpB,MAAMG,cAAcJ,eAAeK,GAAG,CAAC,CAACC,GAAGC,IACzChB,iBAAiBI,cAAcC,YAAYI,eAAeQ,KAAK,CAAC,GAAGD,IAAI,KACvE,6CAA6C;;IAE/C,OAAO;QACL,GAAGR,OAAO;QACV,CAACJ,cAAcc,wBAAwB,cAAc,EAAEL;IACzD;AACF,EAAC"}
1
+ {"version":3,"sources":["../../src/utilities/populateBreadcrumbs.ts"],"sourcesContent":["import type { CollectionConfig } from 'payload'\n\nimport type { NestedDocsPluginConfig } from '../types.js'\n\nimport { formatBreadcrumb } from './formatBreadcrumb.js'\nimport { getParents } from './getParents.js'\n\nexport const populateBreadcrumbs = async (\n req: any,\n pluginConfig: NestedDocsPluginConfig,\n collection: CollectionConfig,\n data: any,\n originalDoc?: any,\n): Promise<any> => {\n const newData = data\n const breadcrumbDocs = [\n ...(await getParents(req, pluginConfig, collection, {\n ...originalDoc,\n ...data,\n })),\n ]\n\n const currentDocBreadcrumb = {\n ...originalDoc,\n ...data,\n }\n\n if (originalDoc?.id) {\n currentDocBreadcrumb.id = originalDoc?.id\n }\n\n breadcrumbDocs.push(currentDocBreadcrumb)\n\n const breadcrumbs = breadcrumbDocs.map((_, i) =>\n formatBreadcrumb(pluginConfig, collection, breadcrumbDocs.slice(0, i + 1)),\n )\n\n return {\n ...newData,\n [pluginConfig?.breadcrumbsFieldSlug || 'breadcrumbs']: breadcrumbs,\n }\n}\n"],"names":["formatBreadcrumb","getParents","populateBreadcrumbs","req","pluginConfig","collection","data","originalDoc","newData","breadcrumbDocs","currentDocBreadcrumb","id","push","breadcrumbs","map","_","i","slice","breadcrumbsFieldSlug"],"mappings":"AAIA,SAASA,gBAAgB,QAAQ,wBAAuB;AACxD,SAASC,UAAU,QAAQ,kBAAiB;AAE5C,OAAO,MAAMC,sBAAsB,OACjCC,KACAC,cACAC,YACAC,MACAC;IAEA,MAAMC,UAAUF;IAChB,MAAMG,iBAAiB;WACjB,MAAMR,WAAWE,KAAKC,cAAcC,YAAY;YAClD,GAAGE,WAAW;YACd,GAAGD,IAAI;QACT;KACD;IAED,MAAMI,uBAAuB;QAC3B,GAAGH,WAAW;QACd,GAAGD,IAAI;IACT;IAEA,IAAIC,aAAaI,IAAI;QACnBD,qBAAqBC,EAAE,GAAGJ,aAAaI;IACzC;IAEAF,eAAeG,IAAI,CAACF;IAEpB,MAAMG,cAAcJ,eAAeK,GAAG,CAAC,CAACC,GAAGC,IACzChB,iBAAiBI,cAAcC,YAAYI,eAAeQ,KAAK,CAAC,GAAGD,IAAI;IAGzE,OAAO;QACL,GAAGR,OAAO;QACV,CAACJ,cAAcc,wBAAwB,cAAc,EAAEL;IACzD;AACF,EAAC"}
package/license.md ADDED
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2018-2024 Payload CMS, Inc. <info@payloadcms.com>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ 'Software'), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@payloadcms/plugin-nested-docs",
3
- "version": "3.0.0-canary.f6e77b8",
3
+ "version": "3.0.0-canary.fb04843",
4
4
  "description": "The official Nested Docs plugin for Payload",
5
5
  "homepage": "https://payloadcms.com",
6
6
  "repository": {
@@ -10,17 +10,24 @@
10
10
  },
11
11
  "license": "MIT",
12
12
  "author": "Payload <dev@payloadcms.com> (https://payloadcms.com)",
13
+ "maintainers": [
14
+ {
15
+ "name": "Payload",
16
+ "email": "info@payloadcms.com",
17
+ "url": "https://payloadcms.com"
18
+ }
19
+ ],
13
20
  "type": "module",
14
21
  "exports": {
15
22
  ".": {
16
23
  "import": "./dist/index.js",
17
- "require": "./dist/index.js",
18
- "types": "./dist/index.d.ts"
24
+ "types": "./dist/index.d.ts",
25
+ "default": "./dist/index.js"
19
26
  },
20
- "./*": {
21
- "import": "./dist/exports/*.js",
22
- "require": "./dist/exports/*.js",
23
- "types": "./dist/exports/*.d.ts"
27
+ "./types": {
28
+ "import": "./dist/exports/types.js",
29
+ "types": "./dist/exports/types.d.ts",
30
+ "default": "./dist/exports/types.js"
24
31
  }
25
32
  },
26
33
  "main": "./dist/index.js",
@@ -29,20 +36,22 @@
29
36
  "dist"
30
37
  ],
31
38
  "devDependencies": {
32
- "@payloadcms/eslint-config": "1.1.1",
33
- "payload": "3.0.0-canary.f6e77b8"
39
+ "@payloadcms/eslint-config": "3.0.0-beta.112",
40
+ "payload": "3.0.0-canary.fb04843"
34
41
  },
35
42
  "peerDependencies": {
36
- "payload": "3.0.0-canary.f6e77b8"
43
+ "payload": "3.0.0-canary.fb04843"
37
44
  },
38
45
  "publishConfig": {
39
46
  "registry": "https://registry.npmjs.org/"
40
47
  },
41
48
  "scripts": {
42
- "build": "pnpm copyfiles && pnpm build:swc && pnpm build:types",
43
- "build:swc": "swc ./src -d ./dist --config-file .swcrc",
49
+ "build": "pnpm copyfiles && pnpm build:types && pnpm build:swc",
50
+ "build:swc": "swc ./src -d ./dist --config-file .swcrc --strip-leading-paths",
44
51
  "build:types": "tsc --emitDeclarationOnly --outDir dist",
45
52
  "clean": "rimraf {dist,*.tsbuildinfo}",
46
- "copyfiles": "copyfiles -u 1 \"src/**/*.{html,css,scss,ttf,woff,woff2,eot,svg,jpg,png,json}\" dist/"
53
+ "copyfiles": "copyfiles -u 1 \"src/**/*.{html,css,scss,ttf,woff,woff2,eot,svg,jpg,png,json}\" dist/",
54
+ "lint": "eslint .",
55
+ "lint:fix": "eslint . --fix"
47
56
  }
48
57
  }