one
Version:
One is a new React Framework that makes Vite serve both native and web.
70 lines • 2.9 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: !0
});
},
__copyProps = (to, from, except, desc) => {
if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__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: !0
}), mod);
var findRouteNode_exports = {};
__export(findRouteNode_exports, {
extractParamsFromState: () => extractParamsFromState,
extractPathnameFromHref: () => extractPathnameFromHref,
extractSearchFromHref: () => extractSearchFromHref,
findRouteNodeFromState: () => findRouteNodeFromState
});
module.exports = __toCommonJS(findRouteNode_exports);
function findRouteNodeFromState(state, rootNode) {
if (!state || !rootNode) return null;
const currentRoute = state.routes[state.routes.length - 1];
if (!currentRoute) return null;
const matchingNode = findNodeByRouteName(rootNode, currentRoute.name);
if (!matchingNode) return null;
if (currentRoute.state && currentRoute.state.routes) {
const nestedResult = findRouteNodeFromState(currentRoute.state, matchingNode);
if (nestedResult) return nestedResult;
}
return matchingNode;
}
function findNodeByRouteName(node, routeName) {
if (node.route === routeName) return node;
for (const child of node.children) {
const found = findNodeByRouteName(child, routeName);
if (found) return found;
}
return null;
}
function extractParamsFromState(state) {
if (!state) return {};
const params = {};
for (const route of state.routes) route.params && Object.assign(params, route.params), route.state && Object.assign(params, extractParamsFromState(route.state));
return params;
}
function extractSearchFromHref(href) {
const searchIndex = href.indexOf("?");
if (searchIndex === -1) return {};
const searchString = href.slice(searchIndex + 1),
params = {};
return new URLSearchParams(searchString).forEach((value, key) => {
const existing = params[key];
existing === void 0 ? params[key] = value : Array.isArray(existing) ? existing.push(value) : params[key] = [existing, value];
}), params;
}
function extractPathnameFromHref(href) {
const searchIndex = href.indexOf("?"),
hashIndex = href.indexOf("#");
let endIndex = href.length;
return searchIndex !== -1 && (endIndex = Math.min(endIndex, searchIndex)), hashIndex !== -1 && (endIndex = Math.min(endIndex, hashIndex)), href.slice(0, endIndex);
}