UNPKG

one

Version:

One is a new React Framework that makes Vite serve both native and web.

52 lines (51 loc) 1.62 kB
import { Platform } from "react-native"; import { appendBaseUrl } from "../fork/getPathFromState-mods.native.js"; import { stripGroupSegmentsFromPath } from "../router/matchers.native.js"; import { useOneRouter } from "../router/router.native.js"; function eventShouldPreventDefault(e) { if (e === null || e === void 0 ? void 0 : e.defaultPrevented) { return false; } if ( // Only check MouseEvents "button" in e && // ignore clicks with modifier keys !e.metaKey && !e.altKey && !e.ctrlKey && !e.shiftKey && (e.button == null || e.button === 0) && // Only accept left clicks [void 0, null, "", "self"].includes(e.currentTarget.target)) { return true; } return false; } function useLinkTo(props) { var { linkTo } = useOneRouter(); var onPress = function (e) { var event = props.replace ? "REPLACE" : "PUSH"; var shouldHandle = false; if (Platform.OS !== "web" || !e) { shouldHandle = e ? !e.defaultPrevented : true; } else if (eventShouldPreventDefault(e)) { e.preventDefault(); shouldHandle = true; } if (shouldHandle) { var options = props.mask ? { mask: { href: props.mask } } : void 0; linkTo(props.href, event, options); } }; var displayHref = props.mask || props.href; return { // Ensure there's always a value for href. Manually append the baseUrl to the href prop that shows in the static HTML. href: appendBaseUrl(stripGroupSegmentsFromPath(displayHref) || "/"), role: "link", onPress }; } export { useLinkTo }; //# sourceMappingURL=useLinkTo.native.js.map