alinea
Version:
[](https://npmjs.org/package/alinea) [](https://packagephobia.com/result?p=alinea)
47 lines (45 loc) • 1.26 kB
JavaScript
import "../chunks/chunk-U5RRZUYZ.js";
// src/dashboard/DashboardNav.ts
var navMatchers = {
matchEntry: "/entry/*",
matchEntryId: "/:action/:workspace/:root?/:entryId?",
matchWorkspace: "/:action/:workspace",
matchRoot: "/:action/:workspace/:root"
};
function dashboardNav(defaults) {
function loc(location) {
const workspace = location?.workspace ?? defaults.workspace;
const root2 = location?.root ?? defaults.root;
const locale = "locale" in location ? location.locale : defaults.locale;
const id = location.i18nId ?? ("entryId" in location ? location.entryId : defaults.entryId);
const rootLocation = locale ? `${root2}:${locale}` : root2;
if (!id && !root2)
return `/${workspace}`;
if (!id)
return `/${workspace}/${rootLocation}`;
return `/${workspace}/${rootLocation}/${id}`;
}
function root({ entryId, i18nId, ...location }) {
return entry(location);
}
function entry(location) {
return `/entry${loc(location)}`;
}
function create(location) {
return entry(location) + "?new";
}
function draft(location) {
return `/draft${loc(location)}`;
}
return {
root,
entry,
draft,
create,
...navMatchers
};
}
export {
dashboardNav,
navMatchers
};