@consilioweb/admin-nav 0.4.3

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.

Potentially problematic release.


This version of @consilioweb/admin-nav might be problematic. Click here for more details.

@@ -0,0 +1,164 @@
1
+ import { Plugin, Config, CollectionConfig, PayloadHandler } from 'payload';
2
+
3
+ /** Localizable string — plain string or per-language record */
4
+ type LocalizedString = string | Record<string, string>;
5
+ /** A single navigation item */
6
+ interface NavItemConfig {
7
+ /** Unique item ID (e.g. 'pages', 'posts', 'seo-dashboard') */
8
+ id: string;
9
+ /** Admin URL path (e.g. '/admin/collections/pages') */
10
+ href: string;
11
+ /** Display label (string or { fr: '...', en: '...' }) */
12
+ label: LocalizedString;
13
+ /** Icon name from the built-in icon registry */
14
+ icon: string;
15
+ /** If true, pathname.startsWith(href) activates the item */
16
+ matchPrefix?: boolean;
17
+ /** Nested child items (e.g. ticket status filters) */
18
+ children?: NavItemConfig[];
19
+ /** Whether this item is visible (default: true) */
20
+ visible?: boolean;
21
+ }
22
+ /** A navigation group (section with a title) */
23
+ interface NavGroupConfig {
24
+ /** Unique group ID */
25
+ id: string;
26
+ /** Group title displayed as section header (string or { fr: '...', en: '...' }) */
27
+ title: LocalizedString;
28
+ /** Items in this group */
29
+ items: NavItemConfig[];
30
+ /** Whether this group is visible (default: true) */
31
+ visible?: boolean;
32
+ /** Whether this group starts collapsed (default: false) */
33
+ defaultCollapsed?: boolean;
34
+ }
35
+ /** Full navigation layout stored per-user in the database */
36
+ interface NavLayout {
37
+ /** Ordered list of navigation groups */
38
+ groups: NavGroupConfig[];
39
+ /** Schema version for future migrations */
40
+ version: number;
41
+ }
42
+ /** Plugin configuration options */
43
+ interface AdminNavPluginConfig {
44
+ /**
45
+ * Default navigation layout — the initial sidebar structure.
46
+ * If not provided, the plugin auto-discovers collections, globals, and views
47
+ * from the Payload config and generates a navigation layout automatically.
48
+ */
49
+ defaultNav?: NavGroupConfig[];
50
+ /** Components to render after the nav (e.g. NotificationCenter paths) */
51
+ afterNav?: string[];
52
+ /** Collection slug for preferences storage (default: 'admin-nav-preferences') */
53
+ collectionSlug?: string;
54
+ /** User collection slug to create the relationship (default: 'users') */
55
+ userCollectionSlug?: string;
56
+ /** Base path for API endpoints (default: '/admin-nav') */
57
+ endpointBasePath?: string;
58
+ /** Whether to add the /admin/nav-customizer view (default: true) */
59
+ addCustomizerView?: boolean;
60
+ /**
61
+ * Override the AdminNav component path for beforeNavLinks.
62
+ * Use this when the package is installed via file: or link: protocol
63
+ * to avoid webpack RSC resolution issues. Point to a local wrapper
64
+ * that re-exports AdminNav from the package.
65
+ * Example: '@/components/admin/AdminNavWrapper#AdminNav'
66
+ * Default: '@consilioweb/admin-nav/client#AdminNav'
67
+ */
68
+ navComponentPath?: string;
69
+ }
70
+
71
+ /**
72
+ * Payload CMS Admin Nav Plugin.
73
+ *
74
+ * Adds a fully customizable sidebar navigation to the Payload admin UI:
75
+ * - Per-user navigation preferences stored in the database
76
+ * - Drag & drop reordering (groups + items) via @dnd-kit
77
+ * - Show/hide items, create custom groups, edit labels/icons
78
+ * - API endpoints for preferences CRUD
79
+ * - Admin view at /admin/nav-customizer
80
+ * - i18n support (FR/EN, extensible)
81
+ * - Auto-discovery: generates nav from collections/globals/views if no defaultNav
82
+ *
83
+ * Usage:
84
+ * import { adminNavPlugin } from '@consilioweb/admin-nav'
85
+ *
86
+ * // Minimal — auto-discovers nav from Payload config
87
+ * export default buildConfig({
88
+ * plugins: [adminNavPlugin()],
89
+ * })
90
+ *
91
+ * // Custom — provide your own nav layout
92
+ * export default buildConfig({
93
+ * plugins: [
94
+ * adminNavPlugin({
95
+ * defaultNav: [
96
+ * { id: 'content', title: 'Content', items: [...] },
97
+ * ],
98
+ * }),
99
+ * ],
100
+ * })
101
+ */
102
+
103
+ declare const adminNavPlugin: (pluginConfig?: AdminNavPluginConfig) => Plugin;
104
+
105
+ /**
106
+ * Auto-discover navigation structure from Payload config.
107
+ *
108
+ * When no `defaultNav` is provided, the plugin reads collections, globals,
109
+ * and custom admin views from the Payload config and generates a reasonable
110
+ * navigation layout automatically.
111
+ */
112
+
113
+ /**
114
+ * Auto-discover navigation groups from a Payload config.
115
+ *
116
+ * Groups collections by their `admin.group` property.
117
+ * Creates items for globals and custom admin views.
118
+ * Assigns icons based on slug matching.
119
+ */
120
+ declare function autoDiscoverNav(config: Config): NavGroupConfig[];
121
+
122
+ /**
123
+ * Creates the AdminNavPreferences collection.
124
+ * Stores per-user navigation layout customizations.
125
+ */
126
+ declare function createAdminNavPreferencesCollection(slug?: string, userCollectionSlug?: string): CollectionConfig;
127
+
128
+ /**
129
+ * GET handler — retrieve current user's nav preferences.
130
+ * Returns the navLayout or null if no custom layout is saved.
131
+ */
132
+ declare function createGetPreferencesHandler(collectionSlug: string): PayloadHandler;
133
+ /**
134
+ * PATCH handler — save/update current user's nav preferences.
135
+ * Expects JSON body: { navLayout: NavLayout }
136
+ */
137
+ declare function createSavePreferencesHandler(collectionSlug: string): PayloadHandler;
138
+ /**
139
+ * DELETE handler — reset current user's nav preferences (back to default).
140
+ */
141
+ declare function createResetPreferencesHandler(collectionSlug: string): PayloadHandler;
142
+
143
+ /**
144
+ * Built-in SVG icon registry.
145
+ * Inline SVG paths — no external dependency (Lucide-compatible viewBox 0 0 24 24).
146
+ * Each icon is a <path d="..."/> string for a 24x24 viewBox.
147
+ */
148
+ declare const iconPaths: Record<string, string>;
149
+ /** Get all available icon names */
150
+ declare function getIconNames(): string[];
151
+ /** Get the SVG path data for a given icon name */
152
+ declare function getIconPath(name: string): string | undefined;
153
+
154
+ /**
155
+ * Check if a label is a multi-language record.
156
+ */
157
+ declare function isMultiLang(label: string | Record<string, string>): label is Record<string, string>;
158
+ /**
159
+ * Resolve a potentially multi-language label to a string.
160
+ * Falls back to: lang → fallback → first available value → empty string.
161
+ */
162
+ declare function resolveLabel(label: string | Record<string, string>, lang: string, fallback?: string): string;
163
+
164
+ export { type AdminNavPluginConfig, type LocalizedString, type NavGroupConfig, type NavItemConfig, type NavLayout, adminNavPlugin, autoDiscoverNav, createAdminNavPreferencesCollection, createGetPreferencesHandler, createResetPreferencesHandler, createSavePreferencesHandler, getIconNames, getIconPath, iconPaths, isMultiLang, resolveLabel };
@@ -0,0 +1,164 @@
1
+ import { Plugin, Config, CollectionConfig, PayloadHandler } from 'payload';
2
+
3
+ /** Localizable string — plain string or per-language record */
4
+ type LocalizedString = string | Record<string, string>;
5
+ /** A single navigation item */
6
+ interface NavItemConfig {
7
+ /** Unique item ID (e.g. 'pages', 'posts', 'seo-dashboard') */
8
+ id: string;
9
+ /** Admin URL path (e.g. '/admin/collections/pages') */
10
+ href: string;
11
+ /** Display label (string or { fr: '...', en: '...' }) */
12
+ label: LocalizedString;
13
+ /** Icon name from the built-in icon registry */
14
+ icon: string;
15
+ /** If true, pathname.startsWith(href) activates the item */
16
+ matchPrefix?: boolean;
17
+ /** Nested child items (e.g. ticket status filters) */
18
+ children?: NavItemConfig[];
19
+ /** Whether this item is visible (default: true) */
20
+ visible?: boolean;
21
+ }
22
+ /** A navigation group (section with a title) */
23
+ interface NavGroupConfig {
24
+ /** Unique group ID */
25
+ id: string;
26
+ /** Group title displayed as section header (string or { fr: '...', en: '...' }) */
27
+ title: LocalizedString;
28
+ /** Items in this group */
29
+ items: NavItemConfig[];
30
+ /** Whether this group is visible (default: true) */
31
+ visible?: boolean;
32
+ /** Whether this group starts collapsed (default: false) */
33
+ defaultCollapsed?: boolean;
34
+ }
35
+ /** Full navigation layout stored per-user in the database */
36
+ interface NavLayout {
37
+ /** Ordered list of navigation groups */
38
+ groups: NavGroupConfig[];
39
+ /** Schema version for future migrations */
40
+ version: number;
41
+ }
42
+ /** Plugin configuration options */
43
+ interface AdminNavPluginConfig {
44
+ /**
45
+ * Default navigation layout — the initial sidebar structure.
46
+ * If not provided, the plugin auto-discovers collections, globals, and views
47
+ * from the Payload config and generates a navigation layout automatically.
48
+ */
49
+ defaultNav?: NavGroupConfig[];
50
+ /** Components to render after the nav (e.g. NotificationCenter paths) */
51
+ afterNav?: string[];
52
+ /** Collection slug for preferences storage (default: 'admin-nav-preferences') */
53
+ collectionSlug?: string;
54
+ /** User collection slug to create the relationship (default: 'users') */
55
+ userCollectionSlug?: string;
56
+ /** Base path for API endpoints (default: '/admin-nav') */
57
+ endpointBasePath?: string;
58
+ /** Whether to add the /admin/nav-customizer view (default: true) */
59
+ addCustomizerView?: boolean;
60
+ /**
61
+ * Override the AdminNav component path for beforeNavLinks.
62
+ * Use this when the package is installed via file: or link: protocol
63
+ * to avoid webpack RSC resolution issues. Point to a local wrapper
64
+ * that re-exports AdminNav from the package.
65
+ * Example: '@/components/admin/AdminNavWrapper#AdminNav'
66
+ * Default: '@consilioweb/admin-nav/client#AdminNav'
67
+ */
68
+ navComponentPath?: string;
69
+ }
70
+
71
+ /**
72
+ * Payload CMS Admin Nav Plugin.
73
+ *
74
+ * Adds a fully customizable sidebar navigation to the Payload admin UI:
75
+ * - Per-user navigation preferences stored in the database
76
+ * - Drag & drop reordering (groups + items) via @dnd-kit
77
+ * - Show/hide items, create custom groups, edit labels/icons
78
+ * - API endpoints for preferences CRUD
79
+ * - Admin view at /admin/nav-customizer
80
+ * - i18n support (FR/EN, extensible)
81
+ * - Auto-discovery: generates nav from collections/globals/views if no defaultNav
82
+ *
83
+ * Usage:
84
+ * import { adminNavPlugin } from '@consilioweb/admin-nav'
85
+ *
86
+ * // Minimal — auto-discovers nav from Payload config
87
+ * export default buildConfig({
88
+ * plugins: [adminNavPlugin()],
89
+ * })
90
+ *
91
+ * // Custom — provide your own nav layout
92
+ * export default buildConfig({
93
+ * plugins: [
94
+ * adminNavPlugin({
95
+ * defaultNav: [
96
+ * { id: 'content', title: 'Content', items: [...] },
97
+ * ],
98
+ * }),
99
+ * ],
100
+ * })
101
+ */
102
+
103
+ declare const adminNavPlugin: (pluginConfig?: AdminNavPluginConfig) => Plugin;
104
+
105
+ /**
106
+ * Auto-discover navigation structure from Payload config.
107
+ *
108
+ * When no `defaultNav` is provided, the plugin reads collections, globals,
109
+ * and custom admin views from the Payload config and generates a reasonable
110
+ * navigation layout automatically.
111
+ */
112
+
113
+ /**
114
+ * Auto-discover navigation groups from a Payload config.
115
+ *
116
+ * Groups collections by their `admin.group` property.
117
+ * Creates items for globals and custom admin views.
118
+ * Assigns icons based on slug matching.
119
+ */
120
+ declare function autoDiscoverNav(config: Config): NavGroupConfig[];
121
+
122
+ /**
123
+ * Creates the AdminNavPreferences collection.
124
+ * Stores per-user navigation layout customizations.
125
+ */
126
+ declare function createAdminNavPreferencesCollection(slug?: string, userCollectionSlug?: string): CollectionConfig;
127
+
128
+ /**
129
+ * GET handler — retrieve current user's nav preferences.
130
+ * Returns the navLayout or null if no custom layout is saved.
131
+ */
132
+ declare function createGetPreferencesHandler(collectionSlug: string): PayloadHandler;
133
+ /**
134
+ * PATCH handler — save/update current user's nav preferences.
135
+ * Expects JSON body: { navLayout: NavLayout }
136
+ */
137
+ declare function createSavePreferencesHandler(collectionSlug: string): PayloadHandler;
138
+ /**
139
+ * DELETE handler — reset current user's nav preferences (back to default).
140
+ */
141
+ declare function createResetPreferencesHandler(collectionSlug: string): PayloadHandler;
142
+
143
+ /**
144
+ * Built-in SVG icon registry.
145
+ * Inline SVG paths — no external dependency (Lucide-compatible viewBox 0 0 24 24).
146
+ * Each icon is a <path d="..."/> string for a 24x24 viewBox.
147
+ */
148
+ declare const iconPaths: Record<string, string>;
149
+ /** Get all available icon names */
150
+ declare function getIconNames(): string[];
151
+ /** Get the SVG path data for a given icon name */
152
+ declare function getIconPath(name: string): string | undefined;
153
+
154
+ /**
155
+ * Check if a label is a multi-language record.
156
+ */
157
+ declare function isMultiLang(label: string | Record<string, string>): label is Record<string, string>;
158
+ /**
159
+ * Resolve a potentially multi-language label to a string.
160
+ * Falls back to: lang → fallback → first available value → empty string.
161
+ */
162
+ declare function resolveLabel(label: string | Record<string, string>, lang: string, fallback?: string): string;
163
+
164
+ export { type AdminNavPluginConfig, type LocalizedString, type NavGroupConfig, type NavItemConfig, type NavLayout, adminNavPlugin, autoDiscoverNav, createAdminNavPreferencesCollection, createGetPreferencesHandler, createResetPreferencesHandler, createSavePreferencesHandler, getIconNames, getIconPath, iconPaths, isMultiLang, resolveLabel };