one
Version:
One is a new React Framework that makes Vite serve both native and web.
80 lines (78 loc) • 2.65 kB
JavaScript
;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all) __defProp(target, name, {
get: all[name],
enumerable: true
});
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
get: () => from[key],
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
});
}
return to;
};
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
value: true
}), mod);
var useLinkTo_exports = {};
__export(useLinkTo_exports, {
useLinkTo: () => useLinkTo
});
module.exports = __toCommonJS(useLinkTo_exports);
var import_react_native = require("react-native");
var import_getPathFromState_mods = require("../fork/getPathFromState-mods.native.js");
var import_matchers = require("../router/matchers.native.js");
var import_router = require("../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
} = (0, import_router.useOneRouter)();
var onPress = function (e) {
var event = props.replace ? "REPLACE" : "PUSH";
var shouldHandle = false;
if (import_react_native.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: (0, import_getPathFromState_mods.appendBaseUrl)((0, import_matchers.stripGroupSegmentsFromPath)(displayHref) || "/"),
role: "link",
onPress
};
}
//# sourceMappingURL=useLinkTo.native.js.map