baaz-custom-components 3.2.4 → 3.2.6

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
@@ -434,7 +434,7 @@ function SrpDropDown({
434
434
  hubIdEnable
435
435
  }) {
436
436
  const defaultValue = userData.currentHubId.toString();
437
- return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(Select, { onValueChange: onChange, defaultValue, disabled: hubIdEnable, children: [
437
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(Select, { onValueChange: onChange, defaultValue, disabled: !hubIdEnable, children: [
438
438
  /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(SelectTrigger, { className: "w-[100px] cursor-pointer", children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(SelectValue, { placeholder: "Hub Id" }) }),
439
439
  /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(SelectContent, { children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(ScrollArea, { className: "h-40 w-full", children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(SelectGroup, { className: "cursor-pointer", children: hubIds == null ? void 0 : hubIds.map((hubId, index) => /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { children: [
440
440
  /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
@@ -724,19 +724,56 @@ function extractPathname(urlOrPath) {
724
724
  }
725
725
  return urlOrPath;
726
726
  }
727
+ function extractOrigin(urlOrPath) {
728
+ try {
729
+ if (urlOrPath.startsWith("http://") || urlOrPath.startsWith("https://")) {
730
+ return new URL(urlOrPath).origin;
731
+ }
732
+ } catch (_) {
733
+ }
734
+ return void 0;
735
+ }
736
+ function getCurrentOrigin() {
737
+ if (typeof window !== "undefined" && window.location) {
738
+ return window.location.origin;
739
+ }
740
+ return void 0;
741
+ }
742
+ function buildFullHref(base, route) {
743
+ return base + normalizePath(route);
744
+ }
745
+ function isRouteActive(fullHref, currentPathname) {
746
+ const hrefPath = extractPathname(fullHref);
747
+ if (hrefPath !== currentPathname) return false;
748
+ const hrefOrigin = extractOrigin(fullHref);
749
+ const currentOrigin = getCurrentOrigin();
750
+ if (!hrefOrigin || !currentOrigin) return true;
751
+ return hrefOrigin === currentOrigin;
752
+ }
727
753
  function treeContainsPath({
728
754
  data,
729
755
  base,
730
- pathname
756
+ pathname,
757
+ currentOrigin
731
758
  }) {
759
+ const originToMatch = currentOrigin != null ? currentOrigin : getCurrentOrigin();
732
760
  for (const value of data) {
733
761
  if (typeof value.routes === "string") {
734
- const full = base + normalizePath(value.routes);
762
+ const full = buildFullHref(base, value.routes);
735
763
  const onlyPath = extractPathname(full);
764
+ if (originToMatch) {
765
+ const fullOrigin = extractOrigin(full);
766
+ if (fullOrigin && fullOrigin !== originToMatch) continue;
767
+ }
736
768
  if (onlyPath === pathname) return true;
737
769
  continue;
738
770
  }
739
- if (treeContainsPath({ data: value.routes, base, pathname })) {
771
+ if (treeContainsPath({
772
+ data: value.routes,
773
+ base,
774
+ pathname,
775
+ currentOrigin: originToMatch
776
+ })) {
740
777
  return true;
741
778
  }
742
779
  }
@@ -755,8 +792,8 @@ function MenuItems({
755
792
  }) {
756
793
  return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_jsx_runtime9.Fragment, { children: data.map((value) => {
757
794
  if (isLeaf(value.routes)) {
758
- const fullPath = base + normalizePath(value.routes);
759
- const active = extractPathname(fullPath) === router.pathname;
795
+ const fullPath = buildFullHref(base, value.routes);
796
+ const active = isRouteActive(fullPath, router.pathname);
760
797
  return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
761
798
  MenubarItem,
762
799
  {
@@ -1555,8 +1592,8 @@ function renderMenu(data, base, router) {
1555
1592
  return data.map((value) => {
1556
1593
  const { scope, label, routes } = value;
1557
1594
  if (typeof routes === "string") {
1558
- const fullPath = `${base}${routes.startsWith("/") ? value : `/${value}`}`;
1559
- const active = extractPathname(fullPath) === router.pathname;
1595
+ const fullPath = buildFullHref(base, routes);
1596
+ const active = isRouteActive(fullPath, router.pathname);
1560
1597
  return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(SidebarMenuSubItem, { children: /* @__PURE__ */ (0, import_jsx_runtime16.jsxs)(
1561
1598
  SidebarMenuSubButton,
1562
1599
  {
package/dist/index.mjs CHANGED
@@ -400,7 +400,7 @@ function SrpDropDown({
400
400
  hubIdEnable
401
401
  }) {
402
402
  const defaultValue = userData.currentHubId.toString();
403
- return /* @__PURE__ */ jsxs4(Select, { onValueChange: onChange, defaultValue, disabled: hubIdEnable, children: [
403
+ return /* @__PURE__ */ jsxs4(Select, { onValueChange: onChange, defaultValue, disabled: !hubIdEnable, children: [
404
404
  /* @__PURE__ */ jsx6(SelectTrigger, { className: "w-[100px] cursor-pointer", children: /* @__PURE__ */ jsx6(SelectValue, { placeholder: "Hub Id" }) }),
405
405
  /* @__PURE__ */ jsx6(SelectContent, { children: /* @__PURE__ */ jsx6(ScrollArea, { className: "h-40 w-full", children: /* @__PURE__ */ jsx6(SelectGroup, { className: "cursor-pointer", children: hubIds == null ? void 0 : hubIds.map((hubId, index) => /* @__PURE__ */ jsxs4("div", { children: [
406
406
  /* @__PURE__ */ jsx6(
@@ -690,19 +690,56 @@ function extractPathname(urlOrPath) {
690
690
  }
691
691
  return urlOrPath;
692
692
  }
693
+ function extractOrigin(urlOrPath) {
694
+ try {
695
+ if (urlOrPath.startsWith("http://") || urlOrPath.startsWith("https://")) {
696
+ return new URL(urlOrPath).origin;
697
+ }
698
+ } catch (_) {
699
+ }
700
+ return void 0;
701
+ }
702
+ function getCurrentOrigin() {
703
+ if (typeof window !== "undefined" && window.location) {
704
+ return window.location.origin;
705
+ }
706
+ return void 0;
707
+ }
708
+ function buildFullHref(base, route) {
709
+ return base + normalizePath(route);
710
+ }
711
+ function isRouteActive(fullHref, currentPathname) {
712
+ const hrefPath = extractPathname(fullHref);
713
+ if (hrefPath !== currentPathname) return false;
714
+ const hrefOrigin = extractOrigin(fullHref);
715
+ const currentOrigin = getCurrentOrigin();
716
+ if (!hrefOrigin || !currentOrigin) return true;
717
+ return hrefOrigin === currentOrigin;
718
+ }
693
719
  function treeContainsPath({
694
720
  data,
695
721
  base,
696
- pathname
722
+ pathname,
723
+ currentOrigin
697
724
  }) {
725
+ const originToMatch = currentOrigin != null ? currentOrigin : getCurrentOrigin();
698
726
  for (const value of data) {
699
727
  if (typeof value.routes === "string") {
700
- const full = base + normalizePath(value.routes);
728
+ const full = buildFullHref(base, value.routes);
701
729
  const onlyPath = extractPathname(full);
730
+ if (originToMatch) {
731
+ const fullOrigin = extractOrigin(full);
732
+ if (fullOrigin && fullOrigin !== originToMatch) continue;
733
+ }
702
734
  if (onlyPath === pathname) return true;
703
735
  continue;
704
736
  }
705
- if (treeContainsPath({ data: value.routes, base, pathname })) {
737
+ if (treeContainsPath({
738
+ data: value.routes,
739
+ base,
740
+ pathname,
741
+ currentOrigin: originToMatch
742
+ })) {
706
743
  return true;
707
744
  }
708
745
  }
@@ -721,8 +758,8 @@ function MenuItems({
721
758
  }) {
722
759
  return /* @__PURE__ */ jsx9(Fragment, { children: data.map((value) => {
723
760
  if (isLeaf(value.routes)) {
724
- const fullPath = base + normalizePath(value.routes);
725
- const active = extractPathname(fullPath) === router.pathname;
761
+ const fullPath = buildFullHref(base, value.routes);
762
+ const active = isRouteActive(fullPath, router.pathname);
726
763
  return /* @__PURE__ */ jsx9(
727
764
  MenubarItem,
728
765
  {
@@ -1521,8 +1558,8 @@ function renderMenu(data, base, router) {
1521
1558
  return data.map((value) => {
1522
1559
  const { scope, label, routes } = value;
1523
1560
  if (typeof routes === "string") {
1524
- const fullPath = `${base}${routes.startsWith("/") ? value : `/${value}`}`;
1525
- const active = extractPathname(fullPath) === router.pathname;
1561
+ const fullPath = buildFullHref(base, routes);
1562
+ const active = isRouteActive(fullPath, router.pathname);
1526
1563
  return /* @__PURE__ */ jsx16(SidebarMenuSubItem, { children: /* @__PURE__ */ jsxs13(
1527
1564
  SidebarMenuSubButton,
1528
1565
  {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "baaz-custom-components",
3
- "version": "3.2.4",
3
+ "version": "3.2.6",
4
4
  "private": false,
5
5
  "sideEffects": false,
6
6
  "main": "dist/index.js",