@veiag/payload-enhanced-sidebar 0.1.1 → 0.2.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.
Files changed (45) hide show
  1. package/README.md +182 -5
  2. package/dist/components/EnhancedSidebar/Badge/index.d.ts +22 -0
  3. package/dist/components/EnhancedSidebar/Badge/index.js +30 -0
  4. package/dist/components/EnhancedSidebar/Badge/index.js.map +1 -0
  5. package/dist/components/EnhancedSidebar/Badge/index.scss +65 -0
  6. package/dist/components/EnhancedSidebar/BadgeProvider/index.d.ts +64 -0
  7. package/dist/components/EnhancedSidebar/BadgeProvider/index.js +66 -0
  8. package/dist/components/EnhancedSidebar/BadgeProvider/index.js.map +1 -0
  9. package/dist/components/EnhancedSidebar/InternalBadgeProvider/index.d.ts +15 -0
  10. package/dist/components/EnhancedSidebar/InternalBadgeProvider/index.js +132 -0
  11. package/dist/components/EnhancedSidebar/InternalBadgeProvider/index.js.map +1 -0
  12. package/dist/components/EnhancedSidebar/NavItem/index.d.ts +11 -0
  13. package/dist/components/EnhancedSidebar/NavItem/index.js +46 -0
  14. package/dist/components/EnhancedSidebar/NavItem/index.js.map +1 -0
  15. package/dist/components/EnhancedSidebar/SettingsMenuButton/index.d.ts +6 -0
  16. package/dist/components/EnhancedSidebar/SettingsMenuButton/index.js +33 -0
  17. package/dist/components/EnhancedSidebar/SettingsMenuButton/index.js.map +1 -0
  18. package/dist/components/EnhancedSidebar/SettingsMenuButton/index.scss +25 -0
  19. package/dist/components/EnhancedSidebar/SidebarContent.d.ts +2 -0
  20. package/dist/components/EnhancedSidebar/SidebarContent.js +117 -99
  21. package/dist/components/EnhancedSidebar/SidebarContent.js.map +1 -1
  22. package/dist/components/EnhancedSidebar/TabsBar/TabItem.d.ts +15 -0
  23. package/dist/components/EnhancedSidebar/TabsBar/TabItem.js +56 -0
  24. package/dist/components/EnhancedSidebar/TabsBar/TabItem.js.map +1 -0
  25. package/dist/components/EnhancedSidebar/TabsBar/index.d.ts +1 -0
  26. package/dist/components/EnhancedSidebar/TabsBar/index.js +58 -52
  27. package/dist/components/EnhancedSidebar/TabsBar/index.js.map +1 -1
  28. package/dist/components/EnhancedSidebar/TabsBar/index.scss +2 -2
  29. package/dist/components/EnhancedSidebar/hooks/useBadge.d.ts +11 -0
  30. package/dist/components/EnhancedSidebar/hooks/useBadge.js +31 -0
  31. package/dist/components/EnhancedSidebar/hooks/useBadge.js.map +1 -0
  32. package/dist/components/EnhancedSidebar/index.client.d.ts +2 -1
  33. package/dist/components/EnhancedSidebar/index.client.js +18 -31
  34. package/dist/components/EnhancedSidebar/index.client.js.map +1 -1
  35. package/dist/components/EnhancedSidebar/index.js +17 -1
  36. package/dist/components/EnhancedSidebar/index.js.map +1 -1
  37. package/dist/exports/client.d.ts +1 -0
  38. package/dist/exports/client.js +2 -1
  39. package/dist/exports/client.js.map +1 -1
  40. package/dist/index.d.ts +2 -1
  41. package/dist/index.js +16 -0
  42. package/dist/index.js.map +1 -1
  43. package/dist/types.d.ts +104 -1
  44. package/dist/types.js.map +1 -1
  45. package/package.json +10 -10
package/dist/types.d.ts CHANGED
@@ -1,14 +1,98 @@
1
1
  import type { icons, LucideIcon } from 'lucide-react';
2
- import type { CollectionSlug, GlobalSlug } from 'payload';
2
+ import type { CollectionSlug, GlobalSlug, Where } from 'payload';
3
+ import type { ReactNode } from 'react';
3
4
  export type IconName = keyof typeof icons;
4
5
  export type LocalizedString = {
5
6
  [locale: string]: string;
6
7
  } | string;
7
8
  export type InternalIcon = IconName | LucideIcon;
9
+ /**
10
+ * Available badge color variants
11
+ */
12
+ export type BadgeColor = 'default' | 'error' | 'primary' | 'success' | 'warning';
13
+ /**
14
+ * Badge configuration Trr API-based fetching
15
+ */
16
+ export interface BadgeConfigApi {
17
+ /**
18
+ * Badge color variant
19
+ * @default 'default'
20
+ */
21
+ color?: BadgeColor;
22
+ /**
23
+ * API endpoint to fetch badge data from.
24
+ * Can be relative (to current origin) or absolute URL.
25
+ */
26
+ endpoint: string;
27
+ /**
28
+ * HTTP method for the request
29
+ * @default 'GET'
30
+ */
31
+ method?: 'GET' | 'POST';
32
+ /**
33
+ * Key in the response object to extract the count from
34
+ * @default 'count'
35
+ */
36
+ responseKey?: string;
37
+ type: 'api';
38
+ }
39
+ /**
40
+ * Badge configuration for provider-based values.
41
+ * Values are provided via BadgeProvider context.
42
+ */
43
+ export interface BadgeConfigProvider {
44
+ /**
45
+ * Badge color variant
46
+ * @default 'default'
47
+ */
48
+ color?: BadgeColor;
49
+ /**
50
+ * Slug to look up in the BadgeProvider values.
51
+ * If not specified, defaults to the item's id/slug.
52
+ */
53
+ slug?: string;
54
+ type: 'provider';
55
+ }
56
+ /**
57
+ * Badge configuration for automatic collection document count.
58
+ * Fetches from /api/{collectionSlug}?limit=0 and uses totalDocs.
59
+ */
60
+ export interface BadgeConfigCollectionCount {
61
+ /**
62
+ * Collection slug to count documents from.
63
+ * If not specified, defaults to the item's slug.
64
+ */
65
+ collectionSlug?: CollectionSlug;
66
+ /**
67
+ * Badge color variant
68
+ * @default 'default'
69
+ */
70
+ color?: BadgeColor;
71
+ type: 'collection-count';
72
+ /**
73
+ * Optional where query to filter documents.
74
+ * Will be serialized as query string.
75
+ * @example { status: { equals: 'draft' } }
76
+ */
77
+ where?: Where;
78
+ }
79
+ /**
80
+ * Badge configuration - union of all badge types
81
+ */
82
+ export type BadgeConfig = BadgeConfigApi | BadgeConfigCollectionCount | BadgeConfigProvider;
83
+ /**
84
+ * Badge values provided via BadgeProvider context
85
+ */
86
+ export type BadgeValues = Record<string, number | ReactNode>;
8
87
  /**
9
88
  * Sidebar tab that shows content when selected
10
89
  */
11
90
  export interface SidebarTabContent {
91
+ /**
92
+ * Badge configuration for this tab.
93
+ * Shows a badge on the tab icon in the tabs bar.
94
+ */
95
+ badge?: BadgeConfig;
12
96
  /**
13
97
  * Collections to show in this tab.
14
98
  * If not specified, no collections are shown (unless items are specified).
@@ -36,6 +120,11 @@ export interface SidebarTabContent {
36
120
  type: 'tab';
37
121
  }
38
122
  interface SidebarTabLinkBase {
123
+ /**
124
+ * Badge configuration for this link.
125
+ * Shows a badge on the link icon in the tabs bar.
126
+ */
127
+ badge?: BadgeConfig;
39
128
  /** Icon name from lucide-react */
40
129
  icon: IconName;
41
130
  /** Unique identifier */
@@ -95,6 +184,20 @@ export type SidebarTabItem = ExternalHrefItem | InternalHrefItem;
95
184
  * Configuration for the enhanced sidebar
96
185
  */
97
186
  export interface EnhancedSidebarConfig {
187
+ /**
188
+ * Badge configurations for sidebar items (collections, globals, custom items).
189
+ * Key is the slug of the item.
190
+ *
191
+ * @example
192
+ * ```typescript
193
+ * badges: {
194
+ * 'posts': { type: 'collection-count', color: 'primary' },
195
+ * 'orders': { type: 'api', endpoint: '/api/orders/pending', responseKey: 'count' },
196
+ * 'notifications': { type: 'provider', color: 'error' },
197
+ * }
198
+ * ```
199
+ */
200
+ badges?: Record<string, BadgeConfig>;
98
201
  /**
99
202
  * Disable the plugin
100
203
  * @default false
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 } from 'payload'\n\nexport type IconName = keyof typeof icons\n\nexport type LocalizedString = { [locale: string]: string } | string\n\nexport type InternalIcon = IconName | LucideIcon\n\n// ============================================\n// Enhanced Sidebar Types\n// ============================================\n\n/**\n * Sidebar tab that shows content when selected\n */\nexport interface SidebarTabContent {\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 /** Icon name from lucide-react */\n icon: IconName\n /** Unique identifier for the tab */\n id: string\n /** Tooltip/label for the tab */\n label: LocalizedString\n type: 'tab'\n}\n\ninterface SidebarTabLinkBase {\n /** Icon name from lucide-react */\n icon: IconName\n /** Unique identifier */\n id: string\n /** Tooltip/label */\n label: LocalizedString\n type: 'link'\n}\ninterface SidebarTabLinkExternal extends SidebarTabLinkBase {\n /** Link href (absolute URL) */\n href: string\n isExternal: true\n}\ninterface SidebarTabLinkInternal extends SidebarTabLinkBase {\n /** Link href (relative to admin route) */\n href: '' | `/${string}`\n isExternal?: false\n}\n/**\n * Sidebar link that navigates to a URL (not a tab)\n */\nexport type SidebarTabLink = SidebarTabLinkExternal | SidebarTabLinkInternal\n/**\n * A tab or link in the sidebar tabs bar\n */\nexport type SidebarTab = SidebarTabContent | SidebarTabLink\n\ninterface BaseSidebarTabItem {\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.\n * If not specified, item will be shown at the bottom as ungrouped.\n */\n group?: LocalizedString\n /** Display label */\n label: LocalizedString\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 * Configuration for the enhanced sidebar\n */\nexport interface EnhancedSidebarConfig {\n /**\n * Disable the plugin\n * @default false\n */\n disabled?: boolean\n\n /**\n * Custom icons for collections and globals in the default tab.\n */\n icons?: {\n collections?: Partial<Record<CollectionSlug, IconName>>\n globals?: Partial<Record<GlobalSlug, IconName>>\n }\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 type: 'collection' | 'custom' | 'global'\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":"AAmKA,WAGC"}
1
+ {"version":3,"sources":["../src/types.ts"],"sourcesContent":["import type { icons, LucideIcon } from 'lucide-react'\nimport type { CollectionSlug, GlobalSlug, 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 Trr 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// Enhanced Sidebar Types\n// ============================================\n\n/**\n * Sidebar tab that shows content when selected\n */\nexport interface SidebarTabContent {\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 /** Icon name from lucide-react */\n icon: IconName\n /** Unique identifier for the tab */\n id: string\n /** Tooltip/label for the tab */\n label: LocalizedString\n type: 'tab'\n}\n\ninterface SidebarTabLinkBase {\n /**\n * Badge configuration for this link.\n * Shows a badge on the link icon in the tabs bar.\n */\n badge?: BadgeConfig\n /** Icon name from lucide-react */\n icon: IconName\n /** Unique identifier */\n id: string\n /** Tooltip/label */\n label: LocalizedString\n type: 'link'\n}\ninterface SidebarTabLinkExternal extends SidebarTabLinkBase {\n /** Link href (absolute URL) */\n href: string\n isExternal: true\n}\ninterface SidebarTabLinkInternal extends SidebarTabLinkBase {\n /** Link href (relative to admin route) */\n href: '' | `/${string}`\n isExternal?: false\n}\n/**\n * Sidebar link that navigates to a URL (not a tab)\n */\nexport type SidebarTabLink = SidebarTabLinkExternal | SidebarTabLinkInternal\n/**\n * A tab or link in the sidebar tabs bar\n */\nexport type SidebarTab = SidebarTabContent | SidebarTabLink\n\ninterface BaseSidebarTabItem {\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.\n * If not specified, item will be shown at the bottom as ungrouped.\n */\n group?: LocalizedString\n /** Display label */\n label: LocalizedString\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 * 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 * Disable the plugin\n * @default false\n */\n disabled?: boolean\n\n /**\n * Custom icons for collections and globals in the default tab.\n */\n icons?: {\n collections?: Partial<Record<CollectionSlug, IconName>>\n globals?: Partial<Record<GlobalSlug, IconName>>\n }\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 type: 'collection' | 'custom' | 'global'\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":"AAqRA,WAGC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@veiag/payload-enhanced-sidebar",
3
- "version": "0.1.1",
3
+ "version": "0.2.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,13 +29,13 @@
29
29
  ],
30
30
  "devDependencies": {
31
31
  "@eslint/eslintrc": "^3.2.0",
32
- "@payloadcms/db-mongodb": "3.37.0",
33
- "@payloadcms/db-postgres": "3.37.0",
34
- "@payloadcms/db-sqlite": "3.37.0",
32
+ "@payloadcms/db-mongodb": "3.60.0",
33
+ "@payloadcms/db-postgres": "3.60.0",
34
+ "@payloadcms/db-sqlite": "3.60.0",
35
35
  "@payloadcms/eslint-config": "3.9.0",
36
- "@payloadcms/next": "3.37.0",
37
- "@payloadcms/richtext-lexical": "3.37.0",
38
- "@payloadcms/ui": "3.37.0",
36
+ "@payloadcms/next": "3.60.0",
37
+ "@payloadcms/richtext-lexical": "3.60.0",
38
+ "@payloadcms/ui": "3.60.0",
39
39
  "@playwright/test": "1.56.1",
40
40
  "@swc-node/register": "1.10.9",
41
41
  "@swc/cli": "0.6.0",
@@ -50,7 +50,7 @@
50
50
  "mongodb-memory-server": "10.1.4",
51
51
  "next": "15.4.8",
52
52
  "open": "^10.1.0",
53
- "payload": "3.37.0",
53
+ "payload": "3.60.0",
54
54
  "prettier": "^3.4.2",
55
55
  "qs-esm": "7.0.2",
56
56
  "react": "19.2.1",
@@ -63,7 +63,7 @@
63
63
  "vitest": "^3.1.2"
64
64
  },
65
65
  "peerDependencies": {
66
- "payload": "^3.37.0"
66
+ "payload": "^3.60.0"
67
67
  },
68
68
  "engines": {
69
69
  "node": "^18.20.2 || >=20.9.0",
@@ -71,7 +71,7 @@
71
71
  },
72
72
  "registry": "https://registry.npmjs.org/",
73
73
  "dependencies": {
74
- "@payloadcms/translations": "^3.37.0",
74
+ "@payloadcms/translations": "^3.60.0",
75
75
  "lucide-react": "^0.556.0"
76
76
  },
77
77
  "scripts": {