{"version":3,"sources":["../../src/components/Routes.tsx"],"sourcesContent":["import type { ReactNode } from 'react';\nimport { Children, isValidElement, use } from 'react';\n\nimport { TinkerableContext } from '../TinkerableContext';\nimport type { RouteComponent, RoutingRule } from '../RoutingSpec';\nimport { matchRoute } from '../routeMatch';\nimport { renderRoute } from '../routing';\n\n/** Props for a {@link Route} declared inside {@link Routes}. */\nexport type RouteProps = {\n  /** A path template (`/posts/:slug`, `/files/*`, `/`) or a raw RegExp. */\n  path: string | RegExp;\n  name?: string;\n  /** Element to render; reads params via `useRouteParams()`. */\n  element?: ReactNode;\n  /** Component to render; receives matched params as a prop. */\n  component?: RouteComponent;\n};\n\n/**\n * Declares a route. Rendered as a child of `<Routes>`, where it is read for its\n * props — it renders nothing on its own. Mounting a `<Route>` registers it;\n * unmounting (or conditionally not rendering it) removes it, which is how routes\n * become dynamic without a mutable registry.\n */\nexport const Route = (_props: RouteProps): null => null;\n\n/**\n * Resolves the active `sandboxPath` against its mounted `<Route>` children,\n * first-match-wins in render order, and renders the winner (or `fallback`). The\n * match scopes a nested context so `useRouteParams()` / `useRoute()` inside the\n * rendered route see this match. Use instead of (or nested within) a `boot`-time\n * `routingSpec`.\n */\nexport const Routes = ({ children, fallback = null }: { children?: ReactNode; fallback?: ReactNode }) => {\n  const context = use(TinkerableContext);\n  const { sandboxPath } = context.navigationState;\n\n  for (const child of Children.toArray(children)) {\n    if (!isValidElement(child) || child.type !== Route) {\n      continue;\n    }\n    const { path, element, component, name } = child.props as RouteProps;\n    const params = matchRoute(path, sandboxPath);\n    if (params) {\n      const routingRule: RoutingRule = { name, pattern: path, element, component };\n      const scoped = {\n        ...context,\n        navigationState: { ...context.navigationState, routingRule, pathParameters: params },\n      };\n      return <TinkerableContext value={scoped}>{renderRoute(routingRule, params)}</TinkerableContext>;\n    }\n  }\n\n  return <>{fallback}</>;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAkDa;AAjDb,mBAA8C;AAE9C,+BAAkC;AAElC,wBAA2B;AAC3B,qBAA4B;AAmBrB,MAAM,QAAQ,CAAC,WAA6B;AAS5C,MAAM,SAAS,CAAC,EAAE,UAAU,WAAW,KAAK,MAAsD;AACvG,QAAM,cAAU,kBAAI,0CAAiB;AACrC,QAAM,EAAE,YAAY,IAAI,QAAQ;AAEhC,aAAW,SAAS,sBAAS,QAAQ,QAAQ,GAAG;AAC9C,QAAI,KAAC,6BAAe,KAAK,KAAK,MAAM,SAAS,OAAO;AAClD;AAAA,IACF;AACA,UAAM,EAAE,MAAM,SAAS,WAAW,KAAK,IAAI,MAAM;AACjD,UAAM,aAAS,8BAAW,MAAM,WAAW;AAC3C,QAAI,QAAQ;AACV,YAAM,cAA2B,EAAE,MAAM,SAAS,MAAM,SAAS,UAAU;AAC3E,YAAM,SAAS;AAAA,QACb,GAAG;AAAA,QACH,iBAAiB,EAAE,GAAG,QAAQ,iBAAiB,aAAa,gBAAgB,OAAO;AAAA,MACrF;AACA,aAAO,4CAAC,8CAAkB,OAAO,QAAS,0CAAY,aAAa,MAAM,GAAE;AAAA,IAC7E;AAAA,EACF;AAEA,SAAO,2EAAG,oBAAS;AACrB;","names":[]}