@wix/editor-react-components 1.2847.0 → 1.2849.0

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.
@@ -1,7 +1,7 @@
1
1
  import { jsx, jsxs, Fragment } from "react/jsx-runtime";
2
2
  import { c as clsx } from "../chunks/clsx.js";
3
3
  import { useService, useGetService } from "@wix/services-manager-react";
4
- import { t as toUrlWithoutQuery } from "../chunks/urlUtils.js";
4
+ import { t as toUrlWithoutQuery, s as safeDecode } from "../chunks/urlUtils.js";
5
5
  import { U as UrlDefinition } from "../chunks/index16.js";
6
6
  import { d as defineService } from "../chunks/index11.js";
7
7
  import { T as TranslationsDefinition } from "../chunks/index4.js";
@@ -39,6 +39,7 @@ const MenuContextProvider = ({
39
39
  items,
40
40
  partToPreviewStateMap,
41
41
  currentUrl,
42
+ siteUrl,
42
43
  activeAnchor,
43
44
  translations,
44
45
  menuStyleId,
@@ -63,6 +64,7 @@ const MenuContextProvider = ({
63
64
  items,
64
65
  partToPreviewStateMap,
65
66
  currentUrl,
67
+ siteUrl,
66
68
  activeAnchor,
67
69
  translations,
68
70
  menuStyleId,
@@ -79,6 +81,7 @@ const MenuContextProvider = ({
79
81
  items,
80
82
  partToPreviewStateMap,
81
83
  currentUrl,
84
+ siteUrl,
82
85
  activeAnchor,
83
86
  translations,
84
87
  menuStyleId,
@@ -611,6 +614,24 @@ const INITIAL_HAMBURGER_MENU_ANIMATION_STATE = {
611
614
  name: HamburgerMenuAnimationName.None
612
615
  };
613
616
  const removeQueryFromUrl = (url) => url.split("?")[0];
617
+ const isPathInSite = (pathname, sitePathname) => {
618
+ const sitePath = sitePathname.replace(/\/$/, "");
619
+ return pathname === sitePath || pathname.startsWith(`${sitePath}/`);
620
+ };
621
+ const isSitePageHref = (href, siteUrl) => {
622
+ if (!href || href.startsWith("#") || href.startsWith("?")) {
623
+ return false;
624
+ }
625
+ try {
626
+ const { protocol, origin, pathname } = new URL(href, `${siteUrl}/`);
627
+ const site = new URL(siteUrl);
628
+ const isWebPage = protocol === "http:" || protocol === "https:";
629
+ return isWebPage && origin === site.origin && isPathInSite(pathname, site.pathname);
630
+ } catch {
631
+ return false;
632
+ }
633
+ };
634
+ const toComparablePageUrl = (href, siteUrl) => siteUrl && isSitePageHref(href, siteUrl) ? toUrlWithoutQuery(href, siteUrl) : safeDecode(removeQueryFromUrl(href));
614
635
  const isDefaultAnchor = (activeAnchor) => {
615
636
  return activeAnchor.dataId === "SCROLL_TO_TOP" || activeAnchor.dataId === "SCROLL_TO_BOTTOM";
616
637
  };
@@ -636,7 +657,7 @@ const flattenMenuItems = (items) => {
636
657
  });
637
658
  return result;
638
659
  };
639
- const getCurrentMenuItem = (items, activeAnchor, currentPageHref) => {
660
+ const getCurrentMenuItem = (items, activeAnchor, currentPageHref, siteUrl) => {
640
661
  const flatItems = flattenMenuItems(items);
641
662
  const selectedFromVelo = flatItems.find((item2) => item2.selected);
642
663
  if (selectedFromVelo) {
@@ -654,7 +675,7 @@ const getCurrentMenuItem = (items, activeAnchor, currentPageHref) => {
654
675
  if (!link) {
655
676
  return false;
656
677
  }
657
- return !isAnchorLink(link) && decodeURIComponent(removeQueryFromUrl(link.href || "")) === currentPageHref;
678
+ return !isAnchorLink(link) && toComparablePageUrl(link.href || "", siteUrl) === currentPageHref;
658
679
  });
659
680
  };
660
681
  const isSameAnchorLinks = (first, second) => {
@@ -1976,6 +1997,7 @@ const MenuContent = (props) => {
1976
1997
  items,
1977
1998
  partToPreviewStateMap,
1978
1999
  currentUrl,
2000
+ siteUrl,
1979
2001
  activeAnchor,
1980
2002
  translations,
1981
2003
  getAnimationPackage,
@@ -1992,7 +2014,12 @@ const MenuContent = (props) => {
1992
2014
  void 0
1993
2015
  );
1994
2016
  const currentItem = useMemo(() => {
1995
- const menuItem = getCurrentMenuItem(items, activeAnchor, currentUrl);
2017
+ const menuItem = getCurrentMenuItem(
2018
+ items,
2019
+ activeAnchor,
2020
+ currentUrl,
2021
+ siteUrl
2022
+ );
1996
2023
  if (activeAnchor) {
1997
2024
  if (isDefaultAnchor(activeAnchor)) {
1998
2025
  lastValidAnchorMenuItemRef.current = void 0;
@@ -2003,7 +2030,7 @@ const MenuContent = (props) => {
2003
2030
  }
2004
2031
  }
2005
2032
  return menuItem;
2006
- }, [items, activeAnchor, currentUrl]);
2033
+ }, [items, activeAnchor, currentUrl, siteUrl]);
2007
2034
  const {
2008
2035
  isScrollable,
2009
2036
  updateScrollState,
@@ -2519,6 +2546,7 @@ const Menu = (props) => {
2519
2546
  translations,
2520
2547
  getAnimationPackage: () => animationName,
2521
2548
  currentUrl,
2549
+ siteUrl: url.siteUrl,
2522
2550
  activeAnchor,
2523
2551
  navAriaLabel: ((_a = navbarProps == null ? void 0 : navbarProps.a11y) == null ? void 0 : _a.ariaLabel) ?? "",
2524
2552
  a11yProps: convertA11yKeysToHtmlFormat((navbarProps == null ? void 0 : navbarProps.a11y) ?? {}),
@@ -5,6 +5,7 @@ export type MenuContextValue = {
5
5
  items: Array<MenuItemWithChildren>;
6
6
  partToPreviewStateMap?: MenuPreviewStateMap;
7
7
  currentUrl: string;
8
+ siteUrl?: string;
8
9
  activeAnchor?: ActiveAnchor;
9
10
  translations: {
10
11
  dropdownButtonAriaLabel?: string;
@@ -1,4 +1,4 @@
1
1
  import { MenuItemProps, ActiveAnchor } from '../../../types/vendored/editor-elements-definitions';
2
2
  export declare const isDefaultAnchor: (activeAnchor: ActiveAnchor) => boolean;
3
- export declare const getCurrentMenuItem: (items: Array<MenuItemProps>, activeAnchor?: ActiveAnchor, currentPageHref?: string) => MenuItemProps | undefined;
3
+ export declare const getCurrentMenuItem: (items: Array<MenuItemProps>, activeAnchor?: ActiveAnchor, currentPageHref?: string, siteUrl?: string) => MenuItemProps | undefined;
4
4
  export declare const isCurrentItem: (item: MenuItemProps, currentItem?: MenuItemProps) => boolean;
@@ -17,5 +17,6 @@ const toUrlWithoutQuery = (currentUrl, siteUrl) => {
17
17
  return relative === "./" ? siteUrl : relative.replace("./", `${siteUrl}/`);
18
18
  };
19
19
  export {
20
+ safeDecode as s,
20
21
  toUrlWithoutQuery as t
21
22
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wix/editor-react-components",
3
- "version": "1.2847.0",
3
+ "version": "1.2849.0",
4
4
  "description": "React components for the Wix Editor",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -228,5 +228,5 @@
228
228
  "registry": "https://registry.npmjs.org/",
229
229
  "access": "public"
230
230
  },
231
- "falconPackageHash": "77670a572b4021ed23a8d36dc104c1dfd8a32bec13d723102513c195"
231
+ "falconPackageHash": "87fda7bac018df8b6c2d46f9cec101626a51a8642229dfc8b3dc6f1d"
232
232
  }