/**
* Design OS route wiring — component catalog, token hub, column catalog, and
* the focus-workflow / exam-lock showcases, plus the pre-`/design-os` root
* redirects.
*
* Kept in its own module (not inlined in `src/routes.tsx`) because `routes.tsx`
* is app-owned in consumer apps: `exxat-ui upgrade` may never overwrite it, so
* the Design OS surface has to arrive as a package-owned file that the consumer
* mounts with one spread. See `packages/ui/bin/upgrade-design-os-wiring.mjs`.
*/
import { Suspense, lazy } from "react"
import { Navigate, useLocation, type RouteObject } from "react-router"
import { LoadingFallback } from "../_loading"
import { RouteError } from "../_error"
/** Prefix swap that preserves the rest of the path, the query, and the hash. */
export function RedirectToDesignOsSubpath({
fromPrefix,
toPrefix,
}: {
fromPrefix: string
toPrefix: string
}) {
const location = useLocation()
const rest = location.pathname.startsWith(fromPrefix)
? location.pathname.slice(fromPrefix.length)
: ""
const normalizedRest = rest.startsWith("/") ? rest : rest ? `/${rest}` : ""
return (
)
}
function lazyPage(loader: () => Promise<{ default: React.ComponentType }>) {
const Lazy = lazy(loader)
return (
}>
)
}
/**
* Design OS hubs, mounted under the product root gate so they resolve at
* `/design-os/design-system`, `/design-os/tokens-themes`, and siblings.
*/
export function designOsProductChildRoutes(): RouteObject[] {
return [
{
path: "design-system",
element: lazyPage(() => import("./_layout")),
errorElement: ,
children: [
{ index: true, element: lazyPage(() => import("./index")) },
{ path: ":slug", element: lazyPage(() => import("./doc")) },
],
},
{
path: "columns",
element: lazyPage(() => import("../columns")),
errorElement: ,
},
{
path: "column-types-demo",
element: lazyPage(() => import("../column-types-demo")),
errorElement: ,
},
{
path: "tokens-themes",
element: lazyPage(() => import("../tokens-themes")),
errorElement: ,
},
{
path: "delivery",
element: lazyPage(() => import("../delivery")),
errorElement: ,
},
{
path: "focus-workflow",
element: lazyPage(() => import("../focus-workflow")),
errorElement: ,
},
{
path: "exam-lock",
element: lazyPage(() => import("../exam-lock")),
errorElement: ,
},
]
}
/** Back-compat: these hubs lived at the workspace root before Design OS existed. */
export function designOsLegacyRootRedirects(): RouteObject[] {
return [
{
path: "library/*",
element: ,
},
{
path: "design-system/*",
element: (
),
},
{
path: "columns/*",
element: ,
},
{
path: "tokens-themes/*",
element: (
),
},
{
path: "exam/*",
element: ,
},
]
}