@xyz/navigation 1.2.3 → 2.0.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/dist/module.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "compatibility": {
5
5
  "nuxt": "^3.0.0 || ^4.0.0"
6
6
  },
7
- "version": "1.2.3",
7
+ "version": "2.0.0",
8
8
  "builder": {
9
9
  "@nuxt/module-builder": "0.8.4",
10
10
  "unbuild": "2.0.0"
@@ -1,21 +1,21 @@
1
- import type { NavigationConfig, NavigationResult, UseNavigationOptions, NavigationSection } from '../types/index.js';
1
+ import type { NavigationConfig, NavigationResult, UseNavigationOptions, NavigationItemConfig } from '../types/index.js';
2
2
  /**
3
- * Main navigation composable
4
- * Processes navigation configuration and returns resolved items
3
+ * Main composable for context-aware navigation
4
+ * Auto-uses navigationConfig if no config provided
5
5
  *
6
6
  * @example
7
7
  * ```ts
8
8
  * const config = {
9
- * app: [
10
- * { label: 'Dashboard', to: '{org}', icon: 'i-lucide-layout-dashboard' },
11
- * { label: 'Settings', to: '{org}/settings', icon: 'i-lucide-settings' }
12
- * ]
9
+ * sections: {
10
+ * app: [
11
+ * { label: 'Dashboard', to: '{org}', icon: 'i-lucide-layout-dashboard' },
12
+ * { label: 'Settings', to: '{org}/settings', icon: 'i-lucide-settings' }
13
+ * ]
14
+ * }
13
15
  * }
14
16
  *
15
- * const { sections } = useNavigation(config)
16
- * // sections.app.value → processed items
17
+ * const { app } = useNavigation(config)
18
+ * // app.value → processed items array
17
19
  * ```
18
- * Main composable for context-aware navigation
19
- * Auto-uses navigationConfig if no config provided
20
20
  */
21
- export declare function useNavigation<T extends Record<string, NavigationSection>>(config?: NavigationConfig<T>, options?: UseNavigationOptions): NavigationResult<T>;
21
+ export declare function useNavigation<T extends Record<string, NavigationItemConfig[]>>(config?: NavigationConfig<T>, options?: UseNavigationOptions): NavigationResult<T>;
@@ -6,17 +6,14 @@ import { processNavigationItems } from "../utils/processor.js";
6
6
  import { createTemplateRegistry } from "../config/default-templates.js";
7
7
  import { validateNavigationConfig } from "../utils/validators.js";
8
8
  import { computeActiveStates } from "../utils/active-state.js";
9
- function isNestedSection(section) {
10
- return typeof section === "object" && !Array.isArray(section) && ("items" in section || "children" in section || "footer" in section || "header" in section);
11
- }
12
9
  export function useNavigation(config = navigationConfig, options = {}) {
13
- if (!config) {
10
+ if (!config || !config.sections) {
14
11
  throw new Error(
15
12
  "[xyz-navigation] No navigation config provided. Either create navigation.config.ts or pass config to useNavigation(config)."
16
13
  );
17
14
  }
18
15
  if (process.dev) {
19
- validateNavigationConfig(config);
16
+ validateNavigationConfig(config.sections);
20
17
  }
21
18
  const baseContext = useNavigationContext();
22
19
  const context = computed(() => {
@@ -35,40 +32,13 @@ export function useNavigation(config = navigationConfig, options = {}) {
35
32
  templates,
36
33
  translationFn: translateFn
37
34
  };
38
- const sectionsRaw = Object.keys(config).reduce((acc, key) => {
35
+ const sectionsRaw = Object.keys(config.sections).reduce((acc, key) => {
39
36
  const sectionKey = key;
40
- const section = config[sectionKey];
37
+ const section = config.sections[sectionKey];
41
38
  acc[sectionKey] = computed(() => {
42
39
  const ctx = context.value;
43
- const result = {};
44
- if (isNestedSection(section)) {
45
- if (section.header) {
46
- result.header = typeof section.header === "function" ? section.header(ctx) : section.header;
47
- }
48
- if (section.items) {
49
- const items = processNavigationItems(section.items, ctx, processingOptions);
50
- result.items = computeActiveStates(items, ctx.route.path);
51
- }
52
- if (section.children) {
53
- const children = processNavigationItems(section.children, ctx, processingOptions);
54
- result.children = computeActiveStates(children, ctx.route.path);
55
- }
56
- if (section.footer) {
57
- const footer = processNavigationItems(section.footer, ctx, processingOptions);
58
- result.footer = computeActiveStates(footer, ctx.route.path);
59
- }
60
- } else {
61
- const items = processNavigationItems(
62
- section,
63
- ctx,
64
- processingOptions
65
- );
66
- result.items = computeActiveStates(items, ctx.route.path);
67
- result.header = void 0;
68
- result.children = [];
69
- result.footer = [];
70
- }
71
- return result;
40
+ const items = processNavigationItems(section, ctx, processingOptions);
41
+ return computeActiveStates(items, ctx.route.path);
72
42
  });
73
43
  return acc;
74
44
  }, {});
@@ -125,67 +125,21 @@ export interface NavigationItemConfig {
125
125
  divider?: boolean;
126
126
  }
127
127
  /**
128
- * Processed navigation menu item (after resolution and filtering)
128
+ * Processed navigation menu item (with active state)
129
129
  */
130
- export interface NavigationMenuItem extends Omit<NavigationItemConfig, 'to' | 'children'> {
131
- to?: string;
132
- children?: NavigationMenuItem[];
130
+ export interface NavigationMenuItem extends NavigationItemConfig {
133
131
  active?: boolean;
134
132
  }
135
133
  /**
136
- * Section header configuration
134
+ * Navigation section - always a flat array of items
137
135
  */
138
- export interface SectionHeader {
139
- title?: string;
140
- subtitle?: string;
141
- avatar?: {
142
- src?: string | null;
143
- icon?: string;
144
- fallback?: string;
145
- };
146
- }
147
- /**
148
- * Nested section configuration
149
- */
150
- export interface NestedSectionConfig {
151
- /**
152
- * Header data (avatar, title, subtitle)
153
- */
154
- header?: (ctx: NavigationContext) => SectionHeader;
155
- /**
156
- * Base path for relative path resolution
157
- */
158
- basePath?: string | ((ctx: NavigationContext) => string);
159
- /**
160
- * Main navigation items
161
- */
162
- items?: NavigationItemConfig[];
163
- /**
164
- * Child/secondary items
165
- */
166
- children?: NavigationItemConfig[];
167
- /**
168
- * Footer items
169
- */
170
- footer?: NavigationItemConfig[];
171
- }
136
+ export type NavigationSection = NavigationItemConfig[];
172
137
  /**
173
- * Processed nested section (after resolution)
138
+ * Navigation configuration
174
139
  */
175
- export interface ProcessedNestedSection {
176
- header?: SectionHeader;
177
- items?: NavigationMenuItem[];
178
- children?: NavigationMenuItem[];
179
- footer?: NavigationMenuItem[];
180
- }
181
- /**
182
- * Section can be flat array or nested object
183
- */
184
- export type NavigationSection = NavigationItemConfig[] | NestedSectionConfig;
185
- /**
186
- * Navigation configuration type
187
- */
188
- export type NavigationConfig = Record<string, NavigationSection>;
140
+ export type NavigationConfig<T extends Record<string, NavigationSection> = Record<string, NavigationSection>> = {
141
+ sections: T;
142
+ };
189
143
  /**
190
144
  * Options for useNavigation composable
191
145
  */
@@ -218,7 +172,7 @@ export type NavigationResult<T extends Record<string, NavigationSection>> = {
218
172
  /**
219
173
  * All sections grouped in a single computed ref
220
174
  */
221
- sections: import('vue').ComputedRef<Record<keyof T, ProcessedNestedSection>>;
175
+ sections: import('vue').ComputedRef<Record<keyof T, NavigationMenuItem[]>>;
222
176
  /**
223
177
  * Navigation context
224
178
  */
@@ -228,7 +182,7 @@ export type NavigationResult<T extends Record<string, NavigationSection>> = {
228
182
  */
229
183
  refresh: () => void;
230
184
  } & {
231
- [K in keyof T]: import('vue').ComputedRef<ProcessedNestedSection>;
185
+ [K in keyof T]: import('vue').ComputedRef<NavigationMenuItem[]>;
232
186
  };
233
187
  /**
234
188
  * Sidebar state options
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xyz/navigation",
3
- "version": "1.2.3",
3
+ "version": "2.0.0",
4
4
  "description": "Context-aware, type-safe navigation for multi-tenant Nuxt applications",
5
5
  "type": "module",
6
6
  "exports": {