@prediktif/ui 0.1.26 → 0.1.27

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/index.js CHANGED
@@ -1396,12 +1396,27 @@ function formatSegment(segment, subHref, navMainItems = [], navSecondaryItems =
1396
1396
  }
1397
1397
  return segment.split("-").map((word) => word.charAt(0).toUpperCase() + word.slice(1)).join(" ");
1398
1398
  }
1399
- function isRouteActive(url, pathname) {
1399
+ function isRouteActive(url, pathname, allItems) {
1400
1400
  if (!pathname) return false;
1401
1401
  const cleanUrl = url.replace(/\/$/, "") || "/";
1402
1402
  const cleanPath = pathname.replace(/\/$/, "") || "/";
1403
1403
  if (cleanUrl === "/") return cleanPath === "/";
1404
- return cleanPath === cleanUrl || cleanPath.startsWith(`${cleanUrl}/`);
1404
+ if (cleanPath === "/") return false;
1405
+ if (cleanPath === cleanUrl) return true;
1406
+ if (cleanPath.startsWith(`${cleanUrl}/`)) return true;
1407
+ if (allItems == null ? void 0 : allItems.length) {
1408
+ const hasMoreSpecificMatch = allItems.some((item) => {
1409
+ const itemUrl = item.url.replace(/\/$/, "") || "/";
1410
+ if (itemUrl === "/" || itemUrl === cleanUrl) return false;
1411
+ return cleanPath === itemUrl || cleanPath.startsWith(`${itemUrl}/`);
1412
+ });
1413
+ if (hasMoreSpecificMatch) return false;
1414
+ }
1415
+ const urlFirstSegment = cleanUrl.split("/").filter(Boolean)[0];
1416
+ const pathFirstSegment = cleanPath.split("/").filter(Boolean)[0];
1417
+ return Boolean(
1418
+ urlFirstSegment && pathFirstSegment && urlFirstSegment === pathFirstSegment
1419
+ );
1405
1420
  }
1406
1421
  function AppSidebarInner({
1407
1422
  name = "",
@@ -1422,6 +1437,7 @@ function AppSidebarInner({
1422
1437
  const pathname = (0, import_navigation.usePathname)();
1423
1438
  const { setOpenMobile } = useSidebar();
1424
1439
  const segments = pathname ? pathname.split("/").filter(Boolean) : [];
1440
+ const allNavItems = [...navMainItems, ...navSecondaryItems];
1425
1441
  (0, import_react.useEffect)(() => {
1426
1442
  if (pathname) {
1427
1443
  setOpenMobile(false);
@@ -1507,7 +1523,7 @@ function AppSidebarInner({
1507
1523
  /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(SidebarGroup, { children: [
1508
1524
  /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(SidebarGroupLabel, { children: "Platform" }),
1509
1525
  /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(SidebarMenu, { children: navMainItems.map(({ title, url, icon, locked }) => {
1510
- const isActive = isRouteActive(url, pathname);
1526
+ const isActive = isRouteActive(url, pathname, allNavItems);
1511
1527
  return /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(SidebarMenuItem, { children: [
1512
1528
  /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(
1513
1529
  SidebarMenuButton,
@@ -1526,7 +1542,7 @@ function AppSidebarInner({
1526
1542
  }) })
1527
1543
  ] }),
1528
1544
  /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(SidebarGroup, { className: "mt-auto", children: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(SidebarGroupContent, { children: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(SidebarMenu, { children: navSecondaryItems.map(({ title, url, icon, locked }) => {
1529
- const isActive = isRouteActive(url, pathname);
1545
+ const isActive = isRouteActive(url, pathname, allNavItems);
1530
1546
  return /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(SidebarMenuItem, { children: [
1531
1547
  /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(
1532
1548
  SidebarMenuButton,
package/dist/index.mjs CHANGED
@@ -1305,12 +1305,27 @@ function formatSegment(segment, subHref, navMainItems = [], navSecondaryItems =
1305
1305
  }
1306
1306
  return segment.split("-").map((word) => word.charAt(0).toUpperCase() + word.slice(1)).join(" ");
1307
1307
  }
1308
- function isRouteActive(url, pathname) {
1308
+ function isRouteActive(url, pathname, allItems) {
1309
1309
  if (!pathname) return false;
1310
1310
  const cleanUrl = url.replace(/\/$/, "") || "/";
1311
1311
  const cleanPath = pathname.replace(/\/$/, "") || "/";
1312
1312
  if (cleanUrl === "/") return cleanPath === "/";
1313
- return cleanPath === cleanUrl || cleanPath.startsWith(`${cleanUrl}/`);
1313
+ if (cleanPath === "/") return false;
1314
+ if (cleanPath === cleanUrl) return true;
1315
+ if (cleanPath.startsWith(`${cleanUrl}/`)) return true;
1316
+ if (allItems == null ? void 0 : allItems.length) {
1317
+ const hasMoreSpecificMatch = allItems.some((item) => {
1318
+ const itemUrl = item.url.replace(/\/$/, "") || "/";
1319
+ if (itemUrl === "/" || itemUrl === cleanUrl) return false;
1320
+ return cleanPath === itemUrl || cleanPath.startsWith(`${itemUrl}/`);
1321
+ });
1322
+ if (hasMoreSpecificMatch) return false;
1323
+ }
1324
+ const urlFirstSegment = cleanUrl.split("/").filter(Boolean)[0];
1325
+ const pathFirstSegment = cleanPath.split("/").filter(Boolean)[0];
1326
+ return Boolean(
1327
+ urlFirstSegment && pathFirstSegment && urlFirstSegment === pathFirstSegment
1328
+ );
1314
1329
  }
1315
1330
  function AppSidebarInner({
1316
1331
  name = "",
@@ -1331,6 +1346,7 @@ function AppSidebarInner({
1331
1346
  const pathname = usePathname();
1332
1347
  const { setOpenMobile } = useSidebar();
1333
1348
  const segments = pathname ? pathname.split("/").filter(Boolean) : [];
1349
+ const allNavItems = [...navMainItems, ...navSecondaryItems];
1334
1350
  useEffect3(() => {
1335
1351
  if (pathname) {
1336
1352
  setOpenMobile(false);
@@ -1416,7 +1432,7 @@ function AppSidebarInner({
1416
1432
  /* @__PURE__ */ jsxs7(SidebarGroup, { children: [
1417
1433
  /* @__PURE__ */ jsx12(SidebarGroupLabel, { children: "Platform" }),
1418
1434
  /* @__PURE__ */ jsx12(SidebarMenu, { children: navMainItems.map(({ title, url, icon, locked }) => {
1419
- const isActive = isRouteActive(url, pathname);
1435
+ const isActive = isRouteActive(url, pathname, allNavItems);
1420
1436
  return /* @__PURE__ */ jsxs7(SidebarMenuItem, { children: [
1421
1437
  /* @__PURE__ */ jsxs7(
1422
1438
  SidebarMenuButton,
@@ -1435,7 +1451,7 @@ function AppSidebarInner({
1435
1451
  }) })
1436
1452
  ] }),
1437
1453
  /* @__PURE__ */ jsx12(SidebarGroup, { className: "mt-auto", children: /* @__PURE__ */ jsx12(SidebarGroupContent, { children: /* @__PURE__ */ jsx12(SidebarMenu, { children: navSecondaryItems.map(({ title, url, icon, locked }) => {
1438
- const isActive = isRouteActive(url, pathname);
1454
+ const isActive = isRouteActive(url, pathname, allNavItems);
1439
1455
  return /* @__PURE__ */ jsxs7(SidebarMenuItem, { children: [
1440
1456
  /* @__PURE__ */ jsxs7(
1441
1457
  SidebarMenuButton,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prediktif/ui",
3
- "version": "0.1.26",
3
+ "version": "0.1.27",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.mjs",
6
6
  "types": "./dist/index.d.ts",