@veiag/payload-enhanced-sidebar 0.3.0 → 0.3.2-canary.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -575,6 +575,7 @@ label: {
575
575
 
576
576
  - **Browse by Folder Button** - Automatically shows folder view button when Payload folders are enabled (requires Payload v3.41.0+)
577
577
  - **Settings Menu Items** - Integrates with Payload's SettingsMenu components (requires Payload v3.60.0+)
578
+ - **`beforeNav` / `afterNav` slots** - Supports Payload's `admin.components.beforeNav` and `admin.components.afterNav` slots (requires Payload v3.75.0+). Both slots are rendered inside the nav content area — `beforeNav` before `beforeNavLinks`, `afterNav` after `afterNavLinks`.
578
579
 
579
580
  ## Contributing
580
581
 
@@ -13,19 +13,21 @@ const TabPanel = ({ id, children })=>{
13
13
  children: children
14
14
  });
15
15
  };
16
- export const NavContent = ({ afterNavLinks, allContent, beforeNavLinks, tabs, tabsContent })=>{
16
+ export const NavContent = ({ afterNav, afterNavLinks, allContent, beforeNav, beforeNavLinks, tabs, tabsContent })=>{
17
17
  const hasTabs = tabs.length > 0;
18
18
  return /*#__PURE__*/ _jsx("nav", {
19
19
  className: `${baseClass}__content`,
20
20
  children: /*#__PURE__*/ _jsxs("div", {
21
21
  className: `${baseClass}__content-scroll`,
22
22
  children: [
23
+ beforeNav,
23
24
  beforeNavLinks,
24
25
  hasTabs ? tabs.map((tab)=>/*#__PURE__*/ _jsx(TabPanel, {
25
26
  id: tab.id,
26
27
  children: tabsContent[tab.id]
27
28
  }, tab.id)) : allContent,
28
- afterNavLinks
29
+ afterNavLinks,
30
+ afterNav
29
31
  ]
30
32
  })
31
33
  });
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/components/EnhancedSidebar/NavContent/index.tsx"],"sourcesContent":["'use client'\n\nimport React from 'react'\n\nimport type { CustomNavContentProps } from '../../../types'\n\nimport { useTabState } from '../hooks/useTabState'\n\nconst baseClass = 'enhanced-sidebar'\n\nconst TabPanel: React.FC<{ children: React.ReactNode; id: string }> = ({ id, children }) => {\n const { isActive } = useTabState(id)\n return (\n <div aria-hidden={!isActive} style={{ display: isActive ? undefined : 'none' }}>\n {children}\n </div>\n )\n}\n\nexport const NavContent: React.FC<CustomNavContentProps> = ({\n afterNavLinks,\n allContent,\n beforeNavLinks,\n tabs,\n tabsContent,\n}) => {\n const hasTabs = tabs.length > 0\n\n return (\n <nav className={`${baseClass}__content`}>\n <div className={`${baseClass}__content-scroll`}>\n {beforeNavLinks}\n {hasTabs\n ? tabs.map((tab) => (\n <TabPanel id={tab.id} key={tab.id}>\n {tabsContent[tab.id]}\n </TabPanel>\n ))\n : allContent}\n {afterNavLinks}\n </div>\n </nav>\n )\n}\n"],"names":["React","useTabState","baseClass","TabPanel","id","children","isActive","div","aria-hidden","style","display","undefined","NavContent","afterNavLinks","allContent","beforeNavLinks","tabs","tabsContent","hasTabs","length","nav","className","map","tab"],"mappings":"AAAA;;AAEA,OAAOA,WAAW,QAAO;AAIzB,SAASC,WAAW,QAAQ,uBAAsB;AAElD,MAAMC,YAAY;AAElB,MAAMC,WAAgE,CAAC,EAAEC,EAAE,EAAEC,QAAQ,EAAE;IACrF,MAAM,EAAEC,QAAQ,EAAE,GAAGL,YAAYG;IACjC,qBACE,KAACG;QAAIC,eAAa,CAACF;QAAUG,OAAO;YAAEC,SAASJ,WAAWK,YAAY;QAAO;kBAC1EN;;AAGP;AAEA,OAAO,MAAMO,aAA8C,CAAC,EAC1DC,aAAa,EACbC,UAAU,EACVC,cAAc,EACdC,IAAI,EACJC,WAAW,EACZ;IACC,MAAMC,UAAUF,KAAKG,MAAM,GAAG;IAE9B,qBACE,KAACC;QAAIC,WAAW,GAAGnB,UAAU,SAAS,CAAC;kBACrC,cAAA,MAACK;YAAIc,WAAW,GAAGnB,UAAU,gBAAgB,CAAC;;gBAC3Ca;gBACAG,UACGF,KAAKM,GAAG,CAAC,CAACC,oBACR,KAACpB;wBAASC,IAAImB,IAAInB,EAAE;kCACjBa,WAAW,CAACM,IAAInB,EAAE,CAAC;uBADKmB,IAAInB,EAAE,KAInCU;gBACHD;;;;AAIT,EAAC"}
1
+ {"version":3,"sources":["../../../../src/components/EnhancedSidebar/NavContent/index.tsx"],"sourcesContent":["'use client'\n\nimport React from 'react'\n\nimport type { CustomNavContentProps } from '../../../types'\n\nimport { useTabState } from '../hooks/useTabState'\n\nconst baseClass = 'enhanced-sidebar'\n\nconst TabPanel: React.FC<{ children: React.ReactNode; id: string }> = ({ id, children }) => {\n const { isActive } = useTabState(id)\n return (\n <div aria-hidden={!isActive} style={{ display: isActive ? undefined : 'none' }}>\n {children}\n </div>\n )\n}\n\nexport const NavContent: React.FC<CustomNavContentProps> = ({\n afterNav,\n afterNavLinks,\n allContent,\n beforeNav,\n beforeNavLinks,\n tabs,\n tabsContent,\n}) => {\n const hasTabs = tabs.length > 0\n\n return (\n <nav className={`${baseClass}__content`}>\n <div className={`${baseClass}__content-scroll`}>\n {beforeNav}\n {beforeNavLinks}\n {hasTabs\n ? tabs.map((tab) => (\n <TabPanel id={tab.id} key={tab.id}>\n {tabsContent[tab.id]}\n </TabPanel>\n ))\n : allContent}\n {afterNavLinks}\n {afterNav}\n </div>\n </nav>\n )\n}\n"],"names":["React","useTabState","baseClass","TabPanel","id","children","isActive","div","aria-hidden","style","display","undefined","NavContent","afterNav","afterNavLinks","allContent","beforeNav","beforeNavLinks","tabs","tabsContent","hasTabs","length","nav","className","map","tab"],"mappings":"AAAA;;AAEA,OAAOA,WAAW,QAAO;AAIzB,SAASC,WAAW,QAAQ,uBAAsB;AAElD,MAAMC,YAAY;AAElB,MAAMC,WAAgE,CAAC,EAAEC,EAAE,EAAEC,QAAQ,EAAE;IACrF,MAAM,EAAEC,QAAQ,EAAE,GAAGL,YAAYG;IACjC,qBACE,KAACG;QAAIC,eAAa,CAACF;QAAUG,OAAO;YAAEC,SAASJ,WAAWK,YAAY;QAAO;kBAC1EN;;AAGP;AAEA,OAAO,MAAMO,aAA8C,CAAC,EAC1DC,QAAQ,EACRC,aAAa,EACbC,UAAU,EACVC,SAAS,EACTC,cAAc,EACdC,IAAI,EACJC,WAAW,EACZ;IACC,MAAMC,UAAUF,KAAKG,MAAM,GAAG;IAE9B,qBACE,KAACC;QAAIC,WAAW,GAAGrB,UAAU,SAAS,CAAC;kBACrC,cAAA,MAACK;YAAIgB,WAAW,GAAGrB,UAAU,gBAAgB,CAAC;;gBAC3Cc;gBACAC;gBACAG,UACGF,KAAKM,GAAG,CAAC,CAACC,oBACR,KAACtB;wBAASC,IAAIqB,IAAIrB,EAAE;kCACjBe,WAAW,CAACM,IAAIrB,EAAE,CAAC;uBADKqB,IAAIrB,EAAE,KAInCW;gBACHD;gBACAD;;;;AAIT,EAAC"}
@@ -1,8 +1,10 @@
1
1
  import React from 'react';
2
2
  import type { EnhancedSidebarConfig } from '../../types';
3
3
  export type SidebarContentProps = {
4
+ afterNav?: React.ReactNode;
4
5
  afterNavLinks?: React.ReactNode;
5
6
  allContent?: React.ReactNode;
7
+ beforeNav?: React.ReactNode;
6
8
  beforeNavLinks?: React.ReactNode;
7
9
  customNavContent?: React.ReactNode;
8
10
  customTabComponents?: Record<string, React.ReactNode>;
@@ -10,7 +10,7 @@ const COOKIE_KEY = 'payload-enhanced-sidebar-active-tab';
10
10
  const setTabCookie = (tabId)=>{
11
11
  document.cookie = `${COOKIE_KEY}=${tabId}; path=/; max-age=31536000; SameSite=Lax`;
12
12
  };
13
- export const SidebarContent = ({ afterNavLinks, allContent, beforeNavLinks, customNavContent, customTabComponents, initialActiveTabId, renderedTabItems, settingsMenu, sidebarConfig, tabIcons, tabsContent })=>{
13
+ export const SidebarContent = ({ afterNav, afterNavLinks, allContent, beforeNav, beforeNavLinks, customNavContent, customTabComponents, initialActiveTabId, renderedTabItems, settingsMenu, sidebarConfig, tabIcons, tabsContent })=>{
14
14
  const [activeTabId, setActiveTabId] = useState(initialActiveTabId);
15
15
  const handleTabChange = useCallback((tabId)=>{
16
16
  setActiveTabId(tabId);
@@ -39,8 +39,10 @@ export const SidebarContent = ({ afterNavLinks, allContent, beforeNavLinks, cust
39
39
  tabIcons: tabIcons
40
40
  }),
41
41
  customNavContent ?? /*#__PURE__*/ _jsx(NavContent, {
42
+ afterNav: afterNav,
42
43
  afterNavLinks: afterNavLinks,
43
44
  allContent: allContent,
45
+ beforeNav: beforeNav,
44
46
  beforeNavLinks: beforeNavLinks,
45
47
  tabs: tabs,
46
48
  tabsContent: tabsContent
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/components/EnhancedSidebar/SidebarContent.tsx"],"sourcesContent":["'use client'\n\nimport React, { useCallback, useMemo, useState } from 'react'\n\nimport type { EnhancedSidebarConfig } from '../../types'\n\nimport { EnhancedSidebarContext } from './context'\nimport { NavContent } from './NavContent'\nimport { SidebarWrapper } from './SidebarWrapper'\nimport { TabsBar } from './TabsBar'\n\nconst baseClass = 'enhanced-sidebar'\n\nexport type SidebarContentProps = {\n afterNavLinks?: React.ReactNode\n allContent?: React.ReactNode\n beforeNavLinks?: React.ReactNode\n customNavContent?: React.ReactNode\n customTabComponents?: Record<string, React.ReactNode>\n initialActiveTabId: string\n renderedTabItems?: React.ReactNode[]\n settingsMenu?: React.ReactNode[]\n sidebarConfig: EnhancedSidebarConfig\n tabIcons?: Record<string, React.ReactNode>\n tabsContent: Record<string, React.ReactNode>\n}\n\nconst COOKIE_KEY = 'payload-enhanced-sidebar-active-tab'\n\nconst setTabCookie = (tabId: string) => {\n document.cookie = `${COOKIE_KEY}=${tabId}; path=/; max-age=31536000; SameSite=Lax`\n}\n\nexport const SidebarContent: React.FC<SidebarContentProps> = ({\n afterNavLinks,\n allContent,\n beforeNavLinks,\n customNavContent,\n customTabComponents,\n initialActiveTabId,\n renderedTabItems,\n settingsMenu,\n sidebarConfig,\n tabIcons,\n tabsContent,\n}) => {\n const [activeTabId, setActiveTabId] = useState(initialActiveTabId)\n\n const handleTabChange = useCallback((tabId: string) => {\n setActiveTabId(tabId)\n setTabCookie(tabId)\n }, [])\n\n const contextValue = useMemo(\n () => ({ activeTabId, onTabChange: handleTabChange }),\n [activeTabId, handleTabChange],\n )\n\n const tabs = sidebarConfig.tabs?.filter((t) => t.type === 'tab') ?? []\n\n return (\n <EnhancedSidebarContext.Provider value={contextValue}>\n <SidebarWrapper baseClass={baseClass}>\n <TabsBar\n activeTabId={activeTabId}\n customTabComponents={customTabComponents}\n onTabChange={handleTabChange}\n renderedTabItems={renderedTabItems}\n settingsMenu={settingsMenu}\n sidebarConfig={sidebarConfig}\n tabIcons={tabIcons}\n />\n {customNavContent ?? (\n <NavContent\n afterNavLinks={afterNavLinks}\n allContent={allContent}\n beforeNavLinks={beforeNavLinks}\n tabs={tabs}\n tabsContent={tabsContent}\n />\n )}\n </SidebarWrapper>\n </EnhancedSidebarContext.Provider>\n )\n}\n"],"names":["React","useCallback","useMemo","useState","EnhancedSidebarContext","NavContent","SidebarWrapper","TabsBar","baseClass","COOKIE_KEY","setTabCookie","tabId","document","cookie","SidebarContent","afterNavLinks","allContent","beforeNavLinks","customNavContent","customTabComponents","initialActiveTabId","renderedTabItems","settingsMenu","sidebarConfig","tabIcons","tabsContent","activeTabId","setActiveTabId","handleTabChange","contextValue","onTabChange","tabs","filter","t","type","Provider","value"],"mappings":"AAAA;;AAEA,OAAOA,SAASC,WAAW,EAAEC,OAAO,EAAEC,QAAQ,QAAQ,QAAO;AAI7D,SAASC,sBAAsB,QAAQ,YAAW;AAClD,SAASC,UAAU,QAAQ,eAAc;AACzC,SAASC,cAAc,QAAQ,mBAAkB;AACjD,SAASC,OAAO,QAAQ,YAAW;AAEnC,MAAMC,YAAY;AAgBlB,MAAMC,aAAa;AAEnB,MAAMC,eAAe,CAACC;IACpBC,SAASC,MAAM,GAAG,GAAGJ,WAAW,CAAC,EAAEE,MAAM,wCAAwC,CAAC;AACpF;AAEA,OAAO,MAAMG,iBAAgD,CAAC,EAC5DC,aAAa,EACbC,UAAU,EACVC,cAAc,EACdC,gBAAgB,EAChBC,mBAAmB,EACnBC,kBAAkB,EAClBC,gBAAgB,EAChBC,YAAY,EACZC,aAAa,EACbC,QAAQ,EACRC,WAAW,EACZ;IACC,MAAM,CAACC,aAAaC,eAAe,GAAGxB,SAASiB;IAE/C,MAAMQ,kBAAkB3B,YAAY,CAACU;QACnCgB,eAAehB;QACfD,aAAaC;IACf,GAAG,EAAE;IAEL,MAAMkB,eAAe3B,QACnB,IAAO,CAAA;YAAEwB;YAAaI,aAAaF;QAAgB,CAAA,GACnD;QAACF;QAAaE;KAAgB;IAGhC,MAAMG,OAAOR,cAAcQ,IAAI,EAAEC,OAAO,CAACC,IAAMA,EAAEC,IAAI,KAAK,UAAU,EAAE;IAEtE,qBACE,KAAC9B,uBAAuB+B,QAAQ;QAACC,OAAOP;kBACtC,cAAA,MAACvB;YAAeE,WAAWA;;8BACzB,KAACD;oBACCmB,aAAaA;oBACbP,qBAAqBA;oBACrBW,aAAaF;oBACbP,kBAAkBA;oBAClBC,cAAcA;oBACdC,eAAeA;oBACfC,UAAUA;;gBAEXN,kCACC,KAACb;oBACCU,eAAeA;oBACfC,YAAYA;oBACZC,gBAAgBA;oBAChBc,MAAMA;oBACNN,aAAaA;;;;;AAMzB,EAAC"}
1
+ {"version":3,"sources":["../../../src/components/EnhancedSidebar/SidebarContent.tsx"],"sourcesContent":["'use client'\n\nimport React, { useCallback, useMemo, useState } from 'react'\n\nimport type { EnhancedSidebarConfig } from '../../types'\n\nimport { EnhancedSidebarContext } from './context'\nimport { NavContent } from './NavContent'\nimport { SidebarWrapper } from './SidebarWrapper'\nimport { TabsBar } from './TabsBar'\n\nconst baseClass = 'enhanced-sidebar'\n\nexport type SidebarContentProps = {\n afterNav?: React.ReactNode\n afterNavLinks?: React.ReactNode\n allContent?: React.ReactNode\n beforeNav?: React.ReactNode\n beforeNavLinks?: React.ReactNode\n customNavContent?: React.ReactNode\n customTabComponents?: Record<string, React.ReactNode>\n initialActiveTabId: string\n renderedTabItems?: React.ReactNode[]\n settingsMenu?: React.ReactNode[]\n sidebarConfig: EnhancedSidebarConfig\n tabIcons?: Record<string, React.ReactNode>\n tabsContent: Record<string, React.ReactNode>\n}\n\nconst COOKIE_KEY = 'payload-enhanced-sidebar-active-tab'\n\nconst setTabCookie = (tabId: string) => {\n document.cookie = `${COOKIE_KEY}=${tabId}; path=/; max-age=31536000; SameSite=Lax`\n}\n\nexport const SidebarContent: React.FC<SidebarContentProps> = ({\n afterNav,\n afterNavLinks,\n allContent,\n beforeNav,\n beforeNavLinks,\n customNavContent,\n customTabComponents,\n initialActiveTabId,\n renderedTabItems,\n settingsMenu,\n sidebarConfig,\n tabIcons,\n tabsContent,\n}) => {\n const [activeTabId, setActiveTabId] = useState(initialActiveTabId)\n\n const handleTabChange = useCallback((tabId: string) => {\n setActiveTabId(tabId)\n setTabCookie(tabId)\n }, [])\n\n const contextValue = useMemo(\n () => ({ activeTabId, onTabChange: handleTabChange }),\n [activeTabId, handleTabChange],\n )\n\n const tabs = sidebarConfig.tabs?.filter((t) => t.type === 'tab') ?? []\n\n return (\n <EnhancedSidebarContext.Provider value={contextValue}>\n <SidebarWrapper baseClass={baseClass}>\n <TabsBar\n activeTabId={activeTabId}\n customTabComponents={customTabComponents}\n onTabChange={handleTabChange}\n renderedTabItems={renderedTabItems}\n settingsMenu={settingsMenu}\n sidebarConfig={sidebarConfig}\n tabIcons={tabIcons}\n />\n {customNavContent ?? (\n <NavContent\n afterNav={afterNav}\n afterNavLinks={afterNavLinks}\n allContent={allContent}\n beforeNav={beforeNav}\n beforeNavLinks={beforeNavLinks}\n tabs={tabs}\n tabsContent={tabsContent}\n />\n )}\n </SidebarWrapper>\n </EnhancedSidebarContext.Provider>\n )\n}\n"],"names":["React","useCallback","useMemo","useState","EnhancedSidebarContext","NavContent","SidebarWrapper","TabsBar","baseClass","COOKIE_KEY","setTabCookie","tabId","document","cookie","SidebarContent","afterNav","afterNavLinks","allContent","beforeNav","beforeNavLinks","customNavContent","customTabComponents","initialActiveTabId","renderedTabItems","settingsMenu","sidebarConfig","tabIcons","tabsContent","activeTabId","setActiveTabId","handleTabChange","contextValue","onTabChange","tabs","filter","t","type","Provider","value"],"mappings":"AAAA;;AAEA,OAAOA,SAASC,WAAW,EAAEC,OAAO,EAAEC,QAAQ,QAAQ,QAAO;AAI7D,SAASC,sBAAsB,QAAQ,YAAW;AAClD,SAASC,UAAU,QAAQ,eAAc;AACzC,SAASC,cAAc,QAAQ,mBAAkB;AACjD,SAASC,OAAO,QAAQ,YAAW;AAEnC,MAAMC,YAAY;AAkBlB,MAAMC,aAAa;AAEnB,MAAMC,eAAe,CAACC;IACpBC,SAASC,MAAM,GAAG,GAAGJ,WAAW,CAAC,EAAEE,MAAM,wCAAwC,CAAC;AACpF;AAEA,OAAO,MAAMG,iBAAgD,CAAC,EAC5DC,QAAQ,EACRC,aAAa,EACbC,UAAU,EACVC,SAAS,EACTC,cAAc,EACdC,gBAAgB,EAChBC,mBAAmB,EACnBC,kBAAkB,EAClBC,gBAAgB,EAChBC,YAAY,EACZC,aAAa,EACbC,QAAQ,EACRC,WAAW,EACZ;IACC,MAAM,CAACC,aAAaC,eAAe,GAAG1B,SAASmB;IAE/C,MAAMQ,kBAAkB7B,YAAY,CAACU;QACnCkB,eAAelB;QACfD,aAAaC;IACf,GAAG,EAAE;IAEL,MAAMoB,eAAe7B,QACnB,IAAO,CAAA;YAAE0B;YAAaI,aAAaF;QAAgB,CAAA,GACnD;QAACF;QAAaE;KAAgB;IAGhC,MAAMG,OAAOR,cAAcQ,IAAI,EAAEC,OAAO,CAACC,IAAMA,EAAEC,IAAI,KAAK,UAAU,EAAE;IAEtE,qBACE,KAAChC,uBAAuBiC,QAAQ;QAACC,OAAOP;kBACtC,cAAA,MAACzB;YAAeE,WAAWA;;8BACzB,KAACD;oBACCqB,aAAaA;oBACbP,qBAAqBA;oBACrBW,aAAaF;oBACbP,kBAAkBA;oBAClBC,cAAcA;oBACdC,eAAeA;oBACfC,UAAUA;;gBAEXN,kCACC,KAACf;oBACCU,UAAUA;oBACVC,eAAeA;oBACfC,YAAYA;oBACZC,WAAWA;oBACXC,gBAAgBA;oBAChBc,MAAMA;oBACNN,aAAaA;;;;;AAMzB,EAAC"}
@@ -1,4 +1,6 @@
1
- @import '~@payloadcms/ui/scss';
1
+ @import "../../../../node_modules/@payloadcms/ui/dist/scss/vars";
2
+ @import "../../../../node_modules/@payloadcms/ui/dist/scss/queries.scss";
3
+
2
4
 
3
5
  @layer payload-default {
4
6
  .tabs-bar {
@@ -109,7 +109,7 @@ export const EnhancedSidebar = async (props)=>{
109
109
  if (!payload?.config) {
110
110
  return null;
111
111
  }
112
- const { admin: { components: { afterNavLinks, beforeNavLinks, settingsMenu } }, collections, globals } = payload.config;
112
+ const { admin: { components: { afterNav, afterNavLinks, beforeNav, beforeNavLinks, settingsMenu } }, collections, globals } = payload.config;
113
113
  const groups = groupNavItems([
114
114
  ...collections.filter(({ slug })=>visibleEntities?.collections.includes(slug)).map((collection)=>({
115
115
  type: EntityType.collection,
@@ -134,6 +134,12 @@ export const EnhancedSidebar = async (props)=>{
134
134
  documentSubViewType,
135
135
  viewType
136
136
  };
137
+ const beforeNavRendered = RenderServerComponent({
138
+ clientProps,
139
+ Component: beforeNav,
140
+ importMap: payload.importMap,
141
+ serverProps
142
+ });
137
143
  const beforeNavLinksRendered = RenderServerComponent({
138
144
  clientProps,
139
145
  Component: beforeNavLinks,
@@ -146,6 +152,12 @@ export const EnhancedSidebar = async (props)=>{
146
152
  importMap: payload.importMap,
147
153
  serverProps
148
154
  });
155
+ const afterNavRendered = RenderServerComponent({
156
+ clientProps,
157
+ Component: afterNav,
158
+ importMap: payload.importMap,
159
+ serverProps
160
+ });
149
161
  const renderedSettingsMenu = settingsMenu && Array.isArray(settingsMenu) ? settingsMenu.map((item, index)=>RenderServerComponent({
150
162
  clientProps,
151
163
  Component: item,
@@ -373,8 +385,10 @@ export const EnhancedSidebar = async (props)=>{
373
385
  const { clientProps: extraProps, path } = resolveSidebarComponent(config.customComponents.NavContent);
374
386
  return RenderServerComponent({
375
387
  clientProps: {
388
+ afterNav: afterNavRendered,
376
389
  afterNavLinks: afterNavLinksRendered,
377
390
  allContent,
391
+ beforeNav: beforeNavRendered,
378
392
  beforeNavLinks: beforeNavLinksRendered,
379
393
  tabs: tabs.map((t)=>({
380
394
  id: t.id
@@ -394,8 +408,10 @@ export const EnhancedSidebar = async (props)=>{
394
408
  tabs: visibleTabItems
395
409
  });
396
410
  return /*#__PURE__*/ _jsx(SidebarContent, {
411
+ afterNav: afterNavRendered,
397
412
  afterNavLinks: afterNavLinksRendered,
398
413
  allContent: allContent,
414
+ beforeNav: beforeNavRendered,
399
415
  beforeNavLinks: beforeNavLinksRendered,
400
416
  customNavContent: customNavContent,
401
417
  customTabComponents: Object.keys(customTabComponents).length > 0 ? customTabComponents : undefined,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/components/EnhancedSidebar/index.tsx"],"sourcesContent":["import type { EntityToGroup } from '@payloadcms/ui/shared'\nimport type { PayloadRequest, ServerProps } from 'payload'\n\nimport { getTranslation } from '@payloadcms/translations'\nimport { NavGroup } from '@payloadcms/ui'\nimport { RenderServerComponent } from '@payloadcms/ui/elements/RenderServerComponent'\nimport { EntityType, groupNavItems } from '@payloadcms/ui/shared'\nimport { cookies } from 'next/headers'\nimport { formatAdminURL } from 'payload/shared'\nimport React, { Fragment } from 'react'\n\nconst COOKIE_KEY = 'payload-enhanced-sidebar-active-tab'\n\nimport type {\n EnhancedSidebarConfig,\n ExtendedEntity,\n ExtendedGroup,\n SidebarTab,\n SidebarTabContent as SidebarTabContentType,\n SidebarTabItem,\n} from '../../types'\n\nimport { extractLocalizedValue, resolveSidebarComponent, sanitizeSidebarConfig } from '../../utils'\nimport { getNavPrefs } from './getNavPrefs'\nimport { Icon } from './Icon'\nimport { NavItem } from './NavItem'\nimport { SidebarContent } from './SidebarContent'\nimport './index.scss'\n\nexport type EnhancedSidebarProps = {\n req?: PayloadRequest\n sidebarConfig?: EnhancedSidebarConfig\n} & ServerProps\n\n/**\n * Computes filtered and merged groups for a specific tab (server-side).\n */\nconst computeGroupsForTab = async (\n tab: SidebarTabContentType,\n groups: ExtendedGroup[],\n currentLang: string,\n req: PayloadRequest | undefined,\n): Promise<ExtendedGroup[]> => {\n const { collections: tabCollections, customItems, globals: tabGlobals } = tab\n\n const showAll = !tabCollections && !tabGlobals\n const allowedSlugs = new Set([...(tabCollections ?? []), ...(tabGlobals ?? [])])\n\n let result: ExtendedGroup[] = []\n\n if (showAll) {\n result = groups.map((g) => ({ ...g, entities: [...g.entities] }))\n } else if (allowedSlugs.size > 0) {\n result = groups\n .map((group) => ({\n ...group,\n entities: group.entities.filter((entity) => allowedSlugs.has(entity.slug)),\n }))\n .filter((group) => group.entities.length > 0)\n }\n\n if (customItems && customItems.length > 0) {\n const topAdditions: ExtendedGroup[] = []\n const topUngrouped: SidebarTabItem[] = []\n const bottomUngrouped: SidebarTabItem[] = []\n\n const toEntity = (item: SidebarTabItem): ExtendedEntity =>\n ({\n slug: item.slug,\n type: 'custom',\n href: item.href,\n isExternal: item.isExternal,\n label: item.label,\n }) as ExtendedEntity\n\n // Filter custom items by access — fail-closed: missing req or thrown error denies access\n const accessResults = await Promise.all(\n customItems.map((item) =>\n Promise.resolve()\n .then(() => (item.access ? (req ? item.access({ item, req }) : false) : true))\n .catch(() => false),\n ),\n )\n const visibleItems = customItems.filter((_, i) => accessResults[i])\n\n for (const item of visibleItems) {\n if (item.group) {\n const itemGroupLabel = extractLocalizedValue(item.group, currentLang)\n const existingGroup = result.find((g) => {\n const groupLabel = extractLocalizedValue(g.label, currentLang)\n return groupLabel === itemGroupLabel\n })\n\n if (existingGroup) {\n // Merged into existing collection group — position has no effect here\n existingGroup.entities.push(toEntity(item))\n } else {\n // New custom group — position controls top vs bottom\n const newGroup: ExtendedGroup = { entities: [toEntity(item)], label: item.group }\n if (item.position === 'top') {\n topAdditions.push(newGroup)\n } else {\n result.push(newGroup)\n }\n }\n } else {\n if (item.position === 'top') {\n topUngrouped.push(item)\n } else {\n bottomUngrouped.push(item)\n }\n }\n }\n\n if (topUngrouped.length > 0) {\n topAdditions.unshift({ entities: topUngrouped.map(toEntity), label: '' })\n }\n\n if (bottomUngrouped.length > 0) {\n result.push({ entities: bottomUngrouped.map(toEntity), label: '' })\n }\n\n result = [...topAdditions, ...result]\n }\n\n return result\n}\n\nexport const EnhancedSidebar: React.FC<EnhancedSidebarProps> = async (props) => {\n const {\n documentSubViewType,\n i18n,\n locale,\n params,\n payload,\n permissions,\n req,\n searchParams,\n sidebarConfig,\n user,\n viewType,\n visibleEntities,\n } = props\n\n if (!payload?.config) {\n return null\n }\n\n const {\n admin: {\n components: { afterNavLinks, beforeNavLinks, settingsMenu },\n },\n collections,\n globals,\n } = payload.config\n\n const groups = groupNavItems(\n [\n ...collections\n .filter(({ slug }) => visibleEntities?.collections.includes(slug))\n .map(\n (collection) =>\n ({\n type: EntityType.collection,\n entity: collection,\n }) satisfies EntityToGroup,\n ),\n ...globals\n .filter(({ slug }) => visibleEntities?.globals.includes(slug))\n .map(\n (global) =>\n ({\n type: EntityType.global,\n entity: global,\n }) satisfies EntityToGroup,\n ),\n ],\n permissions || {},\n i18n,\n ) as unknown as ExtendedGroup[]\n\n const navPreferences = await getNavPrefs(req)\n\n const serverProps = {\n i18n,\n locale,\n params,\n payload,\n permissions,\n searchParams,\n user,\n }\n\n const clientProps = {\n documentSubViewType,\n viewType,\n }\n\n const beforeNavLinksRendered = RenderServerComponent({\n clientProps,\n Component: beforeNavLinks,\n importMap: payload.importMap,\n serverProps,\n })\n\n const afterNavLinksRendered = RenderServerComponent({\n clientProps,\n Component: afterNavLinks,\n importMap: payload.importMap,\n serverProps,\n })\n\n const renderedSettingsMenu =\n settingsMenu && Array.isArray(settingsMenu)\n ? settingsMenu.map((item, index) =>\n RenderServerComponent({\n clientProps,\n Component: item,\n importMap: payload.importMap,\n key: `settings-menu-item-${index}`,\n serverProps,\n }),\n )\n : []\n\n const config: EnhancedSidebarConfig = sidebarConfig ?? {\n tabs: [\n {\n id: 'default',\n type: 'tab',\n icon: 'LayoutGrid',\n label: 'Collections',\n },\n ],\n }\n\n // Filter all tab bar items by access — fail-closed: missing req denies access\n // Note: req can be undefined on 404 pages due to a Payload bug (NotFound view omits req from props)\n const allConfigTabs = config.tabs ?? []\n const tabAccessResults = await Promise.all(\n allConfigTabs.map((t) =>\n Promise.resolve()\n .then(() => (t.access ? (req ? t.access({ item: t, req }) : false) : true))\n .catch(() => false),\n ),\n )\n const visibleTabItems = allConfigTabs.filter((_, i) => tabAccessResults[i])\n\n // Read active tab from cookie\n const cookieStore = await cookies()\n const storedTabId = cookieStore.get(COOKIE_KEY)?.value\n const tabs = visibleTabItems.filter((t) => t.type === 'tab') as SidebarTabContentType[]\n const defaultTabId = tabs[0]?.id ?? ''\n const initialActiveTabId =\n storedTabId && tabs.some((t) => t.id === storedTabId) ? storedTabId : defaultTabId\n\n const adminRoute = payload.config.routes.admin\n const currentLang = i18n.language\n\n /**\n * Renders a single entity as a NavItem (default or custom).\n */\n const renderEntity = (entity: ExtendedEntity, key: string): React.ReactNode => {\n const { slug, type } = entity\n let href: string\n let id: string\n\n if (type === EntityType.collection) {\n href = formatAdminURL({ adminRoute, path: `/collections/${slug}` })\n id = `nav-${slug}`\n } else if (type === EntityType.global) {\n href = formatAdminURL({ adminRoute, path: `/globals/${slug}` })\n id = `nav-global-${slug}`\n } else if (type === 'custom' && entity.href) {\n id = `nav-custom-${slug}`\n href = entity.isExternal ? entity.href : formatAdminURL({ adminRoute, path: entity.href })\n } else {\n return null\n }\n\n const badgeConfig = config.badges?.[slug]\n\n if (config.customComponents?.NavItem) {\n const label = getTranslation(entity.label, i18n)\n const { clientProps: extraProps, path } = resolveSidebarComponent(\n config.customComponents.NavItem,\n )\n return RenderServerComponent({\n clientProps: { id, badgeConfig, entity, href, label, ...extraProps },\n Component: path,\n importMap: payload.importMap,\n key,\n serverProps,\n })\n }\n\n return <NavItem badgeConfig={badgeConfig} entity={entity} href={href} id={id} key={key} />\n }\n\n /**\n * Renders a group with its entities (default NavGroup or custom).\n */\n const renderGroup = (group: ExtendedGroup, key: string): React.ReactNode => {\n const { entities, label } = group\n const isUngrouped = !label || (typeof label === 'string' && label === '')\n const translatedLabel = getTranslation(label || '', i18n)\n\n const items = entities.map((entity, i) => renderEntity(entity, `${key}-${i}`))\n\n if (isUngrouped) {\n return <Fragment key={key}>{items}</Fragment>\n }\n\n if (config.customComponents?.NavGroup) {\n const { clientProps: extraProps, path } = resolveSidebarComponent(\n config.customComponents.NavGroup,\n )\n return RenderServerComponent({\n clientProps: {\n children: items,\n isOpen: navPreferences?.groups?.[translatedLabel]?.open,\n label: translatedLabel,\n ...extraProps,\n },\n Component: path,\n importMap: payload.importMap,\n key,\n serverProps,\n })\n }\n\n return (\n <NavGroup\n isOpen={navPreferences?.groups?.[translatedLabel]?.open}\n key={key}\n label={translatedLabel}\n >\n {items}\n </NavGroup>\n )\n }\n\n // Pre-render content for every tab on the server (computed in parallel)\n const tabGroupResults = await Promise.all(\n tabs.map((tab) => computeGroupsForTab(tab, groups, currentLang, req)),\n )\n const tabsContent: Record<string, React.ReactNode> = {}\n for (let i = 0; i < tabs.length; i++) {\n const tab = tabs[i]\n const tabGroups = tabGroupResults[i]\n tabsContent[tab.id] = (\n <Fragment>{tabGroups.map((group, j) => renderGroup(group, `${tab.id}-${j}`))}</Fragment>\n )\n }\n\n // For the no-tabs fallback — only show all content when the config has no tab-type items at all.\n // If tabs exist but are all hidden by access control, show nothing instead of the full nav.\n const configuredTabsCount = (config.tabs ?? []).filter((t) => t.type === 'tab').length\n const allContent =\n configuredTabsCount === 0 ? (\n <Fragment>{groups.map((group, i) => renderGroup(group, `all-${i}`))}</Fragment>\n ) : undefined\n\n // Build server-side icon and tab button rendering\n const allTabItems = visibleTabItems\n const hasCustomTabButton = !!config.customComponents?.TabButton\n const hasAnyIconComponent = allTabItems.some((t) => t.type !== 'custom' && t.iconComponent)\n\n // tabIcons: per-id icon node (only built when no custom TabButton, just iconComponent overrides)\n const tabIcons: Record<string, React.ReactNode> = {}\n // renderedTabItems: fully custom tab button nodes (built when customComponents.TabButton is set)\n const renderedTabItems: React.ReactNode[] = []\n // customTabComponents: server-rendered components for type:'custom' tab bar slots\n const customTabComponents: Record<string, React.ReactNode> = {}\n\n // Pre-render all type:'custom' items\n for (const item of allTabItems) {\n if (item.type === 'custom') {\n const { clientProps: extraProps, path } = resolveSidebarComponent(item.component)\n customTabComponents[item.id] = RenderServerComponent({\n clientProps: { id: item.id, ...extraProps },\n Component: path,\n importMap: payload.importMap,\n key: item.id,\n serverProps,\n })\n }\n }\n\n if (hasCustomTabButton || hasAnyIconComponent) {\n for (const item of allTabItems) {\n if (item.type === 'custom') {\n // Include pre-rendered custom slot in renderedTabItems when using custom TabButton\n if (hasCustomTabButton) {\n renderedTabItems.push(customTabComponents[item.id])\n }\n continue\n }\n\n const label = getTranslation(item.label, i18n)\n\n // Resolve icon: custom iconComponent > default Lucide\n let iconNode: React.ReactNode\n if (item.iconComponent) {\n const { clientProps: iconExtraProps, path: iconPath } = resolveSidebarComponent(\n item.iconComponent,\n )\n iconNode = RenderServerComponent({\n clientProps: { id: item.id, type: item.type, label, ...iconExtraProps },\n Component: iconPath,\n importMap: payload.importMap,\n serverProps,\n })\n } else {\n iconNode = item.icon ? <Icon name={item.icon} size={20} /> : null\n }\n\n if (hasCustomTabButton) {\n // Compute href for links\n let href: string | undefined\n if (item.type === 'link') {\n href = item.isExternal ? item.href : formatAdminURL({ adminRoute, path: item.href })\n }\n\n const { clientProps: tabBtnExtraProps, path: tabBtnPath } = resolveSidebarComponent(\n config.customComponents!.TabButton!,\n )\n renderedTabItems.push(\n RenderServerComponent({\n clientProps: {\n id: item.id,\n type: item.type,\n badge: item.badge,\n href,\n icon: iconNode,\n isExternal: item.type === 'link' ? item.isExternal : undefined,\n label,\n ...tabBtnExtraProps,\n },\n Component: tabBtnPath,\n importMap: payload.importMap,\n key: item.id,\n serverProps,\n }),\n )\n } else if (item.iconComponent) {\n tabIcons[item.id] = iconNode\n }\n }\n }\n\n const customNavContent = config.customComponents?.NavContent\n ? (() => {\n const { clientProps: extraProps, path } = resolveSidebarComponent(\n config.customComponents.NavContent,\n )\n return RenderServerComponent({\n clientProps: {\n afterNavLinks: afterNavLinksRendered,\n allContent,\n beforeNavLinks: beforeNavLinksRendered,\n tabs: tabs.map((t) => ({ id: t.id })),\n tabsContent,\n ...extraProps,\n },\n Component: path,\n importMap: payload.importMap,\n key: 'enhanced-sidebar-nav-content',\n serverProps,\n })\n })()\n : undefined\n\n // Strip access functions and use only visible tabs before passing to client component\n const clientSidebarConfig = sanitizeSidebarConfig({ ...config, tabs: visibleTabItems })\n\n return (\n <SidebarContent\n afterNavLinks={afterNavLinksRendered}\n allContent={allContent}\n beforeNavLinks={beforeNavLinksRendered}\n customNavContent={customNavContent}\n customTabComponents={Object.keys(customTabComponents).length > 0 ? customTabComponents : undefined}\n initialActiveTabId={initialActiveTabId}\n renderedTabItems={renderedTabItems.length > 0 ? renderedTabItems : undefined}\n settingsMenu={renderedSettingsMenu}\n sidebarConfig={clientSidebarConfig}\n tabIcons={Object.keys(tabIcons).length > 0 ? tabIcons : undefined}\n tabsContent={tabsContent}\n />\n )\n}\n\nexport default EnhancedSidebar\n"],"names":["getTranslation","NavGroup","RenderServerComponent","EntityType","groupNavItems","cookies","formatAdminURL","React","Fragment","COOKIE_KEY","extractLocalizedValue","resolveSidebarComponent","sanitizeSidebarConfig","getNavPrefs","Icon","NavItem","SidebarContent","computeGroupsForTab","tab","groups","currentLang","req","collections","tabCollections","customItems","globals","tabGlobals","showAll","allowedSlugs","Set","result","map","g","entities","size","group","filter","entity","has","slug","length","topAdditions","topUngrouped","bottomUngrouped","toEntity","item","type","href","isExternal","label","accessResults","Promise","all","resolve","then","access","catch","visibleItems","_","i","itemGroupLabel","existingGroup","find","groupLabel","push","newGroup","position","unshift","EnhancedSidebar","props","documentSubViewType","i18n","locale","params","payload","permissions","searchParams","sidebarConfig","user","viewType","visibleEntities","config","admin","components","afterNavLinks","beforeNavLinks","settingsMenu","includes","collection","global","navPreferences","serverProps","clientProps","beforeNavLinksRendered","Component","importMap","afterNavLinksRendered","renderedSettingsMenu","Array","isArray","index","key","tabs","id","icon","allConfigTabs","tabAccessResults","t","visibleTabItems","cookieStore","storedTabId","get","value","defaultTabId","initialActiveTabId","some","adminRoute","routes","language","renderEntity","path","badgeConfig","badges","customComponents","extraProps","renderGroup","isUngrouped","translatedLabel","items","children","isOpen","open","tabGroupResults","tabsContent","tabGroups","j","configuredTabsCount","allContent","undefined","allTabItems","hasCustomTabButton","TabButton","hasAnyIconComponent","iconComponent","tabIcons","renderedTabItems","customTabComponents","component","iconNode","iconExtraProps","iconPath","name","tabBtnExtraProps","tabBtnPath","badge","customNavContent","NavContent","clientSidebarConfig","Object","keys"],"mappings":";AAGA,SAASA,cAAc,QAAQ,2BAA0B;AACzD,SAASC,QAAQ,QAAQ,iBAAgB;AACzC,SAASC,qBAAqB,QAAQ,gDAA+C;AACrF,SAASC,UAAU,EAAEC,aAAa,QAAQ,wBAAuB;AACjE,SAASC,OAAO,QAAQ,eAAc;AACtC,SAASC,cAAc,QAAQ,iBAAgB;AAC/C,OAAOC,SAASC,QAAQ,QAAQ,QAAO;AAEvC,MAAMC,aAAa;AAWnB,SAASC,qBAAqB,EAAEC,uBAAuB,EAAEC,qBAAqB,QAAQ,cAAa;AACnG,SAASC,WAAW,QAAQ,gBAAe;AAC3C,SAASC,IAAI,QAAQ,SAAQ;AAC7B,SAASC,OAAO,QAAQ,YAAW;AACnC,SAASC,cAAc,QAAQ,mBAAkB;AACjD,OAAO,eAAc;AAOrB;;CAEC,GACD,MAAMC,sBAAsB,OAC1BC,KACAC,QACAC,aACAC;IAEA,MAAM,EAAEC,aAAaC,cAAc,EAAEC,WAAW,EAAEC,SAASC,UAAU,EAAE,GAAGR;IAE1E,MAAMS,UAAU,CAACJ,kBAAkB,CAACG;IACpC,MAAME,eAAe,IAAIC,IAAI;WAAKN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AG6C;YACtB;QACF;IACF;IAEA,MAAMO,mBAAmB1E,OAAO0C,gBAAgB,EAAEiC,aAC9C,AAAC,CAAA;QACC,MAAM,EAAEhE,aAAagC,UAAU,EAAEJ,IAAI,EAAE,GAAG7G,wBACxCsE,OAAO0C,gBAAgB,CAACiC,UAAU;QAEpC,OAAO1J,sBAAsB;YAC3B0F,aAAa;gBACXR,eAAeY;gBACfyC;gBACApD,gBAAgBQ;gBAChBS,MAAMA,KAAKvE,GAAG,CAAC,CAAC4E,IAAO,CAAA;wBAAEJ,IAAII,EAAEJ,EAAE;oBAAC,CAAA;gBAClC8B;gBACA,GAAGT,UAAU;YACf;YACA9B,WAAW0B;YACXzB,WAAWrB,QAAQqB,SAAS;YAC5BM,KAAK;YACLV;QACF;IACF,CAAA,MACA+C;IAEJ,sFAAsF;IACtF,MAAMmB,sBAAsBjJ,sBAAsB;QAAE,GAAGqE,MAAM;QAAEqB,MAAMM;IAAgB;IAErF,qBACE,KAAC5F;QACCoE,eAAeY;QACfyC,YAAYA;QACZpD,gBAAgBQ;QAChB8D,kBAAkBA;QAClBT,qBAAqBY,OAAOC,IAAI,CAACb,qBAAqB1G,MAAM,GAAG,IAAI0G,sBAAsBR;QACzFxB,oBAAoBA;QACpB+B,kBAAkBA,iBAAiBzG,MAAM,GAAG,IAAIyG,mBAAmBP;QACnEpD,cAAcW;QACdpB,eAAegF;QACfb,UAAUc,OAAOC,IAAI,CAACf,UAAUxG,MAAM,GAAG,IAAIwG,WAAWN;QACxDL,aAAaA;;AAGnB,EAAC;AAED,eAAejE,gBAAe"}
1
+ {"version":3,"sources":["../../../src/components/EnhancedSidebar/index.tsx"],"sourcesContent":["import type { EntityToGroup } from '@payloadcms/ui/shared'\nimport type { PayloadRequest, ServerProps } from 'payload'\n\nimport { getTranslation } from '@payloadcms/translations'\nimport { NavGroup } from '@payloadcms/ui'\nimport { RenderServerComponent } from '@payloadcms/ui/elements/RenderServerComponent'\nimport { EntityType, groupNavItems } from '@payloadcms/ui/shared'\nimport { cookies } from 'next/headers'\nimport { formatAdminURL } from 'payload/shared'\nimport React, { Fragment } from 'react'\n\nconst COOKIE_KEY = 'payload-enhanced-sidebar-active-tab'\n\nimport type {\n EnhancedSidebarConfig,\n ExtendedEntity,\n ExtendedGroup,\n SidebarTab,\n SidebarTabContent as SidebarTabContentType,\n SidebarTabItem,\n} from '../../types'\n\nimport { extractLocalizedValue, resolveSidebarComponent, sanitizeSidebarConfig } from '../../utils'\nimport { getNavPrefs } from './getNavPrefs'\nimport { Icon } from './Icon'\nimport { NavItem } from './NavItem'\nimport { SidebarContent } from './SidebarContent'\nimport './index.scss'\n\nexport type EnhancedSidebarProps = {\n req?: PayloadRequest\n sidebarConfig?: EnhancedSidebarConfig\n} & ServerProps\n\n/**\n * Computes filtered and merged groups for a specific tab (server-side).\n */\nconst computeGroupsForTab = async (\n tab: SidebarTabContentType,\n groups: ExtendedGroup[],\n currentLang: string,\n req: PayloadRequest | undefined,\n): Promise<ExtendedGroup[]> => {\n const { collections: tabCollections, customItems, globals: tabGlobals } = tab\n\n const showAll = !tabCollections && !tabGlobals\n const allowedSlugs = new Set([...(tabCollections ?? []), ...(tabGlobals ?? [])])\n\n let result: ExtendedGroup[] = []\n\n if (showAll) {\n result = groups.map((g) => ({ ...g, entities: [...g.entities] }))\n } else if (allowedSlugs.size > 0) {\n result = groups\n .map((group) => ({\n ...group,\n entities: group.entities.filter((entity) => allowedSlugs.has(entity.slug)),\n }))\n .filter((group) => group.entities.length > 0)\n }\n\n if (customItems && customItems.length > 0) {\n const topAdditions: ExtendedGroup[] = []\n const topUngrouped: SidebarTabItem[] = []\n const bottomUngrouped: SidebarTabItem[] = []\n\n const toEntity = (item: SidebarTabItem): ExtendedEntity =>\n ({\n slug: item.slug,\n type: 'custom',\n href: item.href,\n isExternal: item.isExternal,\n label: item.label,\n }) as ExtendedEntity\n\n // Filter custom items by access — fail-closed: missing req or thrown error denies access\n const accessResults = await Promise.all(\n customItems.map((item) =>\n Promise.resolve()\n .then(() => (item.access ? (req ? item.access({ item, req }) : false) : true))\n .catch(() => false),\n ),\n )\n const visibleItems = customItems.filter((_, i) => accessResults[i])\n\n for (const item of visibleItems) {\n if (item.group) {\n const itemGroupLabel = extractLocalizedValue(item.group, currentLang)\n const existingGroup = result.find((g) => {\n const groupLabel = extractLocalizedValue(g.label, currentLang)\n return groupLabel === itemGroupLabel\n })\n\n if (existingGroup) {\n // Merged into existing collection group — position has no effect here\n existingGroup.entities.push(toEntity(item))\n } else {\n // New custom group — position controls top vs bottom\n const newGroup: ExtendedGroup = { entities: [toEntity(item)], label: item.group }\n if (item.position === 'top') {\n topAdditions.push(newGroup)\n } else {\n result.push(newGroup)\n }\n }\n } else {\n if (item.position === 'top') {\n topUngrouped.push(item)\n } else {\n bottomUngrouped.push(item)\n }\n }\n }\n\n if (topUngrouped.length > 0) {\n topAdditions.unshift({ entities: topUngrouped.map(toEntity), label: '' })\n }\n\n if (bottomUngrouped.length > 0) {\n result.push({ entities: bottomUngrouped.map(toEntity), label: '' })\n }\n\n result = [...topAdditions, ...result]\n }\n\n return result\n}\n\nexport const EnhancedSidebar: React.FC<EnhancedSidebarProps> = async (props) => {\n const {\n documentSubViewType,\n i18n,\n locale,\n params,\n payload,\n permissions,\n req,\n searchParams,\n sidebarConfig,\n user,\n viewType,\n visibleEntities,\n } = props\n\n if (!payload?.config) {\n return null\n }\n\n const {\n admin: {\n components: { afterNav, afterNavLinks, beforeNav, beforeNavLinks, settingsMenu },\n },\n collections,\n globals,\n } = payload.config\n\n const groups = groupNavItems(\n [\n ...collections\n .filter(({ slug }) => visibleEntities?.collections.includes(slug))\n .map(\n (collection) =>\n ({\n type: EntityType.collection,\n entity: collection,\n }) satisfies EntityToGroup,\n ),\n ...globals\n .filter(({ slug }) => visibleEntities?.globals.includes(slug))\n .map(\n (global) =>\n ({\n type: EntityType.global,\n entity: global,\n }) satisfies EntityToGroup,\n ),\n ],\n permissions || {},\n i18n,\n ) as unknown as ExtendedGroup[]\n\n const navPreferences = await getNavPrefs(req)\n\n const serverProps = {\n i18n,\n locale,\n params,\n payload,\n permissions,\n searchParams,\n user,\n }\n\n const clientProps = {\n documentSubViewType,\n viewType,\n }\n\n const beforeNavRendered = RenderServerComponent({\n clientProps,\n Component: beforeNav,\n importMap: payload.importMap,\n serverProps,\n })\n\n const beforeNavLinksRendered = RenderServerComponent({\n clientProps,\n Component: beforeNavLinks,\n importMap: payload.importMap,\n serverProps,\n })\n\n const afterNavLinksRendered = RenderServerComponent({\n clientProps,\n Component: afterNavLinks,\n importMap: payload.importMap,\n serverProps,\n })\n\n const afterNavRendered = RenderServerComponent({\n clientProps,\n Component: afterNav,\n importMap: payload.importMap,\n serverProps,\n })\n\n const renderedSettingsMenu =\n settingsMenu && Array.isArray(settingsMenu)\n ? settingsMenu.map((item, index) =>\n RenderServerComponent({\n clientProps,\n Component: item,\n importMap: payload.importMap,\n key: `settings-menu-item-${index}`,\n serverProps,\n }),\n )\n : []\n\n const config: EnhancedSidebarConfig = sidebarConfig ?? {\n tabs: [\n {\n id: 'default',\n type: 'tab',\n icon: 'LayoutGrid',\n label: 'Collections',\n },\n ],\n }\n\n // Filter all tab bar items by access — fail-closed: missing req denies access\n // Note: req can be undefined on 404 pages due to a Payload bug (NotFound view omits req from props)\n const allConfigTabs = config.tabs ?? []\n const tabAccessResults = await Promise.all(\n allConfigTabs.map((t) =>\n Promise.resolve()\n .then(() => (t.access ? (req ? t.access({ item: t, req }) : false) : true))\n .catch(() => false),\n ),\n )\n const visibleTabItems = allConfigTabs.filter((_, i) => tabAccessResults[i])\n\n // Read active tab from cookie\n const cookieStore = await cookies()\n const storedTabId = cookieStore.get(COOKIE_KEY)?.value\n const tabs = visibleTabItems.filter((t) => t.type === 'tab') as SidebarTabContentType[]\n const defaultTabId = tabs[0]?.id ?? ''\n const initialActiveTabId =\n storedTabId && tabs.some((t) => t.id === storedTabId) ? storedTabId : defaultTabId\n\n const adminRoute = payload.config.routes.admin\n const currentLang = i18n.language\n\n /**\n * Renders a single entity as a NavItem (default or custom).\n */\n const renderEntity = (entity: ExtendedEntity, key: string): React.ReactNode => {\n const { slug, type } = entity\n let href: string\n let id: string\n\n if (type === EntityType.collection) {\n href = formatAdminURL({ adminRoute, path: `/collections/${slug}` })\n id = `nav-${slug}`\n } else if (type === EntityType.global) {\n href = formatAdminURL({ adminRoute, path: `/globals/${slug}` })\n id = `nav-global-${slug}`\n } else if (type === 'custom' && entity.href) {\n id = `nav-custom-${slug}`\n href = entity.isExternal ? entity.href : formatAdminURL({ adminRoute, path: entity.href })\n } else {\n return null\n }\n\n const badgeConfig = config.badges?.[slug]\n\n if (config.customComponents?.NavItem) {\n const label = getTranslation(entity.label, i18n)\n const { clientProps: extraProps, path } = resolveSidebarComponent(\n config.customComponents.NavItem,\n )\n return RenderServerComponent({\n clientProps: { id, badgeConfig, entity, href, label, ...extraProps },\n Component: path,\n importMap: payload.importMap,\n key,\n serverProps,\n })\n }\n\n return <NavItem badgeConfig={badgeConfig} entity={entity} href={href} id={id} key={key} />\n }\n\n /**\n * Renders a group with its entities (default NavGroup or custom).\n */\n const renderGroup = (group: ExtendedGroup, key: string): React.ReactNode => {\n const { entities, label } = group\n const isUngrouped = !label || (typeof label === 'string' && label === '')\n const translatedLabel = getTranslation(label || '', i18n)\n\n const items = entities.map((entity, i) => renderEntity(entity, `${key}-${i}`))\n\n if (isUngrouped) {\n return <Fragment key={key}>{items}</Fragment>\n }\n\n if (config.customComponents?.NavGroup) {\n const { clientProps: extraProps, path } = resolveSidebarComponent(\n config.customComponents.NavGroup,\n )\n return RenderServerComponent({\n clientProps: {\n children: items,\n isOpen: navPreferences?.groups?.[translatedLabel]?.open,\n label: translatedLabel,\n ...extraProps,\n },\n Component: path,\n importMap: payload.importMap,\n key,\n serverProps,\n })\n }\n\n return (\n <NavGroup\n isOpen={navPreferences?.groups?.[translatedLabel]?.open}\n key={key}\n label={translatedLabel}\n >\n {items}\n </NavGroup>\n )\n }\n\n // Pre-render content for every tab on the server (computed in parallel)\n const tabGroupResults = await Promise.all(\n tabs.map((tab) => computeGroupsForTab(tab, groups, currentLang, req)),\n )\n const tabsContent: Record<string, React.ReactNode> = {}\n for (let i = 0; i < tabs.length; i++) {\n const tab = tabs[i]\n const tabGroups = tabGroupResults[i]\n tabsContent[tab.id] = (\n <Fragment>{tabGroups.map((group, j) => renderGroup(group, `${tab.id}-${j}`))}</Fragment>\n )\n }\n\n // For the no-tabs fallback — only show all content when the config has no tab-type items at all.\n // If tabs exist but are all hidden by access control, show nothing instead of the full nav.\n const configuredTabsCount = (config.tabs ?? []).filter((t) => t.type === 'tab').length\n const allContent =\n configuredTabsCount === 0 ? (\n <Fragment>{groups.map((group, i) => renderGroup(group, `all-${i}`))}</Fragment>\n ) : undefined\n\n // Build server-side icon and tab button rendering\n const allTabItems = visibleTabItems\n const hasCustomTabButton = !!config.customComponents?.TabButton\n const hasAnyIconComponent = allTabItems.some((t) => t.type !== 'custom' && t.iconComponent)\n\n // tabIcons: per-id icon node (only built when no custom TabButton, just iconComponent overrides)\n const tabIcons: Record<string, React.ReactNode> = {}\n // renderedTabItems: fully custom tab button nodes (built when customComponents.TabButton is set)\n const renderedTabItems: React.ReactNode[] = []\n // customTabComponents: server-rendered components for type:'custom' tab bar slots\n const customTabComponents: Record<string, React.ReactNode> = {}\n\n // Pre-render all type:'custom' items\n for (const item of allTabItems) {\n if (item.type === 'custom') {\n const { clientProps: extraProps, path } = resolveSidebarComponent(item.component)\n customTabComponents[item.id] = RenderServerComponent({\n clientProps: { id: item.id, ...extraProps },\n Component: path,\n importMap: payload.importMap,\n key: item.id,\n serverProps,\n })\n }\n }\n\n if (hasCustomTabButton || hasAnyIconComponent) {\n for (const item of allTabItems) {\n if (item.type === 'custom') {\n // Include pre-rendered custom slot in renderedTabItems when using custom TabButton\n if (hasCustomTabButton) {\n renderedTabItems.push(customTabComponents[item.id])\n }\n continue\n }\n\n const label = getTranslation(item.label, i18n)\n\n // Resolve icon: custom iconComponent > default Lucide\n let iconNode: React.ReactNode\n if (item.iconComponent) {\n const { clientProps: iconExtraProps, path: iconPath } = resolveSidebarComponent(\n item.iconComponent,\n )\n iconNode = RenderServerComponent({\n clientProps: { id: item.id, type: item.type, label, ...iconExtraProps },\n Component: iconPath,\n importMap: payload.importMap,\n serverProps,\n })\n } else {\n iconNode = item.icon ? <Icon name={item.icon} size={20} /> : null\n }\n\n if (hasCustomTabButton) {\n // Compute href for links\n let href: string | undefined\n if (item.type === 'link') {\n href = item.isExternal ? item.href : formatAdminURL({ adminRoute, path: item.href })\n }\n\n const { clientProps: tabBtnExtraProps, path: tabBtnPath } = resolveSidebarComponent(\n config.customComponents!.TabButton!,\n )\n renderedTabItems.push(\n RenderServerComponent({\n clientProps: {\n id: item.id,\n type: item.type,\n badge: item.badge,\n href,\n icon: iconNode,\n isExternal: item.type === 'link' ? item.isExternal : undefined,\n label,\n ...tabBtnExtraProps,\n },\n Component: tabBtnPath,\n importMap: payload.importMap,\n key: item.id,\n serverProps,\n }),\n )\n } else if (item.iconComponent) {\n tabIcons[item.id] = iconNode\n }\n }\n }\n\n const customNavContent = config.customComponents?.NavContent\n ? (() => {\n const { clientProps: extraProps, path } = resolveSidebarComponent(\n config.customComponents.NavContent,\n )\n return RenderServerComponent({\n clientProps: {\n afterNav: afterNavRendered,\n afterNavLinks: afterNavLinksRendered,\n allContent,\n beforeNav: beforeNavRendered,\n beforeNavLinks: beforeNavLinksRendered,\n tabs: tabs.map((t) => ({ id: t.id })),\n tabsContent,\n ...extraProps,\n },\n Component: path,\n importMap: payload.importMap,\n key: 'enhanced-sidebar-nav-content',\n serverProps,\n })\n })()\n : undefined\n\n // Strip access functions and use only visible tabs before passing to client component\n const clientSidebarConfig = sanitizeSidebarConfig({ ...config, tabs: visibleTabItems })\n\n return (\n <SidebarContent\n afterNav={afterNavRendered}\n afterNavLinks={afterNavLinksRendered}\n allContent={allContent}\n beforeNav={beforeNavRendered}\n beforeNavLinks={beforeNavLinksRendered}\n customNavContent={customNavContent}\n customTabComponents={Object.keys(customTabComponents).length > 0 ? customTabComponents : undefined}\n initialActiveTabId={initialActiveTabId}\n renderedTabItems={renderedTabItems.length > 0 ? renderedTabItems : undefined}\n settingsMenu={renderedSettingsMenu}\n sidebarConfig={clientSidebarConfig}\n tabIcons={Object.keys(tabIcons).length > 0 ? tabIcons : undefined}\n tabsContent={tabsContent}\n />\n )\n}\n\nexport default EnhancedSidebar\n"],"names":["getTranslation","NavGroup","RenderServerComponent","EntityType","groupNavItems","cookies","formatAdminURL","React","Fragment","COOKIE_KEY","extractLocalizedValue","resolveSidebarComponent","sanitizeSidebarConfig","getNavPrefs","Icon","NavItem","SidebarContent","computeGroupsForTab","tab","groups","currentLang","req","collections","tabCollections","customItems","globals","tabGlobals","showAll","allowedSlugs","Set","result","map","g","entities","size","group","filter","entity","has","slug","length","topAdditions","topUngrouped","bottomUngrouped","toEntity","item","type","href","isExternal","label","accessResults","Promise","all","resolve","then","access","catch","visibleItems","_","i","itemGroupLabel","existingGroup","find","groupLabel","push","newGroup","position","unshift","EnhancedSidebar","props","documentSubViewType","i18n","locale","params","payload","permissions","searchParams","sidebarConfig","user","viewType","visibleEntities","config","admin","components","afterNav","afterNavLinks","beforeNav","beforeNavLinks","settingsMenu","includes","collection","global","navPreferences","serverProps","clientProps","beforeNavRendered","Component","importMap","beforeNavLinksRendered","afterNavLinksRendered","afterNavRendered","renderedSettingsMenu","Array","isArray","index","key","tabs","id","icon","allConfigTabs","tabAccessResults","t","visibleTabItems","cookieStore","storedTabId","get","value","defaultTabId","initialActiveTabId","some","adminRoute","routes","language","renderEntity","path","badgeConfig","badges","customComponents","extraProps","renderGroup","isUngrouped","translatedLabel","items","children","isOpen","open","tabGroupResults","tabsContent","tabGroups","j","configuredTabsCount","allContent","undefined","allTabItems","hasCustomTabButton","TabButton","hasAnyIconComponent","iconComponent","tabIcons","renderedTabItems","customTabComponents","component","iconNode","iconExtraProps","iconPath","name","tabBtnExtraProps","tabBtnPath","badge","customNavContent","NavContent","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gBACf0C;gBACAvD,WAAWS;gBACXR,gBAAgBW;gBAChBQ,MAAMA,KAAK3E,GAAG,CAAC,CAACgF,IAAO,CAAA;wBAAEJ,IAAII,EAAEJ,EAAE;oBAAC,CAAA;gBAClC8B;gBACA,GAAGT,UAAU;YACf;YACAhC,WAAW4B;YACX3B,WAAWvB,QAAQuB,SAAS;YAC5BQ,KAAK;YACLZ;QACF;IACF,CAAA,MACAiD;IAEJ,sFAAsF;IACtF,MAAMmB,sBAAsBrJ,sBAAsB;QAAE,GAAGqE,MAAM;QAAEyB,MAAMM;IAAgB;IAErF,qBACE,KAAChG;QACCoE,UAAUgB;QACVf,eAAec;QACf0C,YAAYA;QACZvD,WAAWS;QACXR,gBAAgBW;QAChB6D,kBAAkBA;QAClBT,qBAAqBY,OAAOC,IAAI,CAACb,qBAAqB9G,MAAM,GAAG,IAAI8G,sBAAsBR;QACzFxB,oBAAoBA;QACpB+B,kBAAkBA,iBAAiB7G,MAAM,GAAG,IAAI6G,mBAAmBP;QACnEtD,cAAca;QACdxB,eAAeoF;QACfb,UAAUc,OAAOC,IAAI,CAACf,UAAU5G,MAAM,GAAG,IAAI4G,WAAWN;QACxDL,aAAaA;;AAGnB,EAAC;AAED,eAAerE,gBAAe"}
@@ -1,4 +1,6 @@
1
- @import '~@payloadcms/ui/scss';
1
+ @import "../../../node_modules/@payloadcms/ui/dist/scss/vars";
2
+ @import "../../../node_modules/@payloadcms/ui/dist/scss/queries.scss";
3
+
2
4
 
3
5
  @layer payload-default {
4
6
  .enhanced-sidebar {
package/dist/types.d.ts CHANGED
@@ -425,10 +425,14 @@ export type CustomTabButtonProps = {
425
425
  * ```
426
426
  */
427
427
  export type CustomNavContentProps = {
428
+ /** Rendered afterNav from payload config (rendered after afterNavLinks) */
429
+ afterNav?: ReactNode;
428
430
  /** Rendered afterNavLinks from payload config */
429
431
  afterNavLinks?: ReactNode;
430
432
  /** Content to show when no tabs are defined */
431
433
  allContent?: ReactNode;
434
+ /** Rendered beforeNav from payload config (rendered before beforeNavLinks) */
435
+ beforeNav?: ReactNode;
432
436
  /** Rendered beforeNavLinks from payload config */
433
437
  beforeNavLinks?: ReactNode;
434
438
  /** Tab definitions (id only) for mapping over */
package/dist/types.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/types.ts"],"sourcesContent":["import type { icons, LucideIcon } from 'lucide-react'\nimport type { CollectionSlug, GlobalSlug, PayloadRequest, Where } from 'payload'\nimport type { ReactNode } from 'react'\n\nexport type IconName = keyof typeof icons\n\nexport type LocalizedString = { [locale: string]: string } | string\n\nexport type InternalIcon = IconName | LucideIcon\n\n// ============================================\n// Badge Types\n// ============================================\n\n/**\n * Available badge color variants\n */\nexport type BadgeColor = 'default' | 'error' | 'primary' | 'success' | 'warning'\n\n/**\n * Badge configuration For API-based fetching\n */\nexport interface BadgeConfigApi {\n /**\n * Badge color variant\n * @default 'default'\n */\n color?: BadgeColor\n /**\n * API endpoint to fetch badge data from.\n * Can be relative (to current origin) or absolute URL.\n */\n endpoint: string\n /**\n * HTTP method for the request\n * @default 'GET'\n */\n method?: 'GET' | 'POST'\n /**\n * Key in the response object to extract the count from\n * @default 'count'\n */\n responseKey?: string\n type: 'api'\n}\n\n/**\n * Badge configuration for provider-based values.\n * Values are provided via BadgeProvider context.\n */\nexport interface BadgeConfigProvider {\n /**\n * Badge color variant\n * @default 'default'\n */\n color?: BadgeColor\n /**\n * Slug to look up in the BadgeProvider values.\n * If not specified, defaults to the item's id/slug.\n */\n slug?: string\n type: 'provider'\n}\n\n/**\n * Badge configuration for automatic collection document count.\n * Fetches from /api/{collectionSlug}?limit=0 and uses totalDocs.\n */\nexport interface BadgeConfigCollectionCount {\n /**\n * Collection slug to count documents from.\n * If not specified, defaults to the item's slug.\n */\n collectionSlug?: CollectionSlug\n /**\n * Badge color variant\n * @default 'default'\n */\n color?: BadgeColor\n type: 'collection-count'\n /**\n * Optional where query to filter documents.\n * Will be serialized as query string.\n * @example { status: { equals: 'draft' } }\n */\n where?: Where\n}\n\n/**\n * Badge configuration - union of all badge types\n */\nexport type BadgeConfig = BadgeConfigApi | BadgeConfigCollectionCount | BadgeConfigProvider\n\n/**\n * Badge values provided via BadgeProvider context\n */\nexport type BadgeValues = Record<string, number | ReactNode>\n\n// ============================================\n// Access Control Types\n// ============================================\n\n/**\n * Access function for a tab or link in the tabs bar.\n * Return `false` to hide the item entirely (both the button and its content).\n */\nexport type TabAccessFunction = (args: {\n item: SidebarTab\n req: PayloadRequest\n}) => boolean | Promise<boolean>\n\n/**\n * Access function for a custom item inside a tab.\n * Return `false` to hide the item from the nav.\n */\nexport type ItemAccessFunction = (args: {\n item: SidebarTabItem\n req: PayloadRequest\n}) => boolean | Promise<boolean>\n\n// ============================================\n// Enhanced Sidebar Types\n// ============================================\n\n/**\n * Path to a component, either as a plain string or as an object with a path and\n * additional client props to forward to the component. Follows Payload's component format.\n *\n * @example\n * ```typescript\n * // Simple path\n * iconComponent: './components/Icons#TabIcon'\n *\n * // With client props — useful for a single component shared across all tabs\n * iconComponent: {\n * path: './components/Icons#TabIcon',\n * clientProps: { icon: 'house' },\n * }\n * ```\n */\nexport type SidebarComponent =\n | {\n /** Additional props forwarded to the component on the client */\n clientProps?: Record<string, unknown>\n /** Component path in Payload's format: `'./path/to/file#ExportName'` */\n path: string\n }\n | string\n\n/**\n * Mutually exclusive icon config: either a Lucide icon name OR a custom icon component path.\n */\ntype TabIconConfig =\n | {\n /** Icon name from lucide-react */\n icon: IconName\n iconComponent?: never\n }\n | {\n icon?: never\n /**\n * Path to a custom icon component. Receives `CustomTabIconProps`.\n * Supports a plain string path or `{ path, clientProps }` to forward extra props.\n * Registered automatically in the import map.\n */\n iconComponent: SidebarComponent\n }\n\n/**\n * Sidebar tab that shows content when selected\n */\nexport type SidebarTabContent = {\n /**\n * Access control function. Called server-side with the current request.\n * Return `false` to hide this tab (button + content) entirely.\n */\n access?: TabAccessFunction\n /**\n * Badge configuration for this tab.\n * Shows a badge on the tab icon in the tabs bar.\n */\n badge?: BadgeConfig\n /**\n * Collections to show in this tab.\n * If not specified, no collections are shown (unless items are specified).\n * Use collection slugs.\n */\n collections?: CollectionSlug[]\n /**\n * Custom items to add to this tab.\n * Items with `group` will be merged into matching collection groups.\n * Items without `group` will be shown at the bottom as a flat list.\n */\n customItems?: SidebarTabItem[]\n /**\n * Globals to show in this tab.\n * If not specified, no globals are shown.\n * Use global slugs.\n */\n globals?: GlobalSlug[]\n /** Unique identifier for the tab */\n id: string\n /** Tooltip/label for the tab */\n label: LocalizedString\n type: 'tab'\n} & TabIconConfig\n\ntype SidebarTabLinkBase = {\n /**\n * Access control function. Called server-side with the current request.\n * Return `false` to hide this link entirely.\n */\n access?: TabAccessFunction\n /**\n * Badge configuration for this link.\n * Shows a badge on the link icon in the tabs bar.\n */\n badge?: BadgeConfig\n /** Unique identifier */\n id: string\n /** Tooltip/label */\n label: LocalizedString\n type: 'link'\n} & TabIconConfig\ntype SidebarTabLinkExternal = {\n /** Link href (absolute URL) */\n href: string\n isExternal: true\n} & SidebarTabLinkBase\ntype SidebarTabLinkInternal = {\n /** Link href (relative to admin route) */\n href: '' | `/${string}`\n isExternal?: false\n} & SidebarTabLinkBase\n/**\n * Sidebar link that navigates to a URL (not a tab)\n */\nexport type SidebarTabLink = SidebarTabLinkExternal | SidebarTabLinkInternal\n/**\n * A custom component rendered in the tabs bar (spacer, separator, badge, etc.).\n * Does not open any content — it's purely a visual slot in the tabs column.\n */\nexport type SidebarTabCustom = {\n /**\n * Access control function. Called server-side with the current request.\n * Return `false` to hide this item entirely.\n */\n access?: TabAccessFunction\n /**\n * Component to render. Receives `{ id }` plus any `clientProps` you pass.\n * Supports a plain string path or `{ path, clientProps }`.\n */\n component: SidebarComponent\n /** Unique identifier */\n id: string\n type: 'custom'\n}\n\n/**\n * Props passed to a custom tabs bar component (spacer, separator, etc.).\n */\nexport type CustomTabsBarComponentProps = {\n id: string\n}\n\n/**\n * A tab, link, or custom component in the sidebar tabs bar\n */\nexport type SidebarTab = SidebarTabContent | SidebarTabCustom | SidebarTabLink\n\ninterface BaseSidebarTabItem {\n /**\n * Access control function. Called server-side with the current request.\n * Return `false` to hide this item from the nav.\n */\n access?: ItemAccessFunction\n /**\n * Group to add this item to.\n * If matches an existing collection group label, item will be merged into that group.\n * If no match found, a new group will be created with this label.\n * If not specified, item will be shown as ungrouped (position controlled by `position`).\n */\n group?: LocalizedString\n /** Display label */\n label: LocalizedString\n /**\n * Where to place this item relative to collection groups in the tab.\n * - `'top'` — appears above all collection/global groups\n * - `'bottom'` — appears below all groups (default)\n *\n * Has no effect on items that are merged into an existing collection group via `group`.\n * For new custom groups (unmatched `group` label), controls whether the group appears\n * at the top or bottom of the nav.\n *\n * @default 'bottom'\n */\n position?: 'bottom' | 'top'\n /** Unique slug for the item */\n slug: string\n}\ninterface ExternalHrefItem extends BaseSidebarTabItem {\n /** Link href (absolute URL or relative to root) */\n href: string\n /** Whether the link is external, without admin route prefix. */\n isExternal: true\n}\n\ninterface InternalHrefItem extends BaseSidebarTabItem {\n /** Link href (relative to admin route) */\n href: '' | `/${string}`\n /** Whether the link is external, without admin route prefix. */\n isExternal?: false\n}\n/**\n * Custom item inside a sidebar tab\n */\nexport type SidebarTabItem = ExternalHrefItem | InternalHrefItem\n\n// ============================================\n// Custom Component Types\n// ============================================\n\n/**\n * Props received by a custom NavItem component registered via `customComponents.NavItem`.\n *\n * Use the `useNavItemState(href)` hook to get reactive `isActive` / `isCurrentPage` values.\n *\n * @example\n * ```tsx\n * 'use client'\n * import React from 'react'\n * import { useNavItemState } from '@veiag/payload-enhanced-sidebar'\n * import type { CustomNavItemProps } from '@veiag/payload-enhanced-sidebar'\n *\n * export const MyNavItem: React.FC<CustomNavItemProps> = ({ entity, href, id, label, badgeConfig }) => {\n * const { isActive, isCurrentPage } = useNavItemState(href)\n * return <a href={href}>{label}</a>\n * }\n * ```\n */\nexport type CustomNavItemProps = {\n /** Badge configuration as defined in the plugin config */\n badgeConfig?: BadgeConfig\n /** The entity (collection, global, or custom item) */\n entity: ExtendedEntity\n /** Computed href with admin route prefix applied */\n href: string\n /** DOM element id */\n id: string\n /** Pre-translated label string */\n label: string\n}\n\n/**\n * Props received by a custom NavGroup component registered via `customComponents.NavGroup`.\n *\n * @example\n * ```tsx\n * 'use client'\n * import React from 'react'\n * import type { CustomNavGroupProps } from '@veiag/payload-enhanced-sidebar'\n *\n * export const MyNavGroup: React.FC<CustomNavGroupProps> = ({ label, isOpen, children }) => {\n * return <div><strong>{label}</strong>{children}</div>\n * }\n * ```\n */\nexport type CustomNavGroupProps = {\n /** Nav items inside the group */\n children: ReactNode\n /** Initial open state from nav preferences */\n isOpen?: boolean\n /** Translated group label */\n label: string\n}\n\n/**\n * Props received by a custom tab icon component set via `iconComponent` on a tab or link.\n *\n * @example\n * ```tsx\n * 'use client'\n * import React from 'react'\n * import type { CustomTabIconProps } from '@veiag/payload-enhanced-sidebar'\n *\n * export const MyIcon: React.FC<CustomTabIconProps> = ({ id, label }) => (\n * <img alt={label} src={`/icons/${id}.svg`} width={20} height={20} />\n * )\n * ```\n */\nexport type CustomTabIconProps = {\n /** Tab/link id */\n id: string\n /** Pre-translated label */\n label: string\n /** Whether this item is a tab or a link */\n type: 'link' | 'tab'\n}\n\n/**\n * Props received by a custom TabButton component registered via `customComponents.TabButton`.\n * Used for both `tab` and `link` type items in the tabs bar.\n *\n * Use `useTabState(id)` for tab active state, or `usePathname()` for link active state.\n * Use `useEnhancedSidebar().onTabChange` to trigger tab switches.\n *\n * @example\n * ```tsx\n * 'use client'\n * import React from 'react'\n * import type { CustomTabButtonProps } from '@veiag/payload-enhanced-sidebar'\n * import { useTabState, useEnhancedSidebar } from '@veiag/payload-enhanced-sidebar'\n *\n * export const MyTabButton: React.FC<CustomTabButtonProps> = ({ id, type, icon, label, href }) => {\n * const { isActive } = useTabState(id)\n * const { onTabChange } = useEnhancedSidebar()\n * if (type === 'link') return <a href={href}>{icon}{label}</a>\n * return <button onClick={() => onTabChange(id)}>{icon}{label}</button>\n * }\n * ```\n */\nexport type CustomTabButtonProps = {\n /** Badge configuration as defined in the plugin config */\n badge?: BadgeConfig\n /** Computed href (for link type, with admin route prefix applied) */\n href?: string\n /** Pre-rendered icon — either from `iconComponent` or the default Lucide icon */\n icon: ReactNode\n /** Tab/link id */\n id: string\n /** Whether the link is external (only set for link type) */\n isExternal?: boolean\n /** Pre-translated label */\n label: string\n /** Item type — use to differentiate rendering */\n type: 'link' | 'tab'\n}\n\n/**\n * Props received by a custom NavContent component registered via `customComponents.NavContent`.\n *\n * Renders in place of the default `<nav>` content area. Use the `useTabState(id)` hook\n * to determine which tab is active and show/hide content accordingly.\n *\n * @example\n * ```tsx\n * 'use client'\n * import type { CustomNavContentProps } from '@veiag/payload-enhanced-sidebar'\n * import { useTabState } from '@veiag/payload-enhanced-sidebar'\n *\n * const TabPanel = ({ id, content }: { id: string; content: React.ReactNode }) => {\n * const { isActive } = useTabState(id)\n * return <div style={{ display: isActive ? undefined : 'none' }}>{content}</div>\n * }\n *\n * export const MyNavContent: React.FC<CustomNavContentProps> = ({\n * tabs, tabsContent, beforeNavLinks, afterNavLinks,\n * }) => {\n * return (\n * <nav>\n * {beforeNavLinks}\n * {tabs.map(tab => <TabPanel key={tab.id} id={tab.id} content={tabsContent[tab.id]} />)}\n * {afterNavLinks}\n * </nav>\n * )\n * }\n * ```\n */\nexport type CustomNavContentProps = {\n /** Rendered afterNavLinks from payload config */\n afterNavLinks?: ReactNode\n /** Content to show when no tabs are defined */\n allContent?: ReactNode\n /** Rendered beforeNavLinks from payload config */\n beforeNavLinks?: ReactNode\n /** Tab definitions (id only) for mapping over */\n tabs: Array<{ id: string }>\n /** Pre-rendered content per tab id */\n tabsContent: Record<string, ReactNode>\n}\n\n/**\n * Configuration for the enhanced sidebar\n */\nexport interface EnhancedSidebarConfig {\n /**\n * Badge configurations for sidebar items (collections, globals, custom items).\n * Key is the slug of the item.\n *\n * @example\n * ```typescript\n * badges: {\n * 'posts': { type: 'collection-count', color: 'primary' },\n * 'orders': { type: 'api', endpoint: '/api/orders/pending', responseKey: 'count' },\n * 'notifications': { type: 'provider', color: 'error' },\n * }\n * ```\n */\n badges?: Record<string, BadgeConfig>\n\n /**\n * Custom components to replace the default NavItem, NavGroup, and/or NavContent rendering.\n * Each field accepts a plain path string or a `SidebarComponent` object `{ path, clientProps }`\n * to forward additional props. The plugin registers them in the import map automatically.\n *\n * @example\n * ```typescript\n * customComponents: {\n * // Plain path\n * NavItem: './components/MySidebar#MyNavItem',\n * // With extra client props forwarded to the component\n * NavGroup: { path: './components/MySidebar#MyNavGroup', clientProps: { collapsible: true } },\n * }\n * ```\n */\n customComponents?: {\n /**\n * Custom NavContent component. Replaces the default `<nav>` content area.\n * Receives `CustomNavContentProps`. Use `useTabState(id)` to check if a tab is active.\n */\n NavContent?: SidebarComponent\n /** Custom NavGroup component. Receives `CustomNavGroupProps`. */\n NavGroup?: SidebarComponent\n /** Custom NavItem component. Receives `CustomNavItemProps`. */\n NavItem?: SidebarComponent\n /**\n * Custom tab button component. Used for both `tab` and `link` items in the tabs bar.\n * Receives `CustomTabButtonProps`. Use `useTabState(id)` and `useEnhancedSidebar()` for state.\n */\n TabButton?: SidebarComponent\n }\n\n /**\n * Disable the plugin\n * @default false\n */\n disabled?: boolean\n\n /**\n * Show logout button at the bottom of the tabs bar.\n * @default true\n */\n showLogout?: boolean\n\n /**\n * Tabs and links to show in the sidebar tabs bar.\n * Order matters - items are rendered top to bottom.\n *\n * @default [{ type: 'tab', id: 'default', icon: 'LayoutGrid', label: 'Collections' }]\n */\n tabs?: SidebarTab[]\n}\n\n/**\n * Generic document type for collections, with dynamic keys.\n * We assume values are either string or number for simplicity, useAsTitle is making sure of that.\n */\nexport type GenericCollectionDocument = {\n [key: string]: number | string\n id: string\n}\n\ninterface BaseExtendedEntity {\n label: Record<string, string> | string\n slug: string\n // 'collections' | 'globals' are EntityType enum values from groupNavItems output; 'custom' is ours\n type: 'collections' | 'custom' | 'globals'\n}\n\ninterface InternalExtendedEntity extends BaseExtendedEntity {\n href?: '' | `/${string}`\n isExternal?: false\n}\n\ninterface ExternalExtendedEntity extends BaseExtendedEntity {\n href: string\n isExternal: true\n}\n\nexport type ExtendedEntity = ExternalExtendedEntity | InternalExtendedEntity\n\nexport type ExtendedGroup = {\n entities: ExtendedEntity[]\n label: Record<string, string> | string\n}\n"],"names":[],"mappings":"AAqkBA,WAGC"}
1
+ {"version":3,"sources":["../src/types.ts"],"sourcesContent":["import type { icons, LucideIcon } from 'lucide-react'\nimport type { CollectionSlug, GlobalSlug, PayloadRequest, Where } from 'payload'\nimport type { ReactNode } from 'react'\n\nexport type IconName = keyof typeof icons\n\nexport type LocalizedString = { [locale: string]: string } | string\n\nexport type InternalIcon = IconName | LucideIcon\n\n// ============================================\n// Badge Types\n// ============================================\n\n/**\n * Available badge color variants\n */\nexport type BadgeColor = 'default' | 'error' | 'primary' | 'success' | 'warning'\n\n/**\n * Badge configuration For API-based fetching\n */\nexport interface BadgeConfigApi {\n /**\n * Badge color variant\n * @default 'default'\n */\n color?: BadgeColor\n /**\n * API endpoint to fetch badge data from.\n * Can be relative (to current origin) or absolute URL.\n */\n endpoint: string\n /**\n * HTTP method for the request\n * @default 'GET'\n */\n method?: 'GET' | 'POST'\n /**\n * Key in the response object to extract the count from\n * @default 'count'\n */\n responseKey?: string\n type: 'api'\n}\n\n/**\n * Badge configuration for provider-based values.\n * Values are provided via BadgeProvider context.\n */\nexport interface BadgeConfigProvider {\n /**\n * Badge color variant\n * @default 'default'\n */\n color?: BadgeColor\n /**\n * Slug to look up in the BadgeProvider values.\n * If not specified, defaults to the item's id/slug.\n */\n slug?: string\n type: 'provider'\n}\n\n/**\n * Badge configuration for automatic collection document count.\n * Fetches from /api/{collectionSlug}?limit=0 and uses totalDocs.\n */\nexport interface BadgeConfigCollectionCount {\n /**\n * Collection slug to count documents from.\n * If not specified, defaults to the item's slug.\n */\n collectionSlug?: CollectionSlug\n /**\n * Badge color variant\n * @default 'default'\n */\n color?: BadgeColor\n type: 'collection-count'\n /**\n * Optional where query to filter documents.\n * Will be serialized as query string.\n * @example { status: { equals: 'draft' } }\n */\n where?: Where\n}\n\n/**\n * Badge configuration - union of all badge types\n */\nexport type BadgeConfig = BadgeConfigApi | BadgeConfigCollectionCount | BadgeConfigProvider\n\n/**\n * Badge values provided via BadgeProvider context\n */\nexport type BadgeValues = Record<string, number | ReactNode>\n\n// ============================================\n// Access Control Types\n// ============================================\n\n/**\n * Access function for a tab or link in the tabs bar.\n * Return `false` to hide the item entirely (both the button and its content).\n */\nexport type TabAccessFunction = (args: {\n item: SidebarTab\n req: PayloadRequest\n}) => boolean | Promise<boolean>\n\n/**\n * Access function for a custom item inside a tab.\n * Return `false` to hide the item from the nav.\n */\nexport type ItemAccessFunction = (args: {\n item: SidebarTabItem\n req: PayloadRequest\n}) => boolean | Promise<boolean>\n\n// ============================================\n// Enhanced Sidebar Types\n// ============================================\n\n/**\n * Path to a component, either as a plain string or as an object with a path and\n * additional client props to forward to the component. Follows Payload's component format.\n *\n * @example\n * ```typescript\n * // Simple path\n * iconComponent: './components/Icons#TabIcon'\n *\n * // With client props — useful for a single component shared across all tabs\n * iconComponent: {\n * path: './components/Icons#TabIcon',\n * clientProps: { icon: 'house' },\n * }\n * ```\n */\nexport type SidebarComponent =\n | {\n /** Additional props forwarded to the component on the client */\n clientProps?: Record<string, unknown>\n /** Component path in Payload's format: `'./path/to/file#ExportName'` */\n path: string\n }\n | string\n\n/**\n * Mutually exclusive icon config: either a Lucide icon name OR a custom icon component path.\n */\ntype TabIconConfig =\n | {\n /** Icon name from lucide-react */\n icon: IconName\n iconComponent?: never\n }\n | {\n icon?: never\n /**\n * Path to a custom icon component. Receives `CustomTabIconProps`.\n * Supports a plain string path or `{ path, clientProps }` to forward extra props.\n * Registered automatically in the import map.\n */\n iconComponent: SidebarComponent\n }\n\n/**\n * Sidebar tab that shows content when selected\n */\nexport type SidebarTabContent = {\n /**\n * Access control function. Called server-side with the current request.\n * Return `false` to hide this tab (button + content) entirely.\n */\n access?: TabAccessFunction\n /**\n * Badge configuration for this tab.\n * Shows a badge on the tab icon in the tabs bar.\n */\n badge?: BadgeConfig\n /**\n * Collections to show in this tab.\n * If not specified, no collections are shown (unless items are specified).\n * Use collection slugs.\n */\n collections?: CollectionSlug[]\n /**\n * Custom items to add to this tab.\n * Items with `group` will be merged into matching collection groups.\n * Items without `group` will be shown at the bottom as a flat list.\n */\n customItems?: SidebarTabItem[]\n /**\n * Globals to show in this tab.\n * If not specified, no globals are shown.\n * Use global slugs.\n */\n globals?: GlobalSlug[]\n /** Unique identifier for the tab */\n id: string\n /** Tooltip/label for the tab */\n label: LocalizedString\n type: 'tab'\n} & TabIconConfig\n\ntype SidebarTabLinkBase = {\n /**\n * Access control function. Called server-side with the current request.\n * Return `false` to hide this link entirely.\n */\n access?: TabAccessFunction\n /**\n * Badge configuration for this link.\n * Shows a badge on the link icon in the tabs bar.\n */\n badge?: BadgeConfig\n /** Unique identifier */\n id: string\n /** Tooltip/label */\n label: LocalizedString\n type: 'link'\n} & TabIconConfig\ntype SidebarTabLinkExternal = {\n /** Link href (absolute URL) */\n href: string\n isExternal: true\n} & SidebarTabLinkBase\ntype SidebarTabLinkInternal = {\n /** Link href (relative to admin route) */\n href: '' | `/${string}`\n isExternal?: false\n} & SidebarTabLinkBase\n/**\n * Sidebar link that navigates to a URL (not a tab)\n */\nexport type SidebarTabLink = SidebarTabLinkExternal | SidebarTabLinkInternal\n/**\n * A custom component rendered in the tabs bar (spacer, separator, badge, etc.).\n * Does not open any content — it's purely a visual slot in the tabs column.\n */\nexport type SidebarTabCustom = {\n /**\n * Access control function. Called server-side with the current request.\n * Return `false` to hide this item entirely.\n */\n access?: TabAccessFunction\n /**\n * Component to render. Receives `{ id }` plus any `clientProps` you pass.\n * Supports a plain string path or `{ path, clientProps }`.\n */\n component: SidebarComponent\n /** Unique identifier */\n id: string\n type: 'custom'\n}\n\n/**\n * Props passed to a custom tabs bar component (spacer, separator, etc.).\n */\nexport type CustomTabsBarComponentProps = {\n id: string\n}\n\n/**\n * A tab, link, or custom component in the sidebar tabs bar\n */\nexport type SidebarTab = SidebarTabContent | SidebarTabCustom | SidebarTabLink\n\ninterface BaseSidebarTabItem {\n /**\n * Access control function. Called server-side with the current request.\n * Return `false` to hide this item from the nav.\n */\n access?: ItemAccessFunction\n /**\n * Group to add this item to.\n * If matches an existing collection group label, item will be merged into that group.\n * If no match found, a new group will be created with this label.\n * If not specified, item will be shown as ungrouped (position controlled by `position`).\n */\n group?: LocalizedString\n /** Display label */\n label: LocalizedString\n /**\n * Where to place this item relative to collection groups in the tab.\n * - `'top'` — appears above all collection/global groups\n * - `'bottom'` — appears below all groups (default)\n *\n * Has no effect on items that are merged into an existing collection group via `group`.\n * For new custom groups (unmatched `group` label), controls whether the group appears\n * at the top or bottom of the nav.\n *\n * @default 'bottom'\n */\n position?: 'bottom' | 'top'\n /** Unique slug for the item */\n slug: string\n}\ninterface ExternalHrefItem extends BaseSidebarTabItem {\n /** Link href (absolute URL or relative to root) */\n href: string\n /** Whether the link is external, without admin route prefix. */\n isExternal: true\n}\n\ninterface InternalHrefItem extends BaseSidebarTabItem {\n /** Link href (relative to admin route) */\n href: '' | `/${string}`\n /** Whether the link is external, without admin route prefix. */\n isExternal?: false\n}\n/**\n * Custom item inside a sidebar tab\n */\nexport type SidebarTabItem = ExternalHrefItem | InternalHrefItem\n\n// ============================================\n// Custom Component Types\n// ============================================\n\n/**\n * Props received by a custom NavItem component registered via `customComponents.NavItem`.\n *\n * Use the `useNavItemState(href)` hook to get reactive `isActive` / `isCurrentPage` values.\n *\n * @example\n * ```tsx\n * 'use client'\n * import React from 'react'\n * import { useNavItemState } from '@veiag/payload-enhanced-sidebar'\n * import type { CustomNavItemProps } from '@veiag/payload-enhanced-sidebar'\n *\n * export const MyNavItem: React.FC<CustomNavItemProps> = ({ entity, href, id, label, badgeConfig }) => {\n * const { isActive, isCurrentPage } = useNavItemState(href)\n * return <a href={href}>{label}</a>\n * }\n * ```\n */\nexport type CustomNavItemProps = {\n /** Badge configuration as defined in the plugin config */\n badgeConfig?: BadgeConfig\n /** The entity (collection, global, or custom item) */\n entity: ExtendedEntity\n /** Computed href with admin route prefix applied */\n href: string\n /** DOM element id */\n id: string\n /** Pre-translated label string */\n label: string\n}\n\n/**\n * Props received by a custom NavGroup component registered via `customComponents.NavGroup`.\n *\n * @example\n * ```tsx\n * 'use client'\n * import React from 'react'\n * import type { CustomNavGroupProps } from '@veiag/payload-enhanced-sidebar'\n *\n * export const MyNavGroup: React.FC<CustomNavGroupProps> = ({ label, isOpen, children }) => {\n * return <div><strong>{label}</strong>{children}</div>\n * }\n * ```\n */\nexport type CustomNavGroupProps = {\n /** Nav items inside the group */\n children: ReactNode\n /** Initial open state from nav preferences */\n isOpen?: boolean\n /** Translated group label */\n label: string\n}\n\n/**\n * Props received by a custom tab icon component set via `iconComponent` on a tab or link.\n *\n * @example\n * ```tsx\n * 'use client'\n * import React from 'react'\n * import type { CustomTabIconProps } from '@veiag/payload-enhanced-sidebar'\n *\n * export const MyIcon: React.FC<CustomTabIconProps> = ({ id, label }) => (\n * <img alt={label} src={`/icons/${id}.svg`} width={20} height={20} />\n * )\n * ```\n */\nexport type CustomTabIconProps = {\n /** Tab/link id */\n id: string\n /** Pre-translated label */\n label: string\n /** Whether this item is a tab or a link */\n type: 'link' | 'tab'\n}\n\n/**\n * Props received by a custom TabButton component registered via `customComponents.TabButton`.\n * Used for both `tab` and `link` type items in the tabs bar.\n *\n * Use `useTabState(id)` for tab active state, or `usePathname()` for link active state.\n * Use `useEnhancedSidebar().onTabChange` to trigger tab switches.\n *\n * @example\n * ```tsx\n * 'use client'\n * import React from 'react'\n * import type { CustomTabButtonProps } from '@veiag/payload-enhanced-sidebar'\n * import { useTabState, useEnhancedSidebar } from '@veiag/payload-enhanced-sidebar'\n *\n * export const MyTabButton: React.FC<CustomTabButtonProps> = ({ id, type, icon, label, href }) => {\n * const { isActive } = useTabState(id)\n * const { onTabChange } = useEnhancedSidebar()\n * if (type === 'link') return <a href={href}>{icon}{label}</a>\n * return <button onClick={() => onTabChange(id)}>{icon}{label}</button>\n * }\n * ```\n */\nexport type CustomTabButtonProps = {\n /** Badge configuration as defined in the plugin config */\n badge?: BadgeConfig\n /** Computed href (for link type, with admin route prefix applied) */\n href?: string\n /** Pre-rendered icon — either from `iconComponent` or the default Lucide icon */\n icon: ReactNode\n /** Tab/link id */\n id: string\n /** Whether the link is external (only set for link type) */\n isExternal?: boolean\n /** Pre-translated label */\n label: string\n /** Item type — use to differentiate rendering */\n type: 'link' | 'tab'\n}\n\n/**\n * Props received by a custom NavContent component registered via `customComponents.NavContent`.\n *\n * Renders in place of the default `<nav>` content area. Use the `useTabState(id)` hook\n * to determine which tab is active and show/hide content accordingly.\n *\n * @example\n * ```tsx\n * 'use client'\n * import type { CustomNavContentProps } from '@veiag/payload-enhanced-sidebar'\n * import { useTabState } from '@veiag/payload-enhanced-sidebar'\n *\n * const TabPanel = ({ id, content }: { id: string; content: React.ReactNode }) => {\n * const { isActive } = useTabState(id)\n * return <div style={{ display: isActive ? undefined : 'none' }}>{content}</div>\n * }\n *\n * export const MyNavContent: React.FC<CustomNavContentProps> = ({\n * tabs, tabsContent, beforeNavLinks, afterNavLinks,\n * }) => {\n * return (\n * <nav>\n * {beforeNavLinks}\n * {tabs.map(tab => <TabPanel key={tab.id} id={tab.id} content={tabsContent[tab.id]} />)}\n * {afterNavLinks}\n * </nav>\n * )\n * }\n * ```\n */\nexport type CustomNavContentProps = {\n /** Rendered afterNav from payload config (rendered after afterNavLinks) */\n afterNav?: ReactNode\n /** Rendered afterNavLinks from payload config */\n afterNavLinks?: ReactNode\n /** Content to show when no tabs are defined */\n allContent?: ReactNode\n /** Rendered beforeNav from payload config (rendered before beforeNavLinks) */\n beforeNav?: ReactNode\n /** Rendered beforeNavLinks from payload config */\n beforeNavLinks?: ReactNode\n /** Tab definitions (id only) for mapping over */\n tabs: Array<{ id: string }>\n /** Pre-rendered content per tab id */\n tabsContent: Record<string, ReactNode>\n}\n\n/**\n * Configuration for the enhanced sidebar\n */\nexport interface EnhancedSidebarConfig {\n /**\n * Badge configurations for sidebar items (collections, globals, custom items).\n * Key is the slug of the item.\n *\n * @example\n * ```typescript\n * badges: {\n * 'posts': { type: 'collection-count', color: 'primary' },\n * 'orders': { type: 'api', endpoint: '/api/orders/pending', responseKey: 'count' },\n * 'notifications': { type: 'provider', color: 'error' },\n * }\n * ```\n */\n badges?: Record<string, BadgeConfig>\n\n /**\n * Custom components to replace the default NavItem, NavGroup, and/or NavContent rendering.\n * Each field accepts a plain path string or a `SidebarComponent` object `{ path, clientProps }`\n * to forward additional props. The plugin registers them in the import map automatically.\n *\n * @example\n * ```typescript\n * customComponents: {\n * // Plain path\n * NavItem: './components/MySidebar#MyNavItem',\n * // With extra client props forwarded to the component\n * NavGroup: { path: './components/MySidebar#MyNavGroup', clientProps: { collapsible: true } },\n * }\n * ```\n */\n customComponents?: {\n /**\n * Custom NavContent component. Replaces the default `<nav>` content area.\n * Receives `CustomNavContentProps`. Use `useTabState(id)` to check if a tab is active.\n */\n NavContent?: SidebarComponent\n /** Custom NavGroup component. Receives `CustomNavGroupProps`. */\n NavGroup?: SidebarComponent\n /** Custom NavItem component. Receives `CustomNavItemProps`. */\n NavItem?: SidebarComponent\n /**\n * Custom tab button component. Used for both `tab` and `link` items in the tabs bar.\n * Receives `CustomTabButtonProps`. Use `useTabState(id)` and `useEnhancedSidebar()` for state.\n */\n TabButton?: SidebarComponent\n }\n\n /**\n * Disable the plugin\n * @default false\n */\n disabled?: boolean\n\n /**\n * Show logout button at the bottom of the tabs bar.\n * @default true\n */\n showLogout?: boolean\n\n /**\n * Tabs and links to show in the sidebar tabs bar.\n * Order matters - items are rendered top to bottom.\n *\n * @default [{ type: 'tab', id: 'default', icon: 'LayoutGrid', label: 'Collections' }]\n */\n tabs?: SidebarTab[]\n}\n\n/**\n * Generic document type for collections, with dynamic keys.\n * We assume values are either string or number for simplicity, useAsTitle is making sure of that.\n */\nexport type GenericCollectionDocument = {\n [key: string]: number | string\n id: string\n}\n\ninterface BaseExtendedEntity {\n label: Record<string, string> | string\n slug: string\n // 'collections' | 'globals' are EntityType enum values from groupNavItems output; 'custom' is ours\n type: 'collections' | 'custom' | 'globals'\n}\n\ninterface InternalExtendedEntity extends BaseExtendedEntity {\n href?: '' | `/${string}`\n isExternal?: false\n}\n\ninterface ExternalExtendedEntity extends BaseExtendedEntity {\n href: string\n isExternal: true\n}\n\nexport type ExtendedEntity = ExternalExtendedEntity | InternalExtendedEntity\n\nexport type ExtendedGroup = {\n entities: ExtendedEntity[]\n label: Record<string, string> | string\n}\n"],"names":[],"mappings":"AAykBA,WAGC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@veiag/payload-enhanced-sidebar",
3
- "version": "0.3.0",
3
+ "version": "0.3.2-canary.0",
4
4
  "description": "An enhanced sidebar plugin for Payload CMS with tabbed navigation to organize collections and globals.",
5
5
  "author": "VeiaG",
6
6
  "license": "MIT",
@@ -29,14 +29,14 @@
29
29
  ],
30
30
  "devDependencies": {
31
31
  "@eslint/eslintrc": "^3.2.0",
32
- "@payloadcms/db-mongodb": "3.60.0",
33
- "@payloadcms/db-postgres": "3.60.0",
34
- "@payloadcms/db-sqlite": "3.60.0",
32
+ "@payloadcms/db-mongodb": "3.75.0",
33
+ "@payloadcms/db-postgres": "3.75.0",
34
+ "@payloadcms/db-sqlite": "3.75.0",
35
35
  "@payloadcms/eslint-config": "3.9.0",
36
- "@payloadcms/next": "3.60.0",
37
- "@payloadcms/plugin-multi-tenant": "3.60.0",
38
- "@payloadcms/richtext-lexical": "3.60.0",
39
- "@payloadcms/ui": "3.60.0",
36
+ "@payloadcms/next": "3.75.0",
37
+ "@payloadcms/plugin-multi-tenant": "3.75.0",
38
+ "@payloadcms/richtext-lexical": "3.75.0",
39
+ "@payloadcms/ui": "3.75.0",
40
40
  "@playwright/test": "1.56.1",
41
41
  "@swc-node/register": "1.10.9",
42
42
  "@swc/cli": "0.6.0",
@@ -51,7 +51,7 @@
51
51
  "mongodb-memory-server": "10.1.4",
52
52
  "next": "15.4.8",
53
53
  "open": "^10.1.0",
54
- "payload": "3.60.0",
54
+ "payload": "3.75.0",
55
55
  "prettier": "^3.4.2",
56
56
  "qs-esm": "7.0.2",
57
57
  "react": "19.2.1",
@@ -64,7 +64,7 @@
64
64
  "vitest": "^3.1.2"
65
65
  },
66
66
  "peerDependencies": {
67
- "payload": "^3.60.0"
67
+ "payload": "^3.75.0"
68
68
  },
69
69
  "engines": {
70
70
  "node": "^18.20.2 || >=20.9.0",
@@ -72,7 +72,7 @@
72
72
  },
73
73
  "registry": "https://registry.npmjs.org/",
74
74
  "dependencies": {
75
- "@payloadcms/translations": "^3.60.0",
75
+ "@payloadcms/translations": "^3.75.0",
76
76
  "lucide-react": "^0.556.0"
77
77
  },
78
78
  "scripts": {