@softwareone/spi-sv5-library 1.16.0 → 1.16.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.
@@ -362,7 +362,7 @@
362
362
  {#snippet removeButton(event: VoidFunction)}
363
363
  <button
364
364
  type="button"
365
- class="clear-button"
365
+ class="clear-button spi-text-regular-2"
366
366
  onclick={(e) => {
367
367
  e.stopPropagation();
368
368
  event();
@@ -1,5 +1,5 @@
1
1
  <script lang="ts">
2
- import type { AnnouncementItem, MenuItem } from '../../index.js';
2
+ import type { AnnouncementItem, MainMenu, MenuItem } from '../../index.js';
3
3
  import Announcement from '../announcement/Announcement.svelte';
4
4
  import Menu from '../menu/Menu.svelte';
5
5
  import Waffle from '../waffle/Waffle.svelte';
@@ -17,7 +17,7 @@
17
17
  userName?: string;
18
18
  hideLoader?: boolean;
19
19
  hideAnnouncement?: boolean;
20
- menuItems?: MenuItem[];
20
+ menuItems?: MainMenu[];
21
21
  waffleItems?: WaffleItem[];
22
22
  profileMenuItems?: MenuItem[];
23
23
  announcementItems?: AnnouncementItem[];
@@ -1,4 +1,4 @@
1
- import type { AnnouncementItem, MenuItem } from '../../index.js';
1
+ import type { AnnouncementItem, MainMenu, MenuItem } from '../../index.js';
2
2
  import type { WaffleItem } from '../waffle/types.js';
3
3
  interface Props {
4
4
  title?: string;
@@ -9,7 +9,7 @@ interface Props {
9
9
  userName?: string;
10
10
  hideLoader?: boolean;
11
11
  hideAnnouncement?: boolean;
12
- menuItems?: MenuItem[];
12
+ menuItems?: MainMenu[];
13
13
  waffleItems?: WaffleItem[];
14
14
  profileMenuItems?: MenuItem[];
15
15
  announcementItems?: AnnouncementItem[];
@@ -1,12 +1,14 @@
1
1
  <script lang="ts">
2
+ import { page } from '$app/state';
2
3
  import { fade } from 'svelte/transition';
3
4
 
4
- import { existRoute, getFirstPathSegment, getNormalizedPathname } from '../../utils/index.js';
5
+ import { existRoute, getSectionPrefix } from '../../utils/index.js';
5
6
  import MainMenuItem from './MenuItem.svelte';
6
- import type { MenuItem } from './types.js';
7
+ import type { MainMenu } from './types.js';
8
+ import { hasMenuItems } from './utils.js';
7
9
 
8
10
  interface Props {
9
- menuItems: MenuItem[];
11
+ menuItems: MainMenu[];
10
12
  showMenu: boolean;
11
13
  }
12
14
 
@@ -15,14 +17,13 @@
15
17
  let activeItem = $state('');
16
18
 
17
19
  const setActiveMenuItem = () => {
18
- activeItem =
19
- menuItems.find((menuItem: MenuItem) => isActiveMenuItem(menuItem.url))?.text || '';
20
+ activeItem = menuItems.find((menu) => isActiveMenuItem(menu))?.text || '';
20
21
  };
21
22
 
22
- const isActiveMenuItem = (url: string) => {
23
- const pathname = getNormalizedPathname();
24
- const firstPathSegment = getFirstPathSegment(pathname);
25
- return existRoute(firstPathSegment, url);
23
+ const isActiveMenuItem = (menu: MainMenu): boolean => {
24
+ const pathname = page.url.pathname;
25
+ const routeToMatch = hasMenuItems(menu.children) ? getSectionPrefix(menu.url) : menu.url;
26
+ return existRoute(routeToMatch, pathname);
26
27
  };
27
28
 
28
29
  const onHandleMenu = () => {
@@ -1,6 +1,6 @@
1
- import type { MenuItem } from './types.js';
1
+ import type { MainMenu } from './types.js';
2
2
  interface Props {
3
- menuItems: MenuItem[];
3
+ menuItems: MainMenu[];
4
4
  showMenu: boolean;
5
5
  }
6
6
  declare const Menu: import("svelte").Component<Props, {}, "showMenu">;
@@ -1,2 +1,3 @@
1
1
  import type { MainMenu, SubMenuItem } from './types.js';
2
+ export declare const hasMenuItems: (children?: SubMenuItem[]) => boolean;
2
3
  export declare const getSubMenuItemsFromMenu: (items: MainMenu[], excludedRoutes?: string[]) => SubMenuItem[];
@@ -1,11 +1,16 @@
1
- import { existRoute, getFirstPathSegment, getNormalizedPathname } from '../../utils/index.js';
1
+ import { page } from '$app/state';
2
+ import { existRoute, getSectionPrefix } from '../../utils/index.js';
3
+ export const hasMenuItems = (children) => {
4
+ return Boolean(children?.some((child) => child.menuItems.length));
5
+ };
2
6
  export const getSubMenuItemsFromMenu = (items, excludedRoutes) => {
3
- const pathname = getNormalizedPathname();
7
+ const pathname = page.url.pathname;
4
8
  if (excludedRoutes?.includes(pathname))
5
9
  return [];
6
- const firstPathSegment = getFirstPathSegment(pathname);
7
10
  const matchedMenu = items.find((menu) => {
8
- return existRoute(firstPathSegment, menu.url);
11
+ if (!hasMenuItems(menu.children))
12
+ return false;
13
+ return existRoute(getSectionPrefix(menu.url), pathname);
9
14
  });
10
15
  return matchedMenu?.children ?? [];
11
16
  };
@@ -1,3 +1,2 @@
1
- export declare const getNormalizedPathname: () => string;
2
- export declare const getFirstPathSegment: (pathname: string) => string;
1
+ export declare const getSectionPrefix: (url: string) => string;
3
2
  export declare const existRoute: (url: string, pathname: string) => boolean;
package/dist/utils/url.js CHANGED
@@ -1,17 +1,9 @@
1
- import { base } from '$app/paths';
2
- import { page } from '$app/state';
3
- const normalizePathname = (path) => path.replace(/^\/v\d+\//, '/');
4
- export const getNormalizedPathname = () => {
5
- const pathname = page.url.pathname;
6
- const withoutBase = base && pathname.startsWith(base) ? pathname.slice(base.length) : pathname;
7
- return normalizePathname(withoutBase);
8
- };
9
- export const getFirstPathSegment = (pathname) => {
10
- const matchedPath = /^\/[^/]+/.exec(pathname);
11
- return matchedPath?.[0] ?? '/';
1
+ export const getSectionPrefix = (url) => {
2
+ const segments = url.split('/');
3
+ segments.pop();
4
+ return segments.join('/') || '/';
12
5
  };
13
6
  export const existRoute = (url, pathname) => {
14
- const normalizedPathname = normalizePathname(pathname);
15
- const regex = new RegExp(`^${url}(?![\\w-])`);
16
- return regex.test(normalizedPathname);
7
+ const regex = new RegExp(String.raw `^${url}(?![\w-])`);
8
+ return regex.test(pathname);
17
9
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@softwareone/spi-sv5-library",
3
- "version": "1.16.0",
3
+ "version": "1.16.1",
4
4
  "description": "Svelte components",
5
5
  "keywords": [
6
6
  "svelte",