@payloadcms/plugin-nested-docs 3.0.0-alpha.59 → 3.0.0-alpha.61
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/fields/breadcrumbs.js.map +1 -1
- package/dist/fields/parent.js.map +1 -1
- package/dist/fields/parentFilterOptions.js.map +1 -1
- package/dist/hooks/resaveChildren.js.map +1 -1
- package/dist/hooks/resaveSelfAfterCreate.js.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/utilities/formatBreadcrumb.js.map +1 -1
- package/dist/utilities/getParents.js.map +1 -1
- package/dist/utilities/populateBreadcrumbs.js.map +1 -1
- package/package.json +3 -3
|
@@ -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\nexport default createBreadcrumbsField\n"],"names":["createBreadcrumbsField","relationTo","overrides","name","type","localized","admin","readOnly","fields","disabled","maxDepth","width","label"],"mappings":"AAEA,OAAO,MAAMA,yBAAyB,CACpCC,YACAC,YAAiC,CAAC,CAAC,GACxB,CAAA;QACXC,MAAM;QACNC,MAAM;QACNC,WAAW;QACX,GAAIH,aAAa,CAAC,CAAC;QACnBI,OAAO;YACLC,UAAU;YACV,GAAIL,WAAWI,SAAS,CAAC,CAAC;QAC5B;QACAE,QAAQ;YACN;gBACEL,MAAM;gBACNC,MAAM;gBACNE,OAAO;oBACLG,UAAU;gBACZ;gBACAC,UAAU;gBACVT;YACF;YACA;gBACEG,MAAM;gBACNI,QAAQ;oBACN;wBACEL,MAAM;wBACNC,MAAM;wBACNE,OAAO;4BACLK,OAAO;wBACT;wBACAC,OAAO;oBACT;oBACA;wBACET,MAAM;wBACNC,MAAM;wBACNE,OAAO;4BACLK,OAAO;wBACT;oBACF;iBACD;YACH;eACIT,WAAWM,UAAU,EAAE;SAC5B;IACH,CAAA,EAAE;AAEF,eAAeR,uBAAsB"}
|
|
1
|
+
{"version":3,"sources":["../../src/fields/breadcrumbs.ts"],"sourcesContent":["import type { ArrayField, Field } from 'payload/types'\n\nexport const createBreadcrumbsField = (\n relationTo: string,\n overrides: Partial<ArrayField> = {},\n): Field => ({\n name: 'breadcrumbs',\n type: 'array',\n localized: true,\n ...(overrides || {}),\n admin: {\n readOnly: true,\n ...(overrides?.admin || {}),\n },\n fields: [\n {\n name: 'doc',\n type: 'relationship',\n admin: {\n disabled: true,\n },\n maxDepth: 0,\n relationTo,\n },\n {\n type: 'row',\n fields: [\n {\n name: 'url',\n type: 'text',\n admin: {\n width: '50%',\n },\n label: 'URL',\n },\n {\n name: 'label',\n type: 'text',\n admin: {\n width: '50%',\n },\n },\n ],\n },\n ...(overrides?.fields || []),\n ],\n})\n\nexport default createBreadcrumbsField\n"],"names":["createBreadcrumbsField","relationTo","overrides","name","type","localized","admin","readOnly","fields","disabled","maxDepth","width","label"],"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;AAEF,eAAeR,uBAAsB"}
|
|
@@ -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\nexport default createParentField\n"],"names":["createParentField","relationTo","overrides","name","admin","position","type","maxDepth"],"mappings":"AAEA,OAAO,MAAMA,oBAAoB,CAC/BC,YACAC,YAK6B,CAAA;QAC7BC,MAAM;QACNC,OAAO;YACLC,UAAU;YACV,GAAIH,WAAWE,SAAS,CAAC,CAAC;QAC5B;QACA,mEAAmE;QACnE,wCAAwC;QACxCE,MAAM;QACNC,UAAU;QACVN;QACA,GAAIC,aAAa,CAAC,CAAC;IACrB,CAAA,EAAE;AAEF,eAAeF,kBAAiB"}
|
|
1
|
+
{"version":3,"sources":["../../src/fields/parent.ts"],"sourcesContent":["import type { SingleRelationshipField } from 'payload/types'\n\nexport const createParentField = (\n relationTo: string,\n overrides?: Partial<\n SingleRelationshipField & {\n hasMany: false\n }\n >,\n): SingleRelationshipField => ({\n name: 'parent',\n admin: {\n position: 'sidebar',\n ...(overrides?.admin || {}),\n },\n // filterOptions are assigned dynamically based on the pluginConfig\n // filterOptions: parentFilterOptions(),\n type: 'relationship',\n maxDepth: 1,\n relationTo,\n ...(overrides || {}),\n})\n\nexport default createParentField\n"],"names":["createParentField","relationTo","overrides","name","admin","position","type","maxDepth"],"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;AAEF,eAAeF,kBAAiB"}
|
|
@@ -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\nexport default parentFilterOptions\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;AAEH,eAAeF,oBAAmB"}
|
|
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\nexport default parentFilterOptions\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;AAEH,eAAeF,oBAAmB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/hooks/resaveChildren.ts"],"sourcesContent":["import type { CollectionAfterChangeHook, CollectionConfig, PayloadRequest } from 'payload/types'\n\nimport type { PluginConfig } 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: PluginConfig\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) 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\nconst resaveChildren =\n (pluginConfig: PluginConfig, 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 }\nexport default resaveChildren\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"],"mappings":"AAIA,OAAOA,yBAAyB,sCAAqC;AAUrE,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,MAAMG,iBACJ,CAAC/B,cAA4BH,aAC7B,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;AACF,eAAeD,eAAc"}
|
|
1
|
+
{"version":3,"sources":["../../src/hooks/resaveChildren.ts"],"sourcesContent":["import type { CollectionAfterChangeHook, CollectionConfig, PayloadRequest } from 'payload/types'\n\nimport type { PluginConfig } 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: PluginConfig\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) 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\nconst resaveChildren =\n (pluginConfig: PluginConfig, 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 }\nexport default resaveChildren\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":"AAIA,OAAOA,yBAAyB,sCAAqC;AAUrE,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,MAAMG,iBACJ,CAAC/B,cAA4BH,aAC7B,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;AACF,eAAeD,eAAc"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/hooks/resaveSelfAfterCreate.ts"],"sourcesContent":["import type { CollectionAfterChangeHook, CollectionConfig } from 'payload/types'\n\nimport type { PluginConfig } 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\nconst resaveSelfAfterCreate =\n (pluginConfig: PluginConfig, 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\nexport default resaveSelfAfterCreate\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,MAAMA,wBACJ,CAACC,cAA4BC,aAC7B,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;AAEF,eAAe9B,sBAAqB"}
|
|
1
|
+
{"version":3,"sources":["../../src/hooks/resaveSelfAfterCreate.ts"],"sourcesContent":["import type { CollectionAfterChangeHook, CollectionConfig } from 'payload/types'\n\nimport type { PluginConfig } 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\nconst resaveSelfAfterCreate =\n (pluginConfig: PluginConfig, 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\nexport default resaveSelfAfterCreate\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,MAAMA,wBACJ,CAACC,cAA4BC,aAC7B,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;AAEF,eAAe9B,sBAAqB"}
|
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 { PluginConfig } 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\nconst nestedDocs =\n (pluginConfig: PluginConfig): 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\nexport default nestedDocs\n"],"names":["createBreadcrumbsField","createParentField","parentFilterOptions","resaveChildren","resaveSelfAfterCreate","populateBreadcrumbs","nestedDocs","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":"AAKA,OAAOA,4BAA4B,0BAAyB;AAC5D,OAAOC,uBAAuB,qBAAoB;AAClD,OAAOC,yBAAyB,kCAAiC;AACjE,OAAOC,oBAAoB,4BAA2B;AACtD,OAAOC,2BAA2B,mCAAkC;AACpE,OAAOC,yBAAyB,qCAAoC;AAEpE,MAAMC,aACJ,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;AAEF,eAAeL,WAAU"}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { Plugin } from 'payload/config'\nimport type { SingleRelationshipField } from 'payload/types'\n\nimport type { PluginConfig } 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\nconst nestedDocs =\n (pluginConfig: PluginConfig): 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\nexport default nestedDocs\n"],"names":["createBreadcrumbsField","createParentField","parentFilterOptions","resaveChildren","resaveSelfAfterCreate","populateBreadcrumbs","nestedDocs","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,OAAOA,4BAA4B,0BAAyB;AAC5D,OAAOC,uBAAuB,qBAAoB;AAClD,OAAOC,yBAAyB,kCAAiC;AACjE,OAAOC,oBAAoB,4BAA2B;AACtD,OAAOC,2BAA2B,mCAAkC;AACpE,OAAOC,yBAAyB,qCAAoC;AAEpE,MAAMC,aACJ,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;AAEF,eAAeL,WAAU"}
|
package/dist/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/types.ts"],"sourcesContent":["export interface 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 interface PluginConfig {\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
|
+
{"version":3,"sources":["../src/types.ts"],"sourcesContent":["export interface 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 interface PluginConfig {\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 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utilities/formatBreadcrumb.ts"],"sourcesContent":["import type { CollectionConfig } from 'payload/types'\n\nimport type { Breadcrumb, PluginConfig } from '../types.js'\n\nconst formatBreadcrumb = (\n pluginConfig: PluginConfig,\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\nexport default formatBreadcrumb\n"],"names":["formatBreadcrumb","pluginConfig","collection","docs","url","undefined","label","lastDoc","length","generateURL","generateLabel","useAsTitle","admin","doc","id"],"mappings":"AAIA,MAAMA,mBAAmB,CACvBC,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;AAEA,eAAeJ,iBAAgB"}
|
|
1
|
+
{"version":3,"sources":["../../src/utilities/formatBreadcrumb.ts"],"sourcesContent":["import type { CollectionConfig } from 'payload/types'\n\nimport type { Breadcrumb, PluginConfig } from '../types.js'\n\nconst formatBreadcrumb = (\n pluginConfig: PluginConfig,\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\nexport default formatBreadcrumb\n"],"names":["formatBreadcrumb","pluginConfig","collection","docs","url","undefined","label","lastDoc","length","generateURL","generateLabel","useAsTitle","admin","doc","id"],"rangeMappings":";;;;;;;;;;;;;;;;;;;","mappings":"AAIA,MAAMA,mBAAmB,CACvBC,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;AAEA,eAAeJ,iBAAgB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utilities/getParents.ts"],"sourcesContent":["import type { CollectionConfig } from 'payload/types'\n\nimport type { PluginConfig } from '../types.js'\n\nconst getParents = async (\n req: any,\n pluginConfig: PluginConfig,\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\nexport default getParents\n"],"names":["getParents","req","pluginConfig","collection","doc","docs","parentSlug","parentFieldSlug","parent","retrievedParent","payload","findByID","id","slug","depth","disableErrors"],"mappings":"AAIA,MAAMA,aAAa,OACjBC,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;AAEA,eAAeL,WAAU"}
|
|
1
|
+
{"version":3,"sources":["../../src/utilities/getParents.ts"],"sourcesContent":["import type { CollectionConfig } from 'payload/types'\n\nimport type { PluginConfig } from '../types.js'\n\nconst getParents = async (\n req: any,\n pluginConfig: PluginConfig,\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\nexport default getParents\n"],"names":["getParents","req","pluginConfig","collection","doc","docs","parentSlug","parentFieldSlug","parent","retrievedParent","payload","findByID","id","slug","depth","disableErrors"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAIA,MAAMA,aAAa,OACjBC,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;AAEA,eAAeL,WAAU"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utilities/populateBreadcrumbs.ts"],"sourcesContent":["import type { CollectionConfig } from 'payload/types'\n\nimport type { PluginConfig } from '../types.js'\n\nimport formatBreadcrumb from './formatBreadcrumb.js'\nimport getParents from './getParents.js'\n\nconst populateBreadcrumbs = async (\n req: any,\n pluginConfig: PluginConfig,\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\nexport default populateBreadcrumbs\n"],"names":["formatBreadcrumb","getParents","populateBreadcrumbs","req","pluginConfig","collection","data","originalDoc","newData","breadcrumbDocs","currentDocBreadcrumb","id","push","breadcrumbs","map","_","i","slice","breadcrumbsFieldSlug"],"mappings":"AAIA,OAAOA,sBAAsB,wBAAuB;AACpD,OAAOC,gBAAgB,kBAAiB;AAExC,MAAMC,sBAAsB,OAC1BC,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;AAEA,eAAeX,oBAAmB"}
|
|
1
|
+
{"version":3,"sources":["../../src/utilities/populateBreadcrumbs.ts"],"sourcesContent":["import type { CollectionConfig } from 'payload/types'\n\nimport type { PluginConfig } from '../types.js'\n\nimport formatBreadcrumb from './formatBreadcrumb.js'\nimport getParents from './getParents.js'\n\nconst populateBreadcrumbs = async (\n req: any,\n pluginConfig: PluginConfig,\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\nexport default populateBreadcrumbs\n"],"names":["formatBreadcrumb","getParents","populateBreadcrumbs","req","pluginConfig","collection","data","originalDoc","newData","breadcrumbDocs","currentDocBreadcrumb","id","push","breadcrumbs","map","_","i","slice","breadcrumbsFieldSlug"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAIA,OAAOA,sBAAsB,wBAAuB;AACpD,OAAOC,gBAAgB,kBAAiB;AAExC,MAAMC,sBAAsB,OAC1BC,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;AAEA,eAAeX,oBAAmB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@payloadcms/plugin-nested-docs",
|
|
3
|
-
"version": "3.0.0-alpha.
|
|
3
|
+
"version": "3.0.0-alpha.61",
|
|
4
4
|
"description": "The official Nested Docs plugin for Payload",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -15,10 +15,10 @@
|
|
|
15
15
|
"type": "module",
|
|
16
16
|
"devDependencies": {
|
|
17
17
|
"@payloadcms/eslint-config": "1.1.1",
|
|
18
|
-
"payload": "3.0.0-alpha.
|
|
18
|
+
"payload": "3.0.0-alpha.61"
|
|
19
19
|
},
|
|
20
20
|
"peerDependencies": {
|
|
21
|
-
"payload": "3.0.0-alpha.
|
|
21
|
+
"payload": "3.0.0-alpha.61"
|
|
22
22
|
},
|
|
23
23
|
"exports": {
|
|
24
24
|
".": {
|