{"version":3,"file":"startTanStackRouterView.mjs","names":[],"sources":["../../../src/domain/tanstackRouter/startTanStackRouterView.ts"],"sourcesContent":["import { display } from '@datadog/browser-core'\nimport { onRumInit } from '../reactPlugin'\nimport type { AnyTanStackRouteMatch } from './types'\n\nexport function startTanStackRouterView(routeMatches: AnyTanStackRouteMatch[]) {\n  onRumInit((configuration, rumPublicApi) => {\n    if (!configuration.router) {\n      display.warn('`router: true` is missing from the react plugin configuration, the view will not be tracked.')\n      return\n    }\n    rumPublicApi.startView(computeViewName(routeMatches))\n  })\n}\n\nexport function computeViewName(routeMatches: AnyTanStackRouteMatch[]) {\n  if (routeMatches.length === 0) {\n    return ''\n  }\n\n  // TanStack Router provides `fullPath` on each match, which is the route template\n  // with param placeholders (e.g., \"/posts/$postId\"). The last match is the most\n  // specific route, and its fullPath is the complete view name.\n  const lastMatch = routeMatches[routeMatches.length - 1]\n  let viewName = lastMatch.fullPath\n\n  // Handle splat routes: TanStack uses bare \"$\" for catch-all segments.\n  // Replace the splat placeholder with the actual matched path for better readability,\n  // consistent with how the React Router integration handles \"*\" splats.\n  viewName = substitutePathSplats(viewName, lastMatch.params)\n\n  // Remove trailing slash (e.g. \"/posts/\" → \"/posts\") happening when the last match is an index route\n  if (viewName.endsWith('/')) {\n    viewName = viewName.slice(0, -1)\n  }\n\n  return viewName || '/'\n}\n\n/**\n * TanStack Router uses a bare \"$\" for catch-all (splat) segments.\n * Example: \"/files/$\" with params._splat = \"path/to/file\" → \"/files/path/to/file\"\n *\n * Keeping the \"$\" in the view name isn't helpful as it hides information.\n * We replace it with the actual matched path, consistent with React Router's \"*\" handling.\n */\nfunction substitutePathSplats(path: string, params: Record<string, string | undefined>): string {\n  if (!path.endsWith('/$') || params._splat === undefined) {\n    return path\n  }\n\n  return path.replace(/\\/\\$$/, `/${params._splat}`)\n}\n"],"mappings":";;;AAIA,SAAgB,wBAAwB,cAAuC;CAC7E,WAAW,eAAe,iBAAiB;EACzC,IAAI,CAAC,cAAc,QAAQ;GACzB,QAAQ,KAAK,8FAA8F;GAC3G;EACF;EACA,aAAa,UAAU,gBAAgB,YAAY,CAAC;CACtD,CAAC;AACH;AAEA,SAAgB,gBAAgB,cAAuC;CACrE,IAAI,aAAa,WAAW,GAC1B,OAAO;CAMT,MAAM,YAAY,aAAa,aAAa,SAAS;CACrD,IAAI,WAAW,UAAU;CAKzB,WAAW,qBAAqB,UAAU,UAAU,MAAM;CAG1D,IAAI,SAAS,SAAS,GAAG,GACvB,WAAW,SAAS,MAAM,GAAG,EAAE;CAGjC,OAAO,YAAY;AACrB;;;;;;;;AASA,SAAS,qBAAqB,MAAc,QAAoD;CAC9F,IAAI,CAAC,KAAK,SAAS,IAAI,KAAK,OAAO,WAAW,KAAA,GAC5C,OAAO;CAGT,OAAO,KAAK,QAAQ,SAAS,IAAI,OAAO,QAAQ;AAClD"}