@riverbankcms/sdk 0.6.0 → 0.6.1

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 (49) hide show
  1. package/README.md +239 -0
  2. package/dist/cli/index.js +22 -5
  3. package/dist/cli/index.js.map +1 -1
  4. package/dist/client/client.js +1 -1
  5. package/dist/client/client.js.map +1 -1
  6. package/dist/client/client.mjs +1 -1
  7. package/dist/client/client.mjs.map +1 -1
  8. package/dist/server/{Layout-BClXUTsd.d.mts → Layout-B7cvis7r.d.mts} +3 -3
  9. package/dist/server/{Layout-UXGjXv8M.d.ts → Layout-wBtJLTVX.d.ts} +3 -3
  10. package/dist/server/{chunk-PHS2KWJX.js → chunk-3B364WO2.js} +4 -4
  11. package/dist/server/chunk-3B364WO2.js.map +1 -0
  12. package/dist/server/{chunk-SSS7CCRR.js → chunk-EIVISR62.js} +15 -57
  13. package/dist/server/chunk-EIVISR62.js.map +1 -0
  14. package/dist/server/{chunk-SQMGHEJM.mjs → chunk-I7ZR2WO3.mjs} +2 -2
  15. package/dist/server/{chunk-SQMGHEJM.mjs.map → chunk-I7ZR2WO3.mjs.map} +1 -1
  16. package/dist/server/{chunk-EOWGKCUZ.js → chunk-IVHIQFJH.js} +2 -2
  17. package/dist/server/{chunk-EOWGKCUZ.js.map → chunk-IVHIQFJH.js.map} +1 -1
  18. package/dist/server/{chunk-2HXHFSMI.mjs → chunk-XXFF4RVR.mjs} +6 -6
  19. package/dist/server/chunk-XXFF4RVR.mjs.map +1 -0
  20. package/dist/server/{chunk-PMHLZ3FW.mjs → chunk-YXA4GAAQ.mjs} +15 -57
  21. package/dist/server/chunk-YXA4GAAQ.mjs.map +1 -0
  22. package/dist/server/{components-DppHY5oD.d.ts → components-CICSJyp_.d.ts} +1 -1
  23. package/dist/server/{components-BmaJxgCV.d.mts → components-CMMwDXTW.d.mts} +1 -1
  24. package/dist/server/components.d.mts +2 -2
  25. package/dist/server/components.d.ts +2 -2
  26. package/dist/server/components.js +3 -3
  27. package/dist/server/components.mjs +2 -2
  28. package/dist/server/index.js +2 -2
  29. package/dist/server/index.mjs +1 -1
  30. package/dist/server/navigation.d.mts +80 -145
  31. package/dist/server/navigation.d.ts +80 -145
  32. package/dist/server/navigation.js +2 -10
  33. package/dist/server/navigation.js.map +1 -1
  34. package/dist/server/navigation.mjs +7 -15
  35. package/dist/server/rendering/server.d.mts +1 -1
  36. package/dist/server/rendering/server.d.ts +1 -1
  37. package/dist/server/rendering/server.js +3 -3
  38. package/dist/server/rendering/server.mjs +2 -2
  39. package/dist/server/rendering.d.mts +3 -3
  40. package/dist/server/rendering.d.ts +3 -3
  41. package/dist/server/rendering.js +3 -3
  42. package/dist/server/rendering.mjs +2 -2
  43. package/dist/server/server.js +2 -2
  44. package/dist/server/server.mjs +1 -1
  45. package/package.json +1 -1
  46. package/dist/server/chunk-2HXHFSMI.mjs.map +0 -1
  47. package/dist/server/chunk-PHS2KWJX.js.map +0 -1
  48. package/dist/server/chunk-PMHLZ3FW.mjs.map +0 -1
  49. package/dist/server/chunk-SSS7CCRR.js.map +0 -1
@@ -12,26 +12,28 @@ import '@riverbankcms/db';
12
12
  * Navigation helper utilities for SDK sites.
13
13
  *
14
14
  * Provides helpers to transform CMS navigation data into render-ready structures.
15
- * Supports both simple NavItem arrays and full MenuViewModels for block rendering.
15
+ * All navigation functions return nested structures supporting dropdowns.
16
16
  *
17
- * @example Simple usage
17
+ * @example Getting nav items
18
18
  * ```ts
19
- * import { getPrimaryNavItems } from '@riverbankcms/sdk/navigation';
19
+ * import { getPrimaryNavItems, isNavLink, isNavDropdown } from '@riverbankcms/sdk/navigation';
20
20
  *
21
21
  * const headerNav = getPrimaryNavItems(siteData.navigation);
22
- * // [{ href: '/', label: 'Home', isExternal: false }, ...]
22
+ * headerNav.forEach(item => {
23
+ * if (isNavLink(item)) {
24
+ * console.log(item.href);
25
+ * } else {
26
+ * console.log(`${item.label} has ${item.children.length} children`);
27
+ * }
28
+ * });
23
29
  * ```
24
30
  *
25
- * @example Block rendering usage
31
+ * @example Building menu and logo
26
32
  * ```ts
27
- * import { buildMenuViewModel, buildLogoViewModel } from '@riverbankcms/sdk/navigation';
28
- *
29
- * const menu = buildMenuViewModel(siteData.navigation);
30
- * const logo = buildLogoViewModel(siteData.layout.logo, siteData.site.title);
33
+ * import { buildMenu, buildLogo } from '@riverbankcms/sdk/navigation';
31
34
  *
32
- * renderBlock(siteHeaderManifest, layout.header, {
33
- * viewModelOverrides: { menu, content: { logo } },
34
- * });
35
+ * const menu = buildMenu(siteData.navigation, siteData.routes);
36
+ * const logo = buildLogo(siteData.layout.logo, siteData.site.title);
35
37
  * ```
36
38
  *
37
39
  * @packageDocumentation
@@ -110,17 +112,6 @@ type LogoViewModel = {
110
112
  storagePath?: string;
111
113
  storageBucket?: string;
112
114
  } | null;
113
- /**
114
- * A simplified navigation item structure for component rendering.
115
- */
116
- type NavItem = {
117
- /** The URL to navigate to */
118
- href: string;
119
- /** Display text for the navigation link */
120
- label: string;
121
- /** Whether link should open in new tab (external links) */
122
- isExternal: boolean;
123
- };
124
115
  /**
125
116
  * A navigation link item with a direct URL.
126
117
  * Use `kind` discriminator for type-safe narrowing.
@@ -160,12 +151,12 @@ type NavDropdown = {
160
151
  children: NavLink[];
161
152
  };
162
153
  /**
163
- * Unified navigation item supporting both links and dropdowns.
154
+ * Navigation item - either a link or a dropdown container.
164
155
  * Use `kind` property for type-safe discrimination.
165
156
  *
166
157
  * @example
167
158
  * ```ts
168
- * const items = getNestedPrimaryNavItems(navigation);
159
+ * const items = getPrimaryNavItems(navigation);
169
160
  * items.forEach(item => {
170
161
  * if (item.kind === 'link') {
171
162
  * console.log(item.href);
@@ -175,72 +166,63 @@ type NavDropdown = {
175
166
  * });
176
167
  * ```
177
168
  */
178
- type NestedNavItem = NavLink | NavDropdown;
169
+ type NavItem = NavLink | NavDropdown;
179
170
  /**
180
171
  * Type guard to check if a navigation item is a link.
181
172
  */
182
- declare function isNavLink(item: NestedNavItem): item is NavLink;
173
+ declare function isNavLink(item: NavItem): item is NavLink;
183
174
  /**
184
175
  * Type guard to check if a navigation item is a dropdown.
185
176
  */
186
- declare function isNavDropdown(item: NestedNavItem): item is NavDropdown;
187
- /**
188
- * Simple nav link with pre-resolved href for block rendering.
189
- */
190
- type SimpleNavLink = {
191
- id: string;
192
- label: string;
193
- href: string;
194
- isExternal: boolean;
195
- };
177
+ declare function isNavDropdown(item: NavItem): item is NavDropdown;
196
178
  /**
197
- * Simple menu view model with pre-resolved hrefs.
198
- * Use this instead of MenuViewModel for cleaner data flow.
199
- */
200
- type SimpleMenuViewModel = {
201
- items: SimpleNavLink[];
202
- ctaItem: SimpleNavLink | null;
203
- };
204
- /**
205
- * Simple nested nav link with pre-resolved href.
206
- */
207
- type SimpleNestedNavLink = {
208
- kind: 'link';
209
- id: string;
210
- label: string;
211
- href: string;
212
- isExternal: boolean;
213
- };
214
- /**
215
- * Simple nested dropdown with pre-resolved children.
216
- */
217
- type SimpleNestedNavDropdown = {
218
- kind: 'dropdown';
219
- id: string;
220
- label: string;
221
- children: SimpleNestedNavLink[];
222
- };
223
- /**
224
- * Unified simple nested navigation item.
225
- */
226
- type SimpleNestedNavItem = SimpleNestedNavLink | SimpleNestedNavDropdown;
227
- /**
228
- * Simple menu view model with nested navigation support.
179
+ * Navigation menu with items and optional CTA.
180
+ * Built from CMS navigation data with pre-resolved hrefs.
181
+ *
182
+ * @example
183
+ * ```ts
184
+ * const menu = buildMenu(siteData.navigation, siteData.routes);
185
+ * menu.items.forEach(item => {
186
+ * if (item.kind === 'link') {
187
+ * console.log(item.href);
188
+ * } else {
189
+ * console.log(item.children);
190
+ * }
191
+ * });
192
+ * ```
229
193
  */
230
- type SimpleNestedMenuViewModel = {
231
- items: SimpleNestedNavItem[];
232
- ctaItem: SimpleNestedNavLink | null;
194
+ type Menu = {
195
+ items: NavItem[];
196
+ ctaItem: NavLink | null;
233
197
  };
234
198
  /**
235
- * Simple logo data for block rendering.
199
+ * Logo data for site rendering.
200
+ *
201
+ * @example
202
+ * ```ts
203
+ * const logo = buildLogo(siteData.layout.logo, siteData.site.title);
204
+ * if (logo) {
205
+ * <img src={logo.src} alt={logo.alt} />
206
+ * }
207
+ * ```
236
208
  */
237
- type SimpleLogo = {
209
+ type Logo = {
238
210
  type: 'image';
239
211
  src: string;
240
212
  alt: string;
241
213
  width?: number;
242
214
  height?: number;
243
215
  } | null;
216
+ /** @deprecated Use `NavLink` instead */
217
+ type SimpleNavLink = NavLink;
218
+ /** @deprecated Use `NavDropdown` instead */
219
+ type SimpleNavDropdown = NavDropdown;
220
+ /** @deprecated Use `NavItem` instead */
221
+ type SimpleNavItem = NavItem;
222
+ /** @deprecated Use `Menu` instead */
223
+ type SimpleMenuViewModel = Menu;
224
+ /** @deprecated Use `Logo` instead */
225
+ type SimpleLogo = Logo;
244
226
  /**
245
227
  * Get the primary navigation menu object.
246
228
  * Returns menu marked as isPrimary, or first menu if none marked.
@@ -248,7 +230,7 @@ type SimpleLogo = {
248
230
  * @example
249
231
  * ```ts
250
232
  * const menu = getPrimaryNavigation(siteData.navigation);
251
- * console.log(menu?.title); // "Main Navigation"
233
+ * console.log(menu?.name); // "main"
252
234
  * ```
253
235
  */
254
236
  declare function getPrimaryNavigation(navigation: NavigationMenuWithItems[]): NavigationMenuWithItems | null;
@@ -263,19 +245,22 @@ declare function getPrimaryNavigation(navigation: NavigationMenuWithItems[]): Na
263
245
  declare function getNavigationBySlug(navigation: NavigationMenuWithItems[], slug: string): NavigationMenuWithItems | null;
264
246
  /**
265
247
  * Get nav items from the primary menu (marked isPrimary, or first menu).
266
- * Returns empty array if no navigation configured.
248
+ * Returns nested structure supporting both links and dropdowns.
267
249
  *
268
250
  * @example
269
251
  * ```ts
270
252
  * const headerNav = getPrimaryNavItems(siteData.navigation);
271
- * // [{ href: '/', label: 'Home', isExternal: false }, ...]
253
+ * headerNav.forEach(item => {
254
+ * if (item.kind === 'dropdown') {
255
+ * console.log(`${item.label} has ${item.children.length} children`);
256
+ * }
257
+ * });
272
258
  * ```
273
259
  */
274
260
  declare function getPrimaryNavItems(navigation: NavigationMenuWithItems[]): NavItem[];
275
261
  /**
276
262
  * Get nav items from a specific menu by slug.
277
- * Useful for footer nav, secondary nav, etc.
278
- * Returns empty array if menu not found.
263
+ * Returns nested structure supporting both links and dropdowns.
279
264
  *
280
265
  * @example
281
266
  * ```ts
@@ -284,47 +269,19 @@ declare function getPrimaryNavItems(navigation: NavigationMenuWithItems[]): NavI
284
269
  */
285
270
  declare function getNavItemsBySlug(navigation: NavigationMenuWithItems[], slug: string): NavItem[];
286
271
  /**
287
- * Transform a menu into simple NavItem array.
288
- */
289
- declare function transformToNavItems(menu: NavigationMenuWithItems | null): NavItem[];
290
- /**
291
- * Transform a menu into nested NestedNavItem array.
292
- * Builds tree structure from flat items, supporting dropdowns with children.
272
+ * Transform a menu into NavItem array.
273
+ * Builds nested structure from flat items, supporting dropdowns with children.
293
274
  *
294
275
  * @example
295
276
  * ```ts
296
- * const nav = transformToNestedNavItems(menu);
277
+ * const nav = transformToNavItems(menu);
297
278
  * // [
298
279
  * // { kind: 'link', href: '/', label: 'Home', ... },
299
280
  * // { kind: 'dropdown', label: 'Services', children: [...] },
300
281
  * // ]
301
282
  * ```
302
283
  */
303
- declare function transformToNestedNavItems(menu: NavigationMenuWithItems | null): NestedNavItem[];
304
- /**
305
- * Get nested nav items from the primary menu.
306
- * Supports dropdowns with children for complex navigation structures.
307
- *
308
- * @example
309
- * ```ts
310
- * const nav = getNestedPrimaryNavItems(siteData.navigation);
311
- * nav.forEach(item => {
312
- * if (item.kind === 'dropdown') {
313
- * console.log(`${item.label} has ${item.children.length} children`);
314
- * }
315
- * });
316
- * ```
317
- */
318
- declare function getNestedPrimaryNavItems(navigation: NavigationMenuWithItems[]): NestedNavItem[];
319
- /**
320
- * Get nested nav items from a specific menu by slug.
321
- *
322
- * @example
323
- * ```ts
324
- * const footerNav = getNestedNavItemsBySlug(siteData.navigation, 'footer');
325
- * ```
326
- */
327
- declare function getNestedNavItemsBySlug(navigation: NavigationMenuWithItems[], slug: string): NestedNavItem[];
284
+ declare function transformToNavItems(menu: NavigationMenuWithItems | null): NavItem[];
328
285
  /**
329
286
  * Build a MenuViewModel from navigation data for block rendering.
330
287
  * Extracts CTA item separately and preserves full link data.
@@ -356,26 +313,15 @@ declare function buildMenuViewModel(navigation: NavigationMenuWithItems[]): Menu
356
313
  */
357
314
  declare function buildLogoViewModel(logo: LogoSource, fallbackTitle: string | null | undefined): LogoViewModel;
358
315
  /**
359
- * Build a SimpleMenuViewModel from navigation data with pre-resolved hrefs.
360
- * Use this instead of buildMenuViewModel for cleaner data flow.
316
+ * Build a Menu from navigation data with pre-resolved hrefs.
317
+ * Supports dropdown containers with nested children.
361
318
  *
362
319
  * @param navigation - Navigation menus from site data
363
320
  * @param routes - Route map for resolving internal links
364
321
  *
365
322
  * @example
366
323
  * ```ts
367
- * const menu = buildSimpleMenu(siteData.navigation, siteData.routes);
368
- * // { items: [{ id, label, href: '/', isExternal: false }], cta: null }
369
- * ```
370
- */
371
- declare function buildSimpleMenu(navigation: NavigationMenuWithItems[], routes: RouteMap): SimpleMenuViewModel;
372
- /**
373
- * Build a SimpleNestedMenuViewModel with pre-resolved hrefs.
374
- * Supports dropdown containers with nested children.
375
- *
376
- * @example
377
- * ```ts
378
- * const menu = buildSimpleNestedMenu(siteData.navigation, siteData.routes);
324
+ * const menu = buildMenu(siteData.navigation, siteData.routes);
379
325
  * menu.items.forEach(item => {
380
326
  * if (item.kind === 'dropdown') {
381
327
  * console.log(item.children);
@@ -383,34 +329,23 @@ declare function buildSimpleMenu(navigation: NavigationMenuWithItems[], routes:
383
329
  * });
384
330
  * ```
385
331
  */
386
- declare function buildSimpleNestedMenu(navigation: NavigationMenuWithItems[], routes: RouteMap): SimpleNestedMenuViewModel;
332
+ declare function buildMenu(navigation: NavigationMenuWithItems[], routes: RouteMap): Menu;
333
+ /** @deprecated Use `buildMenu` instead */
334
+ declare const buildSimpleMenu: typeof buildMenu;
387
335
  /**
388
- * Build a SimpleLogo from site layout data.
336
+ * Build a Logo from site layout data.
389
337
  *
390
338
  * @param logo - Logo data from site layout
391
339
  * @param fallbackAlt - Fallback alt text (usually site title)
392
340
  *
393
341
  * @example
394
342
  * ```ts
395
- * const logo = buildSimpleLogo(siteData.layout.logo, siteData.site.title);
343
+ * const logo = buildLogo(siteData.layout.logo, siteData.site.title);
396
344
  * // { src: 'https://...', alt: 'Site Name', width: 200, height: 50 }
397
345
  * ```
398
346
  */
399
- declare function buildSimpleLogo(logo: {
400
- url?: string | null;
401
- alt?: string | null;
402
- width?: number | null;
403
- height?: number | null;
404
- } | null, fallbackAlt: string | null | undefined): SimpleLogo;
405
- /**
406
- * @deprecated Use `transformToNavItems` instead.
407
- * This alias is maintained for backwards compatibility only.
408
- */
409
- declare const transformNavItems: typeof transformToNavItems;
410
- /**
411
- * @deprecated Use `getPrimaryNavigation` instead.
412
- * This alias is maintained for backwards compatibility only.
413
- */
414
- declare const selectPrimaryMenu: typeof getPrimaryNavigation;
347
+ declare function buildLogo(logo: Partial<LogoSource> | null, fallbackAlt: string | null | undefined): Logo;
348
+ /** @deprecated Use `buildLogo` instead */
349
+ declare const buildSimpleLogo: typeof buildLogo;
415
350
 
416
- export { type CustomLinkValue, type ExternalLinkValue, type InternalLinkValue, type LinkValue, type LogoSource, type LogoViewModel, type MenuCtaViewModel, type MenuLinkViewModel, type MenuViewModel, type NavDropdown, type NavItem, type NavLink, NavigationMenuWithItems, type NestedNavItem, type SimpleLogo, type SimpleMenuViewModel, type SimpleNavLink, type SimpleNestedMenuViewModel, type SimpleNestedNavDropdown, type SimpleNestedNavItem, type SimpleNestedNavLink, buildLogoViewModel, buildMenuViewModel, buildSimpleLogo, buildSimpleMenu, buildSimpleNestedMenu, getNavItemsBySlug, getNavigationBySlug, getNestedNavItemsBySlug, getNestedPrimaryNavItems, getPrimaryNavItems, getPrimaryNavigation, isNavDropdown, isNavLink, selectPrimaryMenu, transformNavItems, transformToNavItems, transformToNestedNavItems };
351
+ export { type CustomLinkValue, type ExternalLinkValue, type InternalLinkValue, type LinkValue, type Logo, type LogoSource, type LogoViewModel, type Menu, type MenuCtaViewModel, type MenuLinkViewModel, type MenuViewModel, type NavDropdown, type NavItem, type NavLink, NavigationMenuWithItems, type SimpleLogo, type SimpleMenuViewModel, type SimpleNavDropdown, type SimpleNavItem, type SimpleNavLink, buildLogo, buildLogoViewModel, buildMenu, buildMenuViewModel, buildSimpleLogo, buildSimpleMenu, getNavItemsBySlug, getNavigationBySlug, getPrimaryNavItems, getPrimaryNavigation, isNavDropdown, isNavLink, transformToNavItems };