@redocly/theme
Version:
Shared UI components lib
49 lines • 2.61 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.loadAndNavigate = loadAndNavigate;
const utils_1 = require("../../core/utils");
let lastNavigatedPath;
// this is copy from portal/src/client/app/utils/loadAndNavigate.ts, for case when we need to run Redoc without Realm
function loadAndNavigate(_a) {
return __awaiter(this, arguments, void 0, function* ({ navigate, to, origin = 'browser', options, }) {
var _b;
lastNavigatedPath = to;
const { pathname, hash, search } = new URL(to, window.location.origin + window.location.pathname);
// use window-shared loader instead of importing to prevent circular import issue
const loader = window['__LOADER'];
const result = yield (0, utils_1.withLoadProgress)(loader.tryLoad(pathname));
// @ts-ignore
if (result === null || result === void 0 ? void 0 : result.redirectTo) {
// @ts-ignore
return loadAndNavigate({ navigate, to: result.redirectTo, origin, options });
}
if (result && lastNavigatedPath === to) {
if (pathname !== window.location.pathname || search !== window.location.search) {
// origin is used to prevent infinite loop when navigating from post message (from wysiwyg)
navigate({ pathname, search, hash }, Object.assign(Object.assign({}, options), { state: { origin }, unstable_flushSync: true }));
}
// @ts-ignore
if ((_b = result.props) === null || _b === void 0 ? void 0 : _b.disableAutoScroll)
return;
if (hash) {
const el = document.getElementById(hash.slice(1));
if (el) {
el.scrollIntoView();
}
}
else {
window.scrollTo(0, 0);
}
}
});
}
//# sourceMappingURL=load-and-navigate.js.map