baaz-custom-components 3.2.13 → 3.2.15

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
@@ -82,10 +82,10 @@ function useIsMobile() {
82
82
  }
83
83
 
84
84
  // src/components/custom/navbar/navbar.tsx
85
- var import_react3 = require("react");
85
+ var import_react4 = require("react");
86
86
 
87
87
  // src/components/custom/navbar/desktopNavbar.tsx
88
- var import_react2 = require("react");
88
+ var import_react3 = require("react");
89
89
 
90
90
  // src/components/ui/dropdown-menu.tsx
91
91
  var DropdownMenuPrimitive = __toESM(require("@radix-ui/react-dropdown-menu"));
@@ -786,31 +786,25 @@ function treeContainsPath({
786
786
  }
787
787
  return false;
788
788
  }
789
- function getDeepestActiveChildren(data, base, pathname) {
790
- let result = null;
791
- function dfs(routes, parentBase) {
792
- for (const node of routes) {
793
- if (typeof node.routes === "string") {
794
- const full = buildFullHref(parentBase, node.routes);
795
- let hrefPath = extractPathname(full);
796
- if (hrefPath.endsWith("/-")) hrefPath = hrefPath.slice(0, -2);
797
- if (pathname === hrefPath || pathname.startsWith(hrefPath + "/")) {
798
- }
799
- } else {
800
- const firstChild = node.routes[0];
801
- const maybePath = typeof firstChild.routes === "string" ? firstChild.routes : "";
802
- const full = buildFullHref(parentBase, maybePath);
803
- let hrefPath = extractPathname(full);
804
- if (hrefPath.endsWith("/-")) hrefPath = hrefPath.slice(0, -2);
805
- if (pathname.startsWith(hrefPath)) {
806
- result = { base: parentBase, children: node.routes };
807
- dfs(node.routes, parentBase);
808
- }
789
+ function getActiveRouteSiblings(data, base, pathname) {
790
+ for (const node of data) {
791
+ if (typeof node.routes === "string") {
792
+ const full = buildFullHref(base, node.routes);
793
+ let hrefPath = extractPathname(full);
794
+ if (hrefPath.endsWith("/-")) hrefPath = hrefPath.slice(0, -2);
795
+ if (pathname === hrefPath || pathname.startsWith(hrefPath + "/")) {
796
+ return { base, children: data };
809
797
  }
798
+ } else {
799
+ const childMatch = getActiveRouteSiblings(
800
+ node.routes,
801
+ base,
802
+ pathname
803
+ );
804
+ if (childMatch) return childMatch;
810
805
  }
811
806
  }
812
- dfs(data, base);
813
- return result;
807
+ return null;
814
808
  }
815
809
 
816
810
  // src/components/custom/navbar/customMenu.tsx
@@ -930,18 +924,22 @@ var Notifications = ({
930
924
  var notifications_default = Notifications;
931
925
 
932
926
  // src/components/custom/navbar/sub-nav.tsx
927
+ var import_react2 = require("react");
933
928
  var import_jsx_runtime11 = require("react/jsx-runtime");
934
929
  function SubNav({
935
930
  base,
936
931
  childrenRoutes,
937
932
  router
938
933
  }) {
939
- const pathname = typeof window !== "undefined" ? window.location.pathname : "";
934
+ const [path, setPath] = (0, import_react2.useState)(router.pathname);
935
+ (0, import_react2.useEffect)(() => {
936
+ setPath(router.pathname);
937
+ }, [router.pathname]);
940
938
  if (!childrenRoutes || childrenRoutes.length === 0) return null;
941
939
  return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("div", { className: "bg-transparent border rounded-md px-2 py-1 shadow-lg flex gap-2", children: childrenRoutes.map((child) => {
942
940
  if (typeof child.routes !== "string") return null;
943
941
  const href = buildFullHref(base, child.routes);
944
- const active = isRouteActive(href, pathname);
942
+ const active = isRouteActive(href, path);
945
943
  return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
946
944
  "button",
947
945
  {
@@ -971,7 +969,7 @@ function DesktopNavbar({
971
969
  hubIdChangeHandler
972
970
  }) {
973
971
  const pathname = router.pathname;
974
- const activeEntry = (0, import_react2.useMemo)(() => {
972
+ const activeEntry = (0, import_react3.useMemo)(() => {
975
973
  return navbarData == null ? void 0 : navbarData.find(
976
974
  (entry) => treeContainsPath({
977
975
  data: entry.routes,
@@ -980,9 +978,9 @@ function DesktopNavbar({
980
978
  })
981
979
  );
982
980
  }, [navbarData, pathname]);
983
- const subNavData = (0, import_react2.useMemo)(() => {
981
+ const subNavData = (0, import_react3.useMemo)(() => {
984
982
  if (!activeEntry) return null;
985
- return getDeepestActiveChildren(
983
+ return getActiveRouteSiblings(
986
984
  activeEntry.routes,
987
985
  activeEntry.url,
988
986
  pathname
@@ -1793,8 +1791,8 @@ function Navbar({
1793
1791
  notificationHandler
1794
1792
  }) {
1795
1793
  const isMobile = useIsMobile();
1796
- const [mounted, setMounted] = (0, import_react3.useState)(false);
1797
- (0, import_react3.useEffect)(() => {
1794
+ const [mounted, setMounted] = (0, import_react4.useState)(false);
1795
+ (0, import_react4.useEffect)(() => {
1798
1796
  setMounted(true);
1799
1797
  }, []);
1800
1798
  if (!mounted) return null;
package/dist/index.mjs CHANGED
@@ -48,7 +48,7 @@ function useIsMobile() {
48
48
  }
49
49
 
50
50
  // src/components/custom/navbar/navbar.tsx
51
- import { useEffect as useEffect3, useState as useState4 } from "react";
51
+ import { useEffect as useEffect4, useState as useState5 } from "react";
52
52
 
53
53
  // src/components/custom/navbar/desktopNavbar.tsx
54
54
  import { useMemo } from "react";
@@ -752,31 +752,25 @@ function treeContainsPath({
752
752
  }
753
753
  return false;
754
754
  }
755
- function getDeepestActiveChildren(data, base, pathname) {
756
- let result = null;
757
- function dfs(routes, parentBase) {
758
- for (const node of routes) {
759
- if (typeof node.routes === "string") {
760
- const full = buildFullHref(parentBase, node.routes);
761
- let hrefPath = extractPathname(full);
762
- if (hrefPath.endsWith("/-")) hrefPath = hrefPath.slice(0, -2);
763
- if (pathname === hrefPath || pathname.startsWith(hrefPath + "/")) {
764
- }
765
- } else {
766
- const firstChild = node.routes[0];
767
- const maybePath = typeof firstChild.routes === "string" ? firstChild.routes : "";
768
- const full = buildFullHref(parentBase, maybePath);
769
- let hrefPath = extractPathname(full);
770
- if (hrefPath.endsWith("/-")) hrefPath = hrefPath.slice(0, -2);
771
- if (pathname.startsWith(hrefPath)) {
772
- result = { base: parentBase, children: node.routes };
773
- dfs(node.routes, parentBase);
774
- }
755
+ function getActiveRouteSiblings(data, base, pathname) {
756
+ for (const node of data) {
757
+ if (typeof node.routes === "string") {
758
+ const full = buildFullHref(base, node.routes);
759
+ let hrefPath = extractPathname(full);
760
+ if (hrefPath.endsWith("/-")) hrefPath = hrefPath.slice(0, -2);
761
+ if (pathname === hrefPath || pathname.startsWith(hrefPath + "/")) {
762
+ return { base, children: data };
775
763
  }
764
+ } else {
765
+ const childMatch = getActiveRouteSiblings(
766
+ node.routes,
767
+ base,
768
+ pathname
769
+ );
770
+ if (childMatch) return childMatch;
776
771
  }
777
772
  }
778
- dfs(data, base);
779
- return result;
773
+ return null;
780
774
  }
781
775
 
782
776
  // src/components/custom/navbar/customMenu.tsx
@@ -896,18 +890,22 @@ var Notifications = ({
896
890
  var notifications_default = Notifications;
897
891
 
898
892
  // src/components/custom/navbar/sub-nav.tsx
893
+ import { useEffect as useEffect2, useState as useState3 } from "react";
899
894
  import { jsx as jsx11 } from "react/jsx-runtime";
900
895
  function SubNav({
901
896
  base,
902
897
  childrenRoutes,
903
898
  router
904
899
  }) {
905
- const pathname = typeof window !== "undefined" ? window.location.pathname : "";
900
+ const [path, setPath] = useState3(router.pathname);
901
+ useEffect2(() => {
902
+ setPath(router.pathname);
903
+ }, [router.pathname]);
906
904
  if (!childrenRoutes || childrenRoutes.length === 0) return null;
907
905
  return /* @__PURE__ */ jsx11("div", { className: "bg-transparent border rounded-md px-2 py-1 shadow-lg flex gap-2", children: childrenRoutes.map((child) => {
908
906
  if (typeof child.routes !== "string") return null;
909
907
  const href = buildFullHref(base, child.routes);
910
- const active = isRouteActive(href, pathname);
908
+ const active = isRouteActive(href, path);
911
909
  return /* @__PURE__ */ jsx11(
912
910
  "button",
913
911
  {
@@ -948,7 +946,7 @@ function DesktopNavbar({
948
946
  }, [navbarData, pathname]);
949
947
  const subNavData = useMemo(() => {
950
948
  if (!activeEntry) return null;
951
- return getDeepestActiveChildren(
949
+ return getActiveRouteSiblings(
952
950
  activeEntry.routes,
953
951
  activeEntry.url,
954
952
  pathname
@@ -1759,8 +1757,8 @@ function Navbar({
1759
1757
  notificationHandler
1760
1758
  }) {
1761
1759
  const isMobile = useIsMobile();
1762
- const [mounted, setMounted] = useState4(false);
1763
- useEffect3(() => {
1760
+ const [mounted, setMounted] = useState5(false);
1761
+ useEffect4(() => {
1764
1762
  setMounted(true);
1765
1763
  }, []);
1766
1764
  if (!mounted) return null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "baaz-custom-components",
3
- "version": "3.2.13",
3
+ "version": "3.2.15",
4
4
  "private": false,
5
5
  "sideEffects": false,
6
6
  "main": "dist/index.js",