one
Version:
One is a React framework for web, iOS, and Android apps.
150 lines (149 loc) • 5.07 kB
JavaScript
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
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 __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
value: mod,
enumerable: true
}) : target, mod));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var Sitemap_web_exports = {};
__export(Sitemap_web_exports, {
Sitemap: () => Sitemap,
getNavOptions: () => getNavOptions
});
module.exports = __toCommonJS(Sitemap_web_exports);
var React = __toESM(require("react"), 1);
var import_Link = require("../link/Link.cjs");
var import_matchers = require("../router/matchers.cjs");
var import_router = require("../router/router.cjs");
var import_jsx_runtime = require("react/jsx-runtime");
const INDENT = 24;
function getNavOptions() {
return {
title: "sitemap",
headerShown: false,
presentation: "modal",
animation: "default",
headerLargeTitleEnabled: false,
headerTitleStyle: { color: "white" },
headerTintColor: "white",
headerLargeTitleStyle: { color: "white" },
headerStyle: { backgroundColor: "black" }
};
}
function Sitemap() {
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("main", {
style: {
minHeight: "100vh",
boxSizing: "border-box",
backgroundColor: "black",
color: "white",
padding: 12
},
children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
style: {
width: "min(960px, 90vw)",
margin: "0 auto"
},
children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("h1", {
style: {
fontSize: 28,
margin: "12px 0 20px"
},
children: "Sitemap"
}), (0, import_router.getSortedRoutes)().map((route) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
style: {
border: "1px solid #323232",
borderRadius: 19,
marginBottom: 12,
overflow: "hidden"
},
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(FileItem, { route })
}, route.contextKey))]
})
});
}
function FileItem({ route, level = 0, parents = [], isInitial = false }) {
const disabled = route.children.length > 0;
const segments = React.useMemo(() => [...parents, ...route.route.split("/")], [parents, route.route]);
const href = React.useMemo(() => "/" + segments.map((segment) => {
if ((0, import_matchers.matchDeepDynamicRouteName)(segment)) {
return `${segment}/${Date.now()}`;
}
return segment === "index" ? "" : segment;
}).filter(Boolean).join("/"), [segments]);
const filename = React.useMemo(() => {
const contextSegments = route.contextKey.split("/");
if (route.contextKey.match(/_layout\.[jt]sx?$/)) {
return contextSegments.slice(-2).join("/");
}
return contextSegments.slice(-route.route.split("/").length).join("/");
}, [route]);
const content = /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
style: {
display: "flex",
alignItems: "center",
justifyContent: "space-between",
gap: 16,
minHeight: 56,
boxSizing: "border-box",
padding: `16px ${INDENT}px 16px ${INDENT + level * INDENT}px`,
color: "white",
opacity: disabled ? .6 : 1
},
children: [/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", {
style: { fontSize: 20 },
children: [
route.children.length ? "🗀" : "📄",
" ",
filename
]
}), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", {
style: {
display: "flex",
alignItems: "center",
gap: 8
},
children: [(isInitial || route.generated) && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
style: { fontSize: 13 },
children: isInitial ? "Initial" : "Virtual"
}), !disabled && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
"aria-hidden": "true",
children: "›"
})]
})]
});
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [!route.internal && (disabled ? content : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_Link.Link, {
href,
replace: true,
accessibilityLabel: route.contextKey,
style: {
display: "block",
textDecoration: "none"
},
children: content
})), route.children.map((child) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(FileItem, {
route: child,
isInitial: route.initialRouteName === child.route,
parents: segments,
level: level + (route.generated ? 0 : 1)
}, child.contextKey))] });
}