@redocly/asyncapi-docs
Version:
Async API docs for Redocly Realm
2 lines (1 loc) • 1.37 kB
JavaScript
var c=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var u=Object.getOwnPropertyNames;var f=Object.prototype.hasOwnProperty;var p=(e,t)=>{for(var o in t)c(e,o,{get:t[o],enumerable:!0})},h=(e,t,o,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of u(t))!f.call(e,n)&&n!==o&&c(e,n,{get:()=>t[n],enumerable:!(i=m(t,n))||i.enumerable});return e};var w=e=>h(c({},"__esModule",{value:!0}),e);var T={};p(T,{useAutoScroll:()=>I});module.exports=w(T);var s=require("react"),l=require("react-router-dom"),r=require("@redocly/theme"),d=require("../utils");let a=!0;function I(e){const t=(0,l.useLocation)(),o=(0,r.useActiveSectionId)(t,!0);(0,s.useEffect)(()=>{S({location:t,routingBasePath:e})},[t,e]),(0,s.useEffect)(()=>{if(o&&a){a=!1;return}r.IS_BROWSER&&window.location.pathname!==o&&window.history.replaceState({},"",o)},[o,e])}function S({location:e,routingBasePath:t}){if(e.pathname===t&&e.hash===""){window.scrollTo(0,0);return}const o=e.pathname,i=y(e.hash),n=E(i)||document.querySelector(`[data-section-id="${o}"]`);n?setTimeout(()=>{n.scrollIntoView()},0):window.scrollTo(0,0)}function y(e){const t=e.replace("#","").toLowerCase();if(!t.includes("&m="))return t;const[o,i]=t.split("&m=");return i.includes("&")||i.includes("/")?t:o}function E(e){return document.getElementById((0,d.tryDecodeURIComponent)(e))}0&&(module.exports={useAutoScroll});