UNPKG

one

Version:

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

52 lines (51 loc) 1.56 kB
import { Platform } from "react-native-web"; import { appendBaseUrl } from "../fork/getPathFromState-mods.mjs"; import { stripGroupSegmentsFromPath } from "../router/matchers.mjs"; import { useOneRouter } from "../router/router.mjs"; function eventShouldPreventDefault(e) { if (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) { const { linkTo } = useOneRouter(); const onPress = e => { const event = props.replace ? "REPLACE" : "PUSH"; let shouldHandle = false; if (Platform.OS !== "web" || !e) { shouldHandle = e ? !e.defaultPrevented : true; } else if (eventShouldPreventDefault(e)) { e.preventDefault(); shouldHandle = true; } if (shouldHandle) { const options = props.mask ? { mask: { href: props.mask } } : void 0; linkTo(props.href, event, options); } }; const 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.mjs.map