@enyxs/wikex-components 0.11.47 → 0.11.48

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/README.md CHANGED
@@ -55,6 +55,10 @@ The package has React, Material UI and Emotion as peer dependencies, so the host
55
55
 
56
56
  ## Release
57
57
 
58
+ ### 0.11.48
59
+
60
+ Header submenu links now match the query string as well as the pathname. Siblings that share a path, such as `/thong-bao/?source=wikex` and `/thong-bao/?source=mxv`, are no longer highlighted together; only the most specific matching link is active, in both the desktop dropdown and the mobile drawer. A parent item stays active on any page under its children's paths. No CMS schema or manifest changes. Frontend and backend must pin the same published version.
61
+
58
62
  ### 0.11.47
59
63
 
60
64
  Adds per-device CMS layout profiles and independent editable images for the three landing hero metrics. The partner hero includes the broker application form, shared validation, date and address inputs, and localized text. Runtime exports, types, embedded artwork, and the generated CMS manifest ship together. Frontend and backend must pin the same published version.
package/dist/index.js CHANGED
@@ -16633,6 +16633,29 @@ function Footer() {
16633
16633
  return /* @__PURE__ */ (0, import_jsx_runtime63.jsx)(Shell, { as: "div", children: /* @__PURE__ */ (0, import_jsx_runtime63.jsx)(LandingFooter, {}) });
16634
16634
  }
16635
16635
 
16636
+ // src/commodity-original/components/Header/active-links.ts
16637
+ var normalizePath = (path) => path.replace(/\/+$/, "") || "/";
16638
+ function isRouteActive(pathname, href) {
16639
+ const route = normalizePath(href.split(/[?#]/)[0]);
16640
+ if (route === "/comming-soon") return false;
16641
+ const current = normalizePath(pathname);
16642
+ return current === route || current.startsWith(`${route}/`);
16643
+ }
16644
+ function linkMatchScore(pathname, searchParams, href) {
16645
+ if (!isRouteActive(pathname, href)) return -1;
16646
+ let score = 0;
16647
+ for (const [key, value4] of new URLSearchParams(href.split("#")[0].split("?")[1] ?? "")) {
16648
+ if (searchParams.get(key) !== value4) return -1;
16649
+ score += 1;
16650
+ }
16651
+ return score;
16652
+ }
16653
+ function activeChildIndexes(pathname, searchParams, children) {
16654
+ const scores = children.map((child) => child.linkDisabled ? -1 : linkMatchScore(pathname, searchParams, child.href));
16655
+ const best = Math.max(-1, ...scores);
16656
+ return new Set(best < 0 ? [] : scores.flatMap((score, index) => score === best ? [index] : []));
16657
+ }
16658
+
16636
16659
  // src/commodity-original/components/Header/index.tsx
16637
16660
  var import_react39 = require("react");
16638
16661
  var import_image9 = __toESM(require("next/image.js"));
@@ -16786,12 +16809,9 @@ function LanguageSwitcher({
16786
16809
  }
16787
16810
  function Header() {
16788
16811
  const pathname = (0, import_navigation3.usePathname)().replace(/\/+$/, "") || "/";
16789
- const selectedCategory = (0, import_navigation3.useSearchParams)().get("category");
16790
- const isRouteActive = (href) => {
16791
- const route = href.split(/[?#]/)[0].replace(/\/+$/, "") || "/";
16792
- if (route === "/comming-soon") return false;
16793
- return pathname === route || pathname.startsWith(`${route}/`);
16794
- };
16812
+ const searchParams = (0, import_navigation3.useSearchParams)();
16813
+ const isRouteActive2 = (href) => isRouteActive(pathname, href);
16814
+ const activeChildIndexes2 = (children) => activeChildIndexes(pathname, searchParams, children);
16795
16815
  const [portalContainer, setPortalContainer] = (0, import_react39.useState)(null);
16796
16816
  const setHeaderRef = (0, import_react39.useCallback)((element) => {
16797
16817
  setPortalContainer(element);
@@ -16863,8 +16883,7 @@ function Header() {
16863
16883
  label: child.label ?? "",
16864
16884
  href: chromeItemHref(child) ?? "#",
16865
16885
  labelKey: `header.menuItems.${index}.children.${childIndex}.label`,
16866
- index: childIndex,
16867
- category: new URL(chromeItemHref(child) || "/", "https://wikex.invalid").searchParams.get("category")
16886
+ index: childIndex
16868
16887
  }))
16869
16888
  }));
16870
16889
  const scrollToPendingMobileSection = () => {
@@ -16937,7 +16956,8 @@ function Header() {
16937
16956
  )
16938
16957
  ] }),
16939
16958
  /* @__PURE__ */ (0, import_jsx_runtime65.jsx)(DesktopNavigation, { "aria-label": t("header.navigation"), children: resolvedNavigationItems.map((item) => {
16940
- const isItemActive = item.children.length > 0 ? item.children.some((child) => isRouteActive(child.href)) : isRouteActive(item.href);
16959
+ const isItemActive = item.children.length > 0 ? item.children.some((child) => isRouteActive2(child.href)) : isRouteActive2(item.href);
16960
+ const activeChildren = activeChildIndexes2(item.children);
16941
16961
  if (item.children.length > 0) {
16942
16962
  return /* @__PURE__ */ (0, import_jsx_runtime65.jsxs)(
16943
16963
  import_radix_ui5.DropdownMenu.Root,
@@ -16965,7 +16985,7 @@ function Header() {
16965
16985
  "aria-label": item.label,
16966
16986
  children: item.children.map((child) => /* @__PURE__ */ (0, import_jsx_runtime65.jsx)(ProductsMenuItem, { asChild: true, children: /* @__PURE__ */ (0, import_jsx_runtime65.jsx)(ExactText, { cmsAs: import_link7.default, cmsField: child.labelKey, ...chromeItemAttributes(language, "header.menuItems", child.index, item.index), href: child.href, "aria-disabled": child.linkDisabled || void 0, onClick: (event) => {
16967
16987
  if (child.linkDisabled) event.preventDefault();
16968
- }, "aria-current": isItemActive && selectedCategory === child.category ? "page" : void 0, children: child.label }) }, child.labelKey))
16988
+ }, "aria-current": activeChildren.has(child.index) ? "page" : void 0, children: child.label }) }, child.labelKey))
16969
16989
  }
16970
16990
  ) })
16971
16991
  ]
@@ -17095,7 +17115,8 @@ function Header() {
17095
17115
  ] }),
17096
17116
  /* @__PURE__ */ (0, import_jsx_runtime65.jsxs)(MobileMenuPanel, { "aria-label": t("header.mobileNavigation"), children: [
17097
17117
  resolvedNavigationItems.map((item) => {
17098
- const isItemActive = item.children.length > 0 ? item.children.some((child) => isRouteActive(child.href)) : isRouteActive(item.href);
17118
+ const isItemActive = item.children.length > 0 ? item.children.some((child) => isRouteActive2(child.href)) : isRouteActive2(item.href);
17119
+ const activeChildren = activeChildIndexes2(item.children);
17099
17120
  if (item.children.length > 0) {
17100
17121
  return /* @__PURE__ */ (0, import_jsx_runtime65.jsxs)("div", { className: "mobile-menu-group", ...chromeItemAttributes(language, "header.menuItems", item.index), children: [
17101
17122
  /* @__PURE__ */ (0, import_jsx_runtime65.jsxs)(
@@ -17148,7 +17169,7 @@ function Header() {
17148
17169
  cmsField: child.labelKey,
17149
17170
  ...chromeItemAttributes(language, "header.menuItems", child.index, item.index),
17150
17171
  href: child.href,
17151
- "aria-current": isItemActive && selectedCategory === child.category ? "page" : void 0,
17172
+ "aria-current": activeChildren.has(child.index) ? "page" : void 0,
17152
17173
  key: child.labelKey,
17153
17174
  "aria-disabled": child.linkDisabled || void 0,
17154
17175
  onClick: (event) => {
package/dist/index.mjs CHANGED
@@ -16560,6 +16560,29 @@ function Footer() {
16560
16560
  return /* @__PURE__ */ jsx57(Shell, { as: "div", children: /* @__PURE__ */ jsx57(LandingFooter, {}) });
16561
16561
  }
16562
16562
 
16563
+ // src/commodity-original/components/Header/active-links.ts
16564
+ var normalizePath = (path) => path.replace(/\/+$/, "") || "/";
16565
+ function isRouteActive(pathname, href) {
16566
+ const route = normalizePath(href.split(/[?#]/)[0]);
16567
+ if (route === "/comming-soon") return false;
16568
+ const current = normalizePath(pathname);
16569
+ return current === route || current.startsWith(`${route}/`);
16570
+ }
16571
+ function linkMatchScore(pathname, searchParams, href) {
16572
+ if (!isRouteActive(pathname, href)) return -1;
16573
+ let score = 0;
16574
+ for (const [key, value4] of new URLSearchParams(href.split("#")[0].split("?")[1] ?? "")) {
16575
+ if (searchParams.get(key) !== value4) return -1;
16576
+ score += 1;
16577
+ }
16578
+ return score;
16579
+ }
16580
+ function activeChildIndexes(pathname, searchParams, children) {
16581
+ const scores = children.map((child) => child.linkDisabled ? -1 : linkMatchScore(pathname, searchParams, child.href));
16582
+ const best = Math.max(-1, ...scores);
16583
+ return new Set(best < 0 ? [] : scores.flatMap((score, index) => score === best ? [index] : []));
16584
+ }
16585
+
16563
16586
  // src/commodity-original/components/Header/index.tsx
16564
16587
  import { useCallback as useCallback3, useEffect as useEffect11, useRef as useRef12, useState as useState19 } from "react";
16565
16588
  import Image9 from "next/image.js";
@@ -16713,12 +16736,9 @@ function LanguageSwitcher({
16713
16736
  }
16714
16737
  function Header() {
16715
16738
  const pathname = usePathname2().replace(/\/+$/, "") || "/";
16716
- const selectedCategory = useSearchParams().get("category");
16717
- const isRouteActive = (href) => {
16718
- const route = href.split(/[?#]/)[0].replace(/\/+$/, "") || "/";
16719
- if (route === "/comming-soon") return false;
16720
- return pathname === route || pathname.startsWith(`${route}/`);
16721
- };
16739
+ const searchParams = useSearchParams();
16740
+ const isRouteActive2 = (href) => isRouteActive(pathname, href);
16741
+ const activeChildIndexes2 = (children) => activeChildIndexes(pathname, searchParams, children);
16722
16742
  const [portalContainer, setPortalContainer] = useState19(null);
16723
16743
  const setHeaderRef = useCallback3((element) => {
16724
16744
  setPortalContainer(element);
@@ -16790,8 +16810,7 @@ function Header() {
16790
16810
  label: child.label ?? "",
16791
16811
  href: chromeItemHref(child) ?? "#",
16792
16812
  labelKey: `header.menuItems.${index}.children.${childIndex}.label`,
16793
- index: childIndex,
16794
- category: new URL(chromeItemHref(child) || "/", "https://wikex.invalid").searchParams.get("category")
16813
+ index: childIndex
16795
16814
  }))
16796
16815
  }));
16797
16816
  const scrollToPendingMobileSection = () => {
@@ -16864,7 +16883,8 @@ function Header() {
16864
16883
  )
16865
16884
  ] }),
16866
16885
  /* @__PURE__ */ jsx58(DesktopNavigation, { "aria-label": t("header.navigation"), children: resolvedNavigationItems.map((item) => {
16867
- const isItemActive = item.children.length > 0 ? item.children.some((child) => isRouteActive(child.href)) : isRouteActive(item.href);
16886
+ const isItemActive = item.children.length > 0 ? item.children.some((child) => isRouteActive2(child.href)) : isRouteActive2(item.href);
16887
+ const activeChildren = activeChildIndexes2(item.children);
16868
16888
  if (item.children.length > 0) {
16869
16889
  return /* @__PURE__ */ jsxs46(
16870
16890
  DropdownMenu2.Root,
@@ -16892,7 +16912,7 @@ function Header() {
16892
16912
  "aria-label": item.label,
16893
16913
  children: item.children.map((child) => /* @__PURE__ */ jsx58(ProductsMenuItem, { asChild: true, children: /* @__PURE__ */ jsx58(ExactText, { cmsAs: Link9, cmsField: child.labelKey, ...chromeItemAttributes(language, "header.menuItems", child.index, item.index), href: child.href, "aria-disabled": child.linkDisabled || void 0, onClick: (event) => {
16894
16914
  if (child.linkDisabled) event.preventDefault();
16895
- }, "aria-current": isItemActive && selectedCategory === child.category ? "page" : void 0, children: child.label }) }, child.labelKey))
16915
+ }, "aria-current": activeChildren.has(child.index) ? "page" : void 0, children: child.label }) }, child.labelKey))
16896
16916
  }
16897
16917
  ) })
16898
16918
  ]
@@ -17022,7 +17042,8 @@ function Header() {
17022
17042
  ] }),
17023
17043
  /* @__PURE__ */ jsxs46(MobileMenuPanel, { "aria-label": t("header.mobileNavigation"), children: [
17024
17044
  resolvedNavigationItems.map((item) => {
17025
- const isItemActive = item.children.length > 0 ? item.children.some((child) => isRouteActive(child.href)) : isRouteActive(item.href);
17045
+ const isItemActive = item.children.length > 0 ? item.children.some((child) => isRouteActive2(child.href)) : isRouteActive2(item.href);
17046
+ const activeChildren = activeChildIndexes2(item.children);
17026
17047
  if (item.children.length > 0) {
17027
17048
  return /* @__PURE__ */ jsxs46("div", { className: "mobile-menu-group", ...chromeItemAttributes(language, "header.menuItems", item.index), children: [
17028
17049
  /* @__PURE__ */ jsxs46(
@@ -17075,7 +17096,7 @@ function Header() {
17075
17096
  cmsField: child.labelKey,
17076
17097
  ...chromeItemAttributes(language, "header.menuItems", child.index, item.index),
17077
17098
  href: child.href,
17078
- "aria-current": isItemActive && selectedCategory === child.category ? "page" : void 0,
17099
+ "aria-current": activeChildren.has(child.index) ? "page" : void 0,
17079
17100
  key: child.labelKey,
17080
17101
  "aria-disabled": child.linkDisabled || void 0,
17081
17102
  onClick: (event) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@enyxs/wikex-components",
3
- "version": "0.11.47",
3
+ "version": "0.11.48",
4
4
  "description": "Reusable CMS blocks, including the original Wikex Commodity UI.",
5
5
  "license": "MIT",
6
6
  "sideEffects": [