@yoast/ai-insights-client 1.4.82 → 1.4.83

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.
@@ -12601,6 +12601,47 @@ const BrandList$1 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineP
12601
12601
  __proto__: null,
12602
12602
  default: BrandList
12603
12603
  }, Symbol.toStringTag, { value: "Module" }));
12604
+ var useRouterBasename = function useRouterBasename2() {
12605
+ var location = useLocation();
12606
+ var basename = useMemo(function() {
12607
+ var fullPathname = window.location.pathname;
12608
+ var routerPathname = location.pathname;
12609
+ if (fullPathname === routerPathname) {
12610
+ return "";
12611
+ }
12612
+ if (!fullPathname.endsWith(routerPathname)) {
12613
+ return "";
12614
+ }
12615
+ var extractedBasename = fullPathname.slice(0, fullPathname.length - routerPathname.length);
12616
+ return extractedBasename.endsWith("/") ? extractedBasename.slice(0, -1) : extractedBasename;
12617
+ }, [location.pathname]);
12618
+ var stripBasename2 = useCallback(function(absolutePath) {
12619
+ if (basename && absolutePath.startsWith(basename)) {
12620
+ var stripped = absolutePath.slice(basename.length);
12621
+ return stripped === "" ? "/" : stripped;
12622
+ }
12623
+ return absolutePath;
12624
+ }, [basename]);
12625
+ var addBasename = useCallback(function(relativePath) {
12626
+ if (!basename) {
12627
+ return relativePath;
12628
+ }
12629
+ var normalizedPath = relativePath.startsWith("/") ? relativePath : "/".concat(relativePath);
12630
+ return "".concat(basename).concat(normalizedPath);
12631
+ }, [basename]);
12632
+ var isWithinBasename = useCallback(function(path) {
12633
+ if (!basename) {
12634
+ return path.startsWith("/") && !path.startsWith("//");
12635
+ }
12636
+ return path.startsWith(basename);
12637
+ }, [basename]);
12638
+ return {
12639
+ basename,
12640
+ stripBasename: stripBasename2,
12641
+ addBasename,
12642
+ isWithinBasename
12643
+ };
12644
+ };
12604
12645
  function _slicedToArray$7(r, e) {
12605
12646
  return _arrayWithHoles$7(r) || _iterableToArrayLimit$7(r, e) || _unsupportedIterableToArray$7(r, e) || _nonIterableRest$7();
12606
12647
  }
@@ -12644,6 +12685,7 @@ function _arrayWithHoles$7(r) {
12644
12685
  var useNavigationBlocker = function useNavigationBlocker2() {
12645
12686
  var _ref = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {}, _ref$shouldBlock = _ref.shouldBlock, shouldBlock = _ref$shouldBlock === void 0 ? true : _ref$shouldBlock, onConfirmLeave = _ref.onConfirmLeave, onCancelLeave = _ref.onCancelLeave;
12646
12687
  var navigate = useNavigate();
12688
+ var _useRouterBasename = useRouterBasename(), stripBasename2 = _useRouterBasename.stripBasename;
12647
12689
  var _useState = useState(false), _useState2 = _slicedToArray$7(_useState, 2), showModal = _useState2[0], setShowModal = _useState2[1];
12648
12690
  var _useState3 = useState(null), _useState4 = _slicedToArray$7(_useState3, 2), pendingNavigation = _useState4[0], setPendingNavigation = _useState4[1];
12649
12691
  useEffect(function() {
@@ -12658,7 +12700,8 @@ var useNavigationBlocker = function useNavigationBlocker2() {
12658
12700
  if (href !== currentPath) {
12659
12701
  e.preventDefault();
12660
12702
  e.stopPropagation();
12661
- setPendingNavigation(href);
12703
+ var routerRelativePath = stripBasename2(href);
12704
+ setPendingNavigation(routerRelativePath);
12662
12705
  setShowModal(true);
12663
12706
  }
12664
12707
  }
@@ -12667,7 +12710,7 @@ var useNavigationBlocker = function useNavigationBlocker2() {
12667
12710
  return function() {
12668
12711
  return document.removeEventListener("click", handleClick, true);
12669
12712
  };
12670
- }, [shouldBlock]);
12713
+ }, [shouldBlock, stripBasename2]);
12671
12714
  useEffect(function() {
12672
12715
  if (!shouldBlock) return;
12673
12716
  window.history.pushState(null, "", window.location.href);
@@ -12692,20 +12735,23 @@ var useNavigationBlocker = function useNavigationBlocker2() {
12692
12735
  return window.removeEventListener("beforeunload", handleBeforeUnload);
12693
12736
  };
12694
12737
  }, [shouldBlock]);
12738
+ var performNavigation = useCallback(function(destination) {
12739
+ if (typeof destination === "number") {
12740
+ navigate(destination);
12741
+ } else {
12742
+ navigate(stripBasename2(destination));
12743
+ }
12744
+ }, [navigate, stripBasename2]);
12695
12745
  var confirmLeave = useCallback(function() {
12696
12746
  if (pendingNavigation !== null) {
12697
12747
  setShowModal(false);
12698
12748
  onConfirmLeave === null || onConfirmLeave === void 0 || onConfirmLeave();
12699
12749
  setTimeout(function() {
12700
- if (typeof pendingNavigation === "number") {
12701
- navigate(pendingNavigation);
12702
- } else {
12703
- navigate(pendingNavigation);
12704
- }
12750
+ performNavigation(pendingNavigation);
12705
12751
  setPendingNavigation(null);
12706
12752
  }, 0);
12707
12753
  }
12708
- }, [pendingNavigation, navigate, onConfirmLeave]);
12754
+ }, [pendingNavigation, performNavigation, onConfirmLeave]);
12709
12755
  var cancelLeave = useCallback(function() {
12710
12756
  setShowModal(false);
12711
12757
  setPendingNavigation(null);
@@ -12713,16 +12759,13 @@ var useNavigationBlocker = function useNavigationBlocker2() {
12713
12759
  }, [onCancelLeave]);
12714
12760
  var navigateAway = useCallback(function(destination) {
12715
12761
  if (shouldBlock) {
12716
- setPendingNavigation(destination);
12762
+ var routerDestination = typeof destination === "string" ? stripBasename2(destination) : destination;
12763
+ setPendingNavigation(routerDestination);
12717
12764
  setShowModal(true);
12718
12765
  } else {
12719
- if (typeof destination === "number") {
12720
- navigate(destination);
12721
- } else {
12722
- navigate(destination);
12723
- }
12766
+ performNavigation(destination);
12724
12767
  }
12725
- }, [shouldBlock, navigate]);
12768
+ }, [shouldBlock, performNavigation, stripBasename2]);
12726
12769
  return {
12727
12770
  showModal,
12728
12771
  pendingNavigation,