Files
med-notes/.pnpm-store/v10/files/68/4c0c20fb960986f06fb7b6c543154905237ac98bc534a7cf8a3f6a74492bc6dc9796112de2b44b779edeef197c808c1d211aeb1a813f4a7bcd0f3722ebd71e
2025-05-09 05:30:08 +02:00

40 lines
1.3 KiB
Plaintext

import { defaultGetScrollRestorationKey, getCssSelector, scrollRestorationCache, setupScrollRestoration } from "@tanstack/router-core";
import { useRouter } from "./useRouter.js";
function useScrollRestoration() {
const router = useRouter();
setupScrollRestoration(router, true);
}
function ScrollRestoration(_props) {
useScrollRestoration();
if (process.env.NODE_ENV === "development") {
console.warn(
"The ScrollRestoration component is deprecated. Use createRouter's `scrollRestoration` option instead."
);
}
return null;
}
function useElementScrollRestoration(options) {
var _a;
useScrollRestoration();
const router = useRouter();
const getKey = options.getKey || defaultGetScrollRestorationKey;
let elementSelector = "";
if (options.id) {
elementSelector = `[data-scroll-restoration-id="${options.id}"]`;
} else {
const element = (_a = options.getElement) == null ? void 0 : _a.call(options);
if (!element) {
return;
}
elementSelector = element instanceof Window ? "window" : getCssSelector(element);
}
const restoreKey = getKey(router.latestLocation);
const byKey = scrollRestorationCache.state[restoreKey];
return byKey == null ? void 0 : byKey[elementSelector];
}
export {
ScrollRestoration,
useElementScrollRestoration
};
//# sourceMappingURL=ScrollRestoration.js.map