import type { ComponentType } from "react"; import { Link, Outlet, type RouteObject } from "react-router-dom"; import { defineBoundedContextModule } from "../../src/contexts/bounded-context-module.ts"; import { defineFeatureModule } from "../../src/features/feature-module.ts"; // Not the design-system barrel, for the reason fixture-feature.tsx gives. import { PageHeader } from "../../src/presentation/components/page-header.tsx"; import { FIXTURE_CONTEXT_MODULE, FIXTURE_FEATURE_MODULE, } from "./fixture-feature.tsx"; /** * 09-03. A test-only product whose screens do not live in AppShell, declared * the way the two downstream products need it, without touching the router: * * context root layout routes * site * site APP_HOME "/" (replaces the platform home), "/explore" * topics topics/* site "/topics" (a second root under one layout) * studio studio/* studio "/studio", "/studio/documents" * offline offline/* offline "/offline" (its layout chunk never arrives) * fixture fixture/* (none) the fixture feature, still under AppShell * * memento's bridges are `site` (its home and its own shell); tech-log's * PUBLIC/STUDIO groups are `site` + `topics` and `studio`. Install it by * mocking the generated indexes with the exports below. */ type RouteSpec = readonly [routeId: string, path: string, title: string, navigationOrder: number | null]; function layoutFeature(featureId: string, specs: readonly RouteSpec[]) { const routes = Object.freeze( Object.fromEntries( specs.map(([routeId, path, title, navigationOrder]) => [ routeId, Object.freeze({ routeId, path, paramsSchema: null, searchSchema: null, access: "public" as const, loadingSurface: "fixture-page", errorSurface: "route-boundary", chunkId: `route-${routeId.toLowerCase()}`, title, navigationLabel: navigationOrder === null ? null : title, navigationOrder, }), ]), ), ); const messages = Object.freeze( Object.fromEntries( specs.flatMap(([routeId, , title]) => [ [`route.${routeId}.title`, title], [`route.${routeId}.navigation`, title], ]), ), ); const feature = defineFeatureModule({ id: featureId, contracts: Object.freeze({ featureId, routes, routeRuntimeContracts: Object.freeze( Object.fromEntries( specs.map(([routeId]) => [ routeId, Object.freeze({ routeId, moduleId: `${routeId.toLowerCase()}-page`, paramsCodec: "none", searchCodec: "none", }), ]), ), ), invalidation: Object.freeze({ topics: [], namespaces: [], edges: [] }), topicVersions: Object.freeze([]), contractPackages: Object.freeze([]), }), routes, messages: Object.freeze({ "ko-KR": messages, "en-US": messages }), loadRuntime: async () => Object.freeze({ featureId, schemas: Object.freeze({}), adapters: Object.freeze([]), contractContributions: Object.freeze([]), }), }); const contextRoutes: readonly RouteObject[] = specs.map(([routeId, path, title]) => ({ id: routeId, path, handle: Object.freeze({ routeId, runtime: Object.freeze({ moduleId: `${routeId.toLowerCase()}-page`, Component: function FixtureLayoutPage() { return ; }, }), }), })); return { feature, contextRoutes }; } /** A product shell: its own skip link, navigation and the one `
`. */ function shell(name: string, links: readonly (readonly [to: string, label: string])[]): ComponentType { return function FixtureProductLayout() { return (
Skip to {name} content
); }; } const SiteLayout = shell("site", [ ["/topics", "Topics"], ["/studio", "Open the studio"], ]); const StudioLayout = shell("studio", [ ["/", "Back to the site"], ["/fixture/first", "Back to the app shell"], ]); // Each context loads its layout itself, the way generated contexts do; site // and topics load the same component, so they share one layout instance. const loadSiteLayout = async () => SiteLayout; const loadTopicsLayout = async () => SiteLayout; const loadStudioLayout = async () => StudioLayout; const site = layoutFeature("site-feature", [ ["APP_HOME", "/", "Site home", 10], ["SITE_EXPLORE", "/explore", "Site explore", null], ]); const topics = layoutFeature("topics-feature", [["SITE_TOPICS", "/topics", "Site topics", null]]); const studio = layoutFeature("studio-feature", [ ["STUDIO_HOME", "/studio", "Studio home", null], ["STUDIO_DOCUMENTS", "/studio/documents", "Studio documents", null], ]); const offline = layoutFeature("offline-feature", [["OFFLINE_HOME", "/offline", "Offline home", null]]); function layoutContext( id: string, path: string, { feature, contextRoutes }: ReturnType, loadLayout: () => Promise, ) { return defineBoundedContextModule({ id, features: [feature], budget: { maxFeatures: 1 }, route: { path, loadRoutes: async () => contextRoutes, loadLayout }, }); } export const LAYOUT_PRODUCT_FEATURE_MODULES = [ site.feature, topics.feature, studio.feature, offline.feature, FIXTURE_FEATURE_MODULE, ] as const; export const LAYOUT_PRODUCT_FEATURE_IDS = LAYOUT_PRODUCT_FEATURE_MODULES.map( (feature) => feature.id, ); export const LAYOUT_PRODUCT_CONTEXT_MODULES = [ layoutContext("site", "*", site, loadSiteLayout), layoutContext("topics", "topics/*", topics, loadTopicsLayout), layoutContext("studio", "studio/*", studio, loadStudioLayout), layoutContext("offline", "offline/*", offline, () => Promise.reject( new TypeError("Failed to fetch dynamically imported module: /assets/offline-layout.js"), ), ), FIXTURE_CONTEXT_MODULE, ] as const;