Next.js website for Rocky Mountain Vending company featuring: - Product catalog with Stripe integration - Service areas and parts pages - Admin dashboard with Clerk authentication - SEO optimized pages with JSON-LD structured data Co-authored-by: Cursor <cursoragent@cursor.com>
1 line
No EOL
6.7 KiB
Text
1 line
No EOL
6.7 KiB
Text
{"version":3,"sources":["../../../../src/shared/lib/router/adapters.tsx"],"sourcesContent":["import type { AppRouterInstance } from '../app-router-context.shared-runtime'\nimport type { Params } from '../../../server/request/params'\nimport type { NextRouter } from './router'\n\nimport React, { useMemo, useRef } from 'react'\nimport { PathnameContext } from '../hooks-client-context.shared-runtime'\nimport { isDynamicRoute } from './utils'\nimport { asPathToSearchParams } from './utils/as-path-to-search-params'\nimport { getRouteRegex } from './utils/route-regex'\n\n/** It adapts a Pages Router (`NextRouter`) to the App Router Instance. */\nexport function adaptForAppRouterInstance(\n pagesRouter: NextRouter\n): AppRouterInstance {\n return {\n back() {\n pagesRouter.back()\n },\n forward() {\n pagesRouter.forward()\n },\n refresh() {\n pagesRouter.reload()\n },\n hmrRefresh() {},\n push(href, { scroll } = {}) {\n void pagesRouter.push(href, undefined, { scroll })\n },\n replace(href, { scroll } = {}) {\n void pagesRouter.replace(href, undefined, { scroll })\n },\n prefetch(href) {\n void pagesRouter.prefetch(href)\n },\n }\n}\n\n/**\n * adaptForSearchParams transforms the ParsedURLQuery into URLSearchParams.\n *\n * @param router the router that contains the query.\n * @returns the search params in the URLSearchParams format\n */\nexport function adaptForSearchParams(\n router: Pick<NextRouter, 'isReady' | 'query' | 'asPath'>\n): URLSearchParams {\n if (!router.isReady || !router.query) {\n return new URLSearchParams()\n }\n\n return asPathToSearchParams(router.asPath)\n}\n\nexport function adaptForPathParams(\n router: Pick<NextRouter, 'isReady' | 'pathname' | 'query' | 'asPath'>\n): Params | null {\n if (!router.isReady || !router.query) {\n return null\n }\n const pathParams: Params = {}\n const routeRegex = getRouteRegex(router.pathname)\n const keys = Object.keys(routeRegex.groups)\n for (const key of keys) {\n pathParams[key] = router.query[key]!\n }\n return pathParams\n}\n\nexport function PathnameContextProviderAdapter({\n children,\n router,\n ...props\n}: React.PropsWithChildren<{\n router: Pick<NextRouter, 'pathname' | 'asPath' | 'isReady' | 'isFallback'>\n isAutoExport: boolean\n}>) {\n const ref = useRef(props.isAutoExport)\n const value = useMemo(() => {\n // isAutoExport is only ever `true` on the first render from the server,\n // so reset it to `false` after we read it for the first time as `true`. If\n // we don't use the value, then we don't need it.\n const isAutoExport = ref.current\n if (isAutoExport) {\n ref.current = false\n }\n\n // When the route is a dynamic route, we need to do more processing to\n // determine if we need to stop showing the pathname.\n if (isDynamicRoute(router.pathname)) {\n // When the router is rendering the fallback page, it can't possibly know\n // the path, so return `null` here. Read more about fallback pages over\n // at:\n // https://nextjs.org/docs/api-reference/data-fetching/get-static-paths#fallback-pages\n if (router.isFallback) {\n return null\n }\n\n // When `isAutoExport` is true, meaning this is a page page has been\n // automatically statically optimized, and the router is not ready, then\n // we can't know the pathname yet. Read more about automatic static\n // optimization at:\n // https://nextjs.org/docs/advanced-features/automatic-static-optimization\n if (isAutoExport && !router.isReady) {\n return null\n }\n }\n\n // The `router.asPath` contains the pathname seen by the browser (including\n // any query strings), so it should have that stripped. Read more about the\n // `asPath` option over at:\n // https://nextjs.org/docs/api-reference/next/router#router-object\n let url: URL\n try {\n url = new URL(router.asPath, 'http://f')\n } catch (_) {\n // fallback to / for invalid asPath values e.g. //\n return '/'\n }\n\n return url.pathname\n }, [router.asPath, router.isFallback, router.isReady, router.pathname])\n\n return (\n <PathnameContext.Provider value={value}>\n {children}\n </PathnameContext.Provider>\n )\n}\n"],"names":["React","useMemo","useRef","PathnameContext","isDynamicRoute","asPathToSearchParams","getRouteRegex","adaptForAppRouterInstance","pagesRouter","back","forward","refresh","reload","hmrRefresh","push","href","scroll","undefined","replace","prefetch","adaptForSearchParams","router","isReady","query","URLSearchParams","asPath","adaptForPathParams","pathParams","routeRegex","pathname","keys","Object","groups","key","PathnameContextProviderAdapter","children","props","ref","isAutoExport","value","current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